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 //