Re: [LOW] STR #3134: fl_clip_box fails on X11 with large coordinates

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

Re: [LOW] STR #3134: fl_clip_box fails on X11 with large coordinates Albrecht Schlosser 06:41 May 26 top right image
 
[STR Closed w/Resolution]

Link: https://www.fltk.org/str.php?L3134
Version: 1.3-current
Fix Version: 1.4.0
Git Commit: 12c050980692c05fb3eb59acd7aba6a46bea4bf8


Thanks to ajapted for the report, and sorry for the late reply and fix.

As suggested, the given rectangle is now "pre-clipped" to the X11 16-bit
coordinate range and then used internally to calculate the clipping box.

Uploaded demo program clip_box.cxx shows the effect with some example
clipping values. See example code for details.

FTR, output on Linux/X11, clipped to 16-bit coordinates:

---  NO CLIPPING  ---
fl_clip_box(    100,     100,    200,    200) => 0 (    100,     100,   
200,    200)
fl_clip_box(-100000, -100000, 200000, 200000) => 1 ( -32760,  -32760, 
65520,  65520)
fl_clip_box( -33000,  -33000,   2000,   2000) => 1 ( -32760,  -32760,  
1760,   1760)
fl_clip_box(   -100,    -100,    180,    100) => 0 (   -100,    -100,   
180,    100)
fl_clip_box(   -100,    -100,    180,    200) => 0 (   -100,    -100,   
180,    200)

---  CLIP TO BOX (20, 20, 80, 25)  ---
fl_clip_box(    100,     100,    200,    200) => 2 (    100,     100,     
0,      0)
fl_clip_box(-100000, -100000, 200000, 200000) => 1 (     20,      20,    
80,     25)
fl_clip_box( -33000,  -33000,   2000,   2000) => 2 ( -32760,  -32760,     
0,      0)
fl_clip_box(   -100,    -100,    180,    100) => 2 (   -100,    -100,     
0,      0)
fl_clip_box(   -100,    -100,    180,    200) => 1 (     20,      20,    
60,     25)

For comparison, output on Windows, using full 32-bit coordinate space:

---  NO CLIPPING  ---
fl_clip_box(    100,     100,    200,    200) => 0 (    100,     100,   
200,    200)
fl_clip_box(-100000, -100000, 200000, 200000) => 0 (-100000, -100000,
200000, 200000)
fl_clip_box( -33000,  -33000,   2000,   2000) => 0 ( -33000,  -33000,  
2000,   2000)
fl_clip_box(   -100,    -100,    180,    100) => 0 (   -100,    -100,   
180,    100)
fl_clip_box(   -100,    -100,    180,    200) => 0 (   -100,    -100,   
180,    200)

---  CLIP TO BOX (20, 20, 80, 25)  ---
fl_clip_box(    100,     100,    200,    200) => 2 (    100,     100,     
0,      0)
fl_clip_box(-100000, -100000, 200000, 200000) => 1 (     20,      20,    
80,     25)
fl_clip_box( -33000,  -33000,   2000,   2000) => 2 ( -33000,  -33000,     
0,      0)
fl_clip_box(   -100,    -100,    180,    100) => 2 (   -100,    -100,     
0,      0)
fl_clip_box(   -100,    -100,    180,    200) => 1 (     20,      20,    
60,     25)


Link: https://www.fltk.org/str.php?L3134
Version: 1.3-current
Fix Version: 1.4.0
Git Commit: 12c050980692c05fb3eb59acd7aba6a46bea4bf8
/*
  fl_clip_box() test program for the Fast Light Tool Kit (FLTK).
*/

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Box.H>
#include <FL/fl_draw.H>

void exitcb(Fl_Widget *w, void *) {
  w->window()->hide();
}

// helper function to test clipping, prints clip results
void test_clip_box(int x, int y, int w, int h) {
  int X = -999, Y = -999, W = -999, H = -999;
  int ret = fl_clip_box(x, y, w, h, X, Y, W, H);
  printf("fl_clip_box(%7d, %7d, %6d, %6d) => %d (%7d, %7d, %6d, %6d)\n",
         x, y, w, h, ret, X, Y, W, H);
  return;
}

// test clipping with several special test cases
void test_clip() {
  test_clip_box(100, 100, 200, 200);
  test_clip_box(-100000, -100000, 200000, 200000);
  test_clip_box(-33000, -33000, 2000, 2000);
  test_clip_box(-100, -100, 180, 100);
  test_clip_box(-100, -100, 180, 200);
}

class myBox : public Fl_Box {
public:
  myBox(int x,int y, int w, int h, const char *L) : Fl_Box(x,y,w,h,L) {}
  void draw() {

    printf("\n---  NO CLIPPING  ---\n");
    fl_push_no_clip();
    test_clip();
    fl_pop_clip();

    printf("\n---  CLIP TO BOX (%d, %d, %d, %d)  ---\n", x(), y(), w(), h());
    fl_push_clip(x(), y(), w(), h());
    test_clip();
    fl_pop_clip();

    draw_box();
    draw_label();
  }
};

int main(int argc, char ** argv) {
  Fl_Window *window = new Fl_Window(320, 65, "test fl_clip_box()");
  myBox *b1 = new myBox(20, 20, 80, 25, "LABEL");
  b1->box(FL_FRAME_BOX);
  Fl_Button *b2 = new Fl_Button(220,20, 80, 25, "E&xit");
  b2->callback(exitcb, 0);
  window->end();
  window->resizable(window);
  window->size_range(window->w(), window->h());
  window->show(argc,argv);
  return Fl::run();
}
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'.