FLTK logo

Re: [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 ]

Re: [fltk/fltk] fl_rescale_offscreen weird behavior on windows (Issue #475) ManoloFLTK Aug 08, 2022  
 

Yes, fl_rescale_offscreen() should be called only when the scaling factor changes value.
I attach a version of the code based on class Fl_Image_Surface.
This version does not blur when rescaling because the canvas is kept a constant size and gets drawn to the display with whatever zoom is necessary.

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

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

public:
  Canvas(int x, int y, int w, int h)
      : Fl_Box(x, y, w, h), offs(new Fl_Image_Surface(w, h)/*fl_create_offscreen(w, h)*/) {
    //fl_begin_offscreen(offs);
    Fl_Surface_Device::push_current(offs);
    fl_color(FL_WHITE);
    fl_rectf(0, 0, w, h);
    //fl_end_offscreen();
    Fl_Surface_Device::pop_current();
  }
  void draw() override {
    if (offs) {
      //fl_rescale_offscreen(offs);
      //fl_copy_offscreen(x(), y(), w(), h(), offs, 0, 0);
      Fl_RGB_Image *img = offs->image();
      img->scale(w(), h(), 0, 1);
      img->draw(x(), y());
      delete img;
    }
    Fl_Box::draw();
  }
  int handle(int e) override {
    auto ret = Fl_Box::handle(e);
    switch (e) {
    case FL_PUSH: {
      //fl_begin_offscreen(offs);
      Fl_Surface_Device::push_current(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();
      Fl_Surface_Device::pop_current();
      redraw();
  //fl_line_style(FL_SOLID, 0);//incorrect here because not a drawing context
      return true;
    }
    case FL_DRAG: {
      //fl_begin_offscreen(offs);
      Fl_Surface_Device::push_current(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();
      Fl_Surface_Device::pop_current();
      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();
}


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/1207752644@github.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'.