Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSShadow does not work #217

Open
optimisme opened this issue Dec 21, 2023 · 21 comments
Open

NSShadow does not work #217

optimisme opened this issue Dec 21, 2023 · 21 comments
Assignees
Labels
enhancement An enhancement to existing functionality

Comments

@optimisme
Copy link

optimisme commented Dec 21, 2023

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
Copy link
Member

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.

@gcasa gcasa added the enhancement An enhancement to existing functionality label Dec 22, 2023
@optimisme
Copy link
Author

optimisme commented Dec 24, 2023

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
Copy link
Member

gcasa commented Dec 24, 2023

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 gcasa added bug A bug, but not a show stopper and removed enhancement An enhancement to existing functionality labels Dec 24, 2023
@gcasa
Copy link
Member

gcasa commented Dec 24, 2023

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.

@gcasa gcasa self-assigned this Dec 24, 2023
@fredkiefer
Copy link
Member

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
Copy link
Member

gcasa commented Dec 24, 2023

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
Copy link
Member

gcasa commented Dec 24, 2023

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
Copy link
Member

gcasa commented Dec 24, 2023

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
Copy link
Member

gcasa commented Dec 24, 2023

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

@gcasa
Copy link
Member

gcasa commented Dec 24, 2023

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
Copy link
Member

gcasa commented Dec 24, 2023

@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
Copy link
Member

Just to clarify a few points:

  • GNUstep has an implementation for layers, but this only works together with the opal drawing backend. This was implemented some years ago by Ivan and a few other GSoC students and was never fully working.

  • From what I remember about NSShadow we have three modes. First to draw a shadow directly as in the first code shown above. This should be fairly easy to get implemented in the cairo backend. Then there are shadows applied to a whole window, this without a composition manager. And then there are shadows on views. Basically these require similar code as the first case but on top of that the redraw mechanism must be aware that views draw outside of their own frame and this is currently missing in GNUstep. Implementing that is doable but will require a bigger rework of our drawing concept.

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

@gcasa
Copy link
Member

gcasa commented Dec 25, 2023

Absolutely understood.

@gcasa
Copy link
Member

gcasa commented Dec 26, 2023

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
Copy link
Member

gcasa commented Dec 26, 2023

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
Copy link
Member

gcasa commented Dec 28, 2023

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
Copy link
Author

optimisme commented Dec 29, 2023

I don't want to discuss, really.

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

@hmelder
Copy link
Contributor

hmelder commented Dec 29, 2023

No baits please

@gcasa
Copy link
Member

gcasa commented Dec 29, 2023

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
Copy link
Author

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
Copy link
Member

gcasa commented Dec 30, 2023

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.

@gcasa gcasa assigned fredkiefer and unassigned gcasa May 12, 2024
@gcasa gcasa added enhancement An enhancement to existing functionality and removed bug A bug, but not a show stopper labels May 31, 2024
@gcasa gcasa changed the title Shadows does not work NSShadow does not work May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement to existing functionality
Development

No branches or pull requests

4 participants