gnustep / libs-gui

The GNUstep gui library is a library of graphical user interface classes written completely in the Objective-C language; the classes are based upon Apple's Cocoa framework (which came from the OpenStep specification). *** Larger patches require copyright assignment to FSF. please file bugs here. ***
http://www.gnustep.org
GNU General Public License v3.0
278 stars 102 forks source link

NSShadow does not work #217

Open optimisme opened 10 months ago

optimisme commented 10 months ago

Here is an example:

    NSRect shadowFrame = NSInsetRect(frame, 5.0, 5.0);
    shadowFrame.origin.x += 5.0;
    shadowFrame.origin.y += 5.0;

    // Definir el color de l'ombra
    NSColor *shadowColor = [NSColor redColor];

    // Definir l'ombra
    NSShadow *shadow = [[NSShadow alloc] init];
    [shadow setShadowColor:shadowColor];
    [shadow setShadowOffset:NSMakeSize(0, -1)];
    [shadow setShadowBlurRadius:10]; 

    // Aplicar l'ombra
    [NSGraphicsContext saveGraphicsState];
    [shadow set];

    // Dibuixar l'ombra (Això dibuixa una "caixa" d'ombra al voltant de l'àrea del botó)
    NSBezierPath *shadowPath = [NSBezierPath bezierPathWithRect:shadowFrame];
    [[NSColor clearColor] set];
    [shadowPath fill];
    // Restaurar l'estat gràfic per a que la configuració de l'ombra no afecti el fons del botó
    [NSGraphicsContext restoreGraphicsState];

Here another example that doesn't do anything:

       [NSGraphicsContext saveGraphicsState];

    // Definir el color de l'ombra
      NSColor *shadowColor = [NSColor blackColor];

      // Crear l'ombra
      NSShadow *shadow = [[NSShadow alloc] init];
      [shadow setShadowColor:shadowColor];
      [shadow setShadowOffset:NSMakeSize(0, 1)]; // Desplaçament de l'ombra 1 píxel cap avall
      [shadow setShadowBlurRadius:20]; // Radi de difuminació de 20 píxels

      // Aplicar l'ombra al botó
      [buttonDefault setShadow:shadow];

      // Restaurar el context gràfic
      [NSGraphicsContext restoreGraphicsState];
fredkiefer commented 10 months ago

Yes, at the moment NSShadow is missing most of the real drawing code. If I remember correctly, it would be really hard to implement this as it requires a different drawing concept from the one we have implemented in GNUstep gui at the moment. Any patchers to improve this are welcome.

optimisme commented 10 months ago

In my opinion, this is not an improvement, it is a bug. A very serious bug. I don't know who will fix it, but without a doubt, having said dozens of times for years that GNUStep is fully customizable, it is not acceptable to use 'enhacement' label to describe this bug.

gcasa commented 10 months ago

In my opinion, this is not an improvement, it is a bug. A very serious bug. I don't know who will fix it, but without a doubt, having said dozens of times for years that GNUStep is fully customizable, it is not acceptable to use 'enhacement' label to describe this bug.

Very well.

gcasa commented 10 months ago

In my opinion, this is not an improvement, it is a bug. A very serious bug. I don't know who will fix it, but without a doubt, having said dozens of times for years that GNUStep is fully customizable, it is not acceptable to use 'enhacement' label to describe this bug.

I moved this to a "bug" since you insisted. What leads you to the conclusion that this "bug" is as serious as you believe it to be? Some other frameworks don't have the concept of shadows.

fredkiefer commented 10 months ago

The difference between an enhancement and a bug used to be that in the later case we are surprised by something not working as expected. whereas in the first case something was never implemented properly and we know it is missing. Adding it would be an enhancement. If we start to mix these two categories we could give them up altogether. I think that @optimisme wanted to express that this missing functionality is a big drawback for him when implementing new themes. I understand this, but this is actually a completely different dimension when classifying issues. One that is currently not supported by GitHub. Anyway this difference seems not so important to me, we will accept changed regardless of whether an issue is classified as bug or as enhancement. Just feel free to write this extension for at least one backend.

