diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2018-03-15 16:52:27 +0000 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2018-03-15 16:52:27 +0000 |
| commit | 726cb77717e00de9cd6d9accad0a69f4ae7a6859 (patch) | |
| tree | b74cffe58b721b02bc749e34a86004e783385d8f /src | |
| parent | 7d985f842ac3e396dfcc3418f56f7f0c3a98d659 (diff) | |
Improve X11 coordinate clipping.
Make clipping methods non-virtual so they can be inlined.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12753 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H | 35 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver_rect.cxx | 20 |
2 files changed, 23 insertions, 32 deletions
diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H index 96126cf21..91badcb47 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H @@ -153,24 +153,35 @@ protected: virtual void polygon_unscaled(float x0, float y0, float x1, float y1, float x2, float y2); virtual void polygon_unscaled(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3); - // --- clipped drawing (after scaling, with real screen coordinates) - // --- currently specific to Fl_Xlib_Graphics_Driver (16-bit coordinate clipping) + // Scaling and clipping stuff for internal usage. + // Currently specific to Fl_Xlib_Graphics_Driver (16-bit coordinate clipping) + // These methods must not be virtual so they can be inlined. + // All these methods work with "real" drawing coordinates (after scaling). - // clipping limits - virtual int clip_max() { return clip_max_; } - virtual int clip_min() { return -clip_max_; } + // Clipping limits + int clip_max() { return clip_max_; } + int clip_min() { return -clip_max_; } - // clip one coordinate (x or y) - virtual int clip_xy(int x); + /* + clip_xy() returns a single coordinate value clipped to the 16-bit + coordinate space. - // clip one line - virtual int clip_line(int &x1, int &y1, int &x2, int &y2); + This can be used to draw horizontal and vertical lines that can be + handled by X. Each single coordinate value can be clipped individually + and the result can be used directly, e.g. in fl_xyline() and fl_yxline(). + */ + int clip_xy(int x) { + return (x < clip_min() ? clip_min() : (x > clip_max() ? clip_max() : x )); + } - // clip one rectangle - virtual int clip_rect(int &x, int &y, int &w, int &h); + // clip an arbitrary line + int clip_line(int &x1, int &y1, int &x2, int &y2); + + // clip a rectangle + int clip_rect(int &x, int &y, int &w, int &h); // draw a line after clipping (if visible) - virtual void draw_clipped_line(int x1, int y1, int x2, int y2); + void draw_clipped_line(int x1, int y1, int x2, int y2); // --- clipping void push_clip(int x, int y, int w, int h); diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_rect.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_rect.cxx index 1080bd360..7ba5490b5 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_rect.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_rect.cxx @@ -188,26 +188,6 @@ int Fl_Xlib_Graphics_Driver::clip_rect(int &x, int &y, int &w, int &h) { return 0; } -/* - clip_xy() returns a single coordinate value clipped to the 16-bit - coordinate space. - - This can be used to draw horizontal and vertical lines that can be - handled by X. Each single coordinate value can be clipped individually - and the result can be used directly, e.g. in fl_xyline() and fl_yxline(). - - Note 1: this can't be used for arbitrary lines (neither horizontal nor vertical). - Note 2: may be changed since Fl_Xlib_Graphics_Driver::clip_line() exists. -*/ - -int Fl_Xlib_Graphics_Driver::clip_xy(int x) { - - if (x < clip_min()) - x = clip_min(); - else if (x > clip_max()) - x = clip_max(); - return x; -} // Missing X call: (is this the fastest way to init a 1-rectangle region?) // Windows equivalent exists, implemented inline in win32.H |
