[fltk/fltk] fl_rescale_offscreen weird behavior on windows (Issue #475)

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.issues  ]
 
Previous Message ]New Message | Reply ]Next Message ]

[fltk/fltk] fl_rescale_offscreen weird behavior on windows (Issue #475) Mohammed Alyousef 05:33 Aug 01 top right image
 

Hi
Not sure if it's because I'm not using it correctly, but this example works correctly on Linux and macOS:

#include <FL/Fl.H>

#include <FL/Enumerations.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Double_Window.H>
#include <FL/fl_draw.H>

class Canvas : public Fl_Box {
  Fl_Offscreen offs = 0;
  int ox = 0, oy = 0;

public:
  Canvas(int x, int y, int w, int h)
      : Fl_Box(x, y, w, h), offs(fl_create_offscreen(w, h)) {
    fl_begin_offscreen(offs);
    fl_color(FL_WHITE);
    fl_rectf(0, 0, w, h);
    fl_end_offscreen();
  }
  void draw() override {
    if (offs) {
      fl_rescale_offscreen(offs);
      fl_copy_offscreen(x(), y(), w(), h(), offs, 0, 0);
    }
    Fl_Box::draw();
  }
  int handle(int e) override {
    auto ret = Fl_Box::handle(e);
    switch (e) {
    case FL_PUSH: {
      fl_begin_offscreen(offs);
      fl_color(FL_RED);
      fl_line_style(FL_SOLID, 3);
      ox = Fl::event_x();
      oy = Fl::event_y();
      fl_point(ox, oy);
      fl_end_offscreen();
      redraw();
      fl_line_style(FL_SOLID, 0);
      return true;
    }
    case FL_DRAG: {
      fl_begin_offscreen(offs);
      fl_color(FL_RED);
      fl_line_style(FL_SOLID, 3);
      int nx = Fl::event_x();
      int ny = Fl::event_y();
      fl_line(ox, oy, nx, ny);
      ox = nx;
      oy = ny;
      fl_end_offscreen();
      redraw();
      fl_line_style(FL_SOLID, 0);
      return true;
    }
    default:
      return ret;
    }
  }
};

int main() {
  auto win = new Fl_Window(800, 600);
  auto box = new Canvas(5, 5, 790, 590);
  win->end();
  win->show();
  return Fl::run();
}

If you remove the call to fl_rescale_offscreen, it works correctly, but the call is necessary if resizing is needed.

This produces a strange artifcat while drawing:
image


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <fltk/fltk/issues/475@github.com>

Direct Link to Message ]
 
bottom left image   bottom right image
Previous Message ]New Message | Reply ]Next Message ]
 
 

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