gcasa commented 10 months ago

I do understand his point of view. I may need your help (@fredkiefer) implementing this as I am not sure how to approach the problem.

I know that macOS uses "layers". We don't and I am not sure I am willing to implement and entirely new approach to how we compose our graphics simply to support shadows.

gcasa commented 10 months ago

I have added a test here

This is currently running on macOS, just to demonstrate the look we need to achieve. I used the code from the first example provided.

NSShadow_example

@optimisme, It should be possible to build this on GNUstep using buildtool/libs-xcode. The shadow won't show until it's implemented in the backend. :)

gcasa commented 10 months ago

Okay, running the test on GNUstep illustrates that we also need the "setShadow:/shadow" methods to be implemented on NSView. We get a failure to load the xib because I have implemented the code from the example in -awakeFromNib which gets called during nib loading. I will create a branch on libs-gui and libs-back for these changes.

gcasa commented 10 months ago

I have opened the draft PR mentioned above and linked this issue. Please see the PR for further updates.

gcasa commented 10 months ago

Just as an aside, Albert... @optimisme ... this is the best way to get us to help. PLEASE KEEP SUBMITTING BUGS/ISSUES. Thank you for taking my advice.

gcasa commented 10 months ago

@optimisme Also, wanted to mention... my classification of this earlier as an enhancement was not meant to imply priority. To me, a bug is something that will block a release. Unfortunately, GitHub doesn't have a way to assign severity. Theoretically, we could do it using tags, and we probably should. Just wanted you to understand that I wasn't trying to downplay the importance of supporting this functionality.

fredkiefer commented 10 months ago

Just to clarify a few points:

I am willing to help with advice and review but won't have the time to this rework.

gcasa commented 10 months ago

Absolutely understood.

gcasa commented 10 months ago

I think I can integrate the shadows into the backend. What I do will support methods one and three. Shadows on Windows is a much more complex issue as this requires a compositing window manager. It's possible that could be implemented in the wayland backend when that is a bit more mature, but X doesn't support this kind of thing without "compiz" as far as I am aware.

gcasa commented 10 months ago

First I am making sure that the XIB information is being read correctly when this is done via InterfaceBuilder / Xcode on the mac. Then I will look into what needs to be done when a view has a shadow in the backend during rendering.

gcasa commented 10 months ago

In my opinion, this is not an improvement, it is a bug. A very serious bug. I don't know who will fix it, but without a doubt, having said dozens of times for years that GNUStep is fully customizable, it is not acceptable to use 'enhacement' label to describe this bug.

One thing I am forced to point out is that I never used those words. I have always maintained that GNUstep can be themed, never "fully customizable." :)

optimisme commented 10 months ago

I don't want to discuss, really.

Captura de pantalla 2023-12-29 a les 21 49 04
hmelder commented 10 months ago

No baits please

gcasa commented 10 months ago

I don't want to discuss, really.

Captura de pantalla 2023-12-29 a les 21 49 04

I wasn't trying to start an argument. I am working on shadows as you have seen so I just want to keep it positive.

My point when making that post was simply that gnustep doesn't always have to look like NeXTSTEP and openstep. Users have a choice.

At the moment I am looking for how this should be approached in the backend.

optimisme commented 10 months ago

I am unfamiliar with the GNUstep architecture and the difficulty this bug entails, but given that there is no rush, wouldn’t it be better to put this bug on hold? To implement the layers (which seem essential if in the future CoreAnimation is also to be added). And then add shadows.

gcasa commented 10 months ago

It might... but...

Strictly speaking layers are not needed to support shadows. Also layer support is backend specific as it is already implemented in the Opal backend. Opal uses our coregraphics implementation on top of Cairo. Currently it is experimental.

I'm still looking into doing it without layers at the moment, but I am going to start looking into working with the opal backend as well to see where that goes.