FLTK logo

[fltk.general] Re: Mac OS drawing lag

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Mac OS drawing lag Ian MacArthur Nov 29, 2022  
 
On Tuesday, 29 November 2022 at 12:22:55 UTC Arnis wrote:
Thank you for the responses.
I am using "redraw".

Here is an example app:

Hmm, OK.
Looks straightforward enough; can't see any obvious reason that would not Just Work.
I don't have a Mac here, but FWIW it seems fine under Win10.

A few thoughts, but I do not think they are going to make much difference:

1. I'd derive from Fl_Double_Window rather than Fl_Window - that will smooth things and reduce flickering on non-composited displays; though unlikely to make much difference on macOS, which does have a composited display...

2. Always call the base class handle from a derived class, particularly if you do not use the event yourself, to make sure the event loop is propagated fully. Particularly with container widgets like group or window, this can make a difference. 

3. Not sure what the call to make_current(); is meant to be doing? It should have no effect there.

Here's the code tweaked as I suggest, but I doubt it will make much difference!


#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/fl_draw.H>

class MainWindow: public Fl_Double_Window {
  public:
    MainWindow(int width, int height, const char* title) : Fl_Double_Window(width, height, title) {};
    ~MainWindow() {};

  private:
    int rectX = 0;
    int rectY = 0;
    int rectW = 1;
    int rectH = 1;

  protected:
    void draw() {
      // Clean screen
      fl_rectf(0, 0, this->w(), this->h(), FL_BLACK);
      // Draw box
      fl_rectf(this->x() + this->rectX, this->y() + this->rectY, this->rectW, this->rectH, FL_WHITE);
    }

    int handle(int event) {
      int x, y;

      switch (event) {
        case FL_PUSH:
          x = Fl::event_x() - this->x();
          y = Fl::event_y() - this->y();

          this->rectX = x;
          this->rectY = y;
          this->rectW = 1;
          this->rectH = 1;
          this->redraw();
          return 1;

        case FL_DRAG:
          x = Fl::event_x() - this->x();
          y = Fl::event_y() - this->y();

          this->rectW = x - this->rectX;
          this->rectH = y - this->rectY;
          this->redraw();
          return 1;

        default:
            break;
      }

      return Fl_Double_Window::handle(event);
    }
};


int main(int argc, char **argv) {
  Fl::scheme("gtk+");

  // Views
  MainWindow *mainWindow = new MainWindow(Fl::w(), Fl::h(), "Test");
  mainWindow->end();
  mainWindow->show(argc, argv);
  // mainWindow->make_current();

  return Fl::run();
}

// end of file //




--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/8cd363e0-eeb2-43c1-99df-9c3de0ead1e5n%40googlegroups.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.