diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2021-03-11 16:05:20 +0100 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2021-03-11 16:05:32 +0100 |
| commit | 569fec25e0454c4e4b98dcc383143a357ca50b55 (patch) | |
| tree | c38048366a56a901a66465fdaca6628d0e03405a /src/Fl_Graphics_Driver.cxx | |
| parent | bd6c9854342094e2de8183aaab740804c1a6fc1f (diff) | |
Unification of scaled coordinate calculations in class Fl_Scalable_Graphics_Driver
Most coordinate calculations are done with the new inline function
int Fl_Scalable_Graphics_Driver::floor(int coord)
that is used by both the Windows and X11 platforms.
Diffstat (limited to 'src/Fl_Graphics_Driver.cxx')
| -rw-r--r-- | src/Fl_Graphics_Driver.cxx | 178 |
1 files changed, 97 insertions, 81 deletions
diff --git a/src/Fl_Graphics_Driver.cxx b/src/Fl_Graphics_Driver.cxx index f1164c19e..5386d5290 100644 --- a/src/Fl_Graphics_Driver.cxx +++ b/src/Fl_Graphics_Driver.cxx @@ -345,14 +345,14 @@ void Fl_Graphics_Driver::xyline(int x, int y, int x1) { } void Fl_Graphics_Driver::xyline(int x, int y, int x1, int y2) { - line(x, y, x1, y); - line(x1, y, x1, y2); + xyline(x, y, x1); + yxline(x1, y, y2); } void Fl_Graphics_Driver::xyline(int x, int y, int x1, int y2, int x3) { - line(x, y, x1, y); - line(x1, y, x1, y2); - line(x1, y2, x3, y2); + xyline(x, y, x1); + yxline(x1, y, y2); + xyline(x1, y2, x3); } void Fl_Graphics_Driver::yxline(int x, int y, int y1) { @@ -360,14 +360,14 @@ void Fl_Graphics_Driver::yxline(int x, int y, int y1) { } void Fl_Graphics_Driver::yxline(int x, int y, int y1, int x2) { - line(x, y, x, y1); - line(x, y1, x2, y1); + yxline(x, y, y1); + xyline(x, y1, x2); } void Fl_Graphics_Driver::yxline(int x, int y, int y1, int x2, int y3) { - line(x, y, x, y1); - line(x, y1, x2, y1); - line(x2, y1, x2, y3); + yxline(x, y, y1); + xyline(x, y1, x2); + yxline(x2, y1, y3); } void Fl_Graphics_Driver::line(int x, int y, int x1, int y1, int x2, int y2) { @@ -692,72 +692,79 @@ Fl_Scalable_Graphics_Driver::Fl_Scalable_Graphics_Driver() : Fl_Graphics_Driver( void Fl_Scalable_Graphics_Driver::rect(int x, int y, int w, int h) { - if (int(scale()) == scale()) { - rect_unscaled(x * scale(), y * scale(), w * scale(), h * scale()); - } else { - if (w > 0 && h > 0) { - xyline(x, y, x+w-1); - yxline(x, y, y+h-1); - yxline(x+w-1, y, y+h-1); - xyline(x, y+h-1, x+w-1); - } + if (w > 0 && h > 0) { + xyline(x, y, x+w-1); + yxline(x, y, y+h-1); + yxline(x+w-1, y, y+h-1); + xyline(x, y+h-1, x+w-1); } } void Fl_Scalable_Graphics_Driver::rectf(int x, int y, int w, int h) { - rectf_unscaled(x * scale(), y * scale(), w * scale(), h * scale()); + if (w <= 0 || h <= 0) return; + rectf_unscaled(this->floor(x), this->floor(y), + this->floor(x + w) - this->floor(x), this->floor(y + h) - this->floor(y)); } void Fl_Scalable_Graphics_Driver::point(int x, int y) { - point_unscaled(x * scale(), y * scale()); + rectf(x, y, 1, 1); } void Fl_Scalable_Graphics_Driver::line(int x, int y, int x1, int y1) { if (y == y1) xyline(x, y, x1); else if (x == x1) yxline(x, y, y1); - else line_unscaled( x*scale(), y*scale(), x1*scale(), y1*scale()); + else line_unscaled(this->floor(x), this->floor(y), this->floor(x1), this->floor(y1)); } void Fl_Scalable_Graphics_Driver::line(int x, int y, int x1, int y1, int x2, int y2) { - if ( (y == y1 || x == x1) && (y2 == y1 || x2 == x1) ) { // only horizontal or vertical lines - line(x, y, x1, y1); - line(x1, y1, x2, y2); - } else line_unscaled( x*scale(), y*scale(), x1*scale(), y1*scale(), x2*scale(), y2*scale()); + line_unscaled(this->floor(x), this->floor(y), this->floor(x1), this->floor(y1), this->floor(x2), this->floor(y2)); } void Fl_Scalable_Graphics_Driver::xyline(int x, int y, int x1) { - xyline_unscaled(x*scale(), y*scale(), x1*scale()); -} - -void Fl_Scalable_Graphics_Driver::xyline(int x, int y, int x1, int y2) { - xyline(x, y, x1); - yxline(x1, y, y2); -} - -void Fl_Scalable_Graphics_Driver::xyline(int x, int y, int x1, int y2, int x3) { - xyline(x, y, x1); - yxline(x1, y, y2); - xyline(x1, y2, x3); + if (y < 0) return; + float s = scale(); int s_int = int(s); + int xx = (x < x1 ? x : x1); + int xx1 = (x < x1 ? x1 : x); + if (s != s_int && line_width_ <= s_int) { + int lwidth = this->floor((y+1)) - this->floor(y); + bool need_change_width = (lwidth != s_int); + void *data = NULL; + if (need_change_width) data = change_pen_width(lwidth); + xyline_unscaled(this->floor(xx), this->floor(y) + int(lwidth/2.f), this->floor(xx1+1)-1); + if (need_change_width) reset_pen_width(data); + } else { + y = this->floor(y); + if (line_width_ <= s_int) y += int(s/2.f); + xyline_unscaled(this->floor(xx), y, this->floor(xx1+1) - 1); + } } void Fl_Scalable_Graphics_Driver::yxline(int x, int y, int y1) { - yxline_unscaled(x*scale(), y*scale(), y1*scale()); + if (x < 0) return; + float s = scale(); int s_int = int(s); + int yy = (y < y1 ? y : y1); + int yy1 = (y < y1 ? y1 : y); + if (s != s_int && line_width_ <= s_int) { + int lwidth = (this->floor((x+1)) - this->floor(x)); + bool need_change_width = (lwidth != s_int); + void *data = NULL; + if (need_change_width) data = change_pen_width(lwidth); + yxline_unscaled(this->floor(x) + int(lwidth/2.f), this->floor(yy), this->floor(yy1+1) - 1); + if (need_change_width) reset_pen_width(data); + } else { + x = this->floor(x); + if (line_width_ <= s_int) x += int(s/2.f); + yxline_unscaled(x, this->floor(yy), this->floor(yy1+1) - 1); + } } -void Fl_Scalable_Graphics_Driver::yxline(int x, int y, int y1, int x2) { - yxline(x, y, y1); - xyline(x, y1, x2); -} +void *Fl_Scalable_Graphics_Driver::change_pen_width(int lwidth) {return NULL;} -void Fl_Scalable_Graphics_Driver::yxline(int x, int y, int y1, int x2, int y3) { - yxline(x, y, y1); - xyline(x, y1, x2); - yxline(x2, y1, y3); -} +void Fl_Scalable_Graphics_Driver::reset_pen_width(void *data){} void Fl_Scalable_Graphics_Driver::loop(int x0, int y0, int x1, int y1, int x2, int y2) { - loop_unscaled(x0*scale(), y0*scale(), x1*scale(), y1*scale(), x2*scale(), y2*scale()); + loop_unscaled(floor(x0), floor(y0), floor(x1), floor(y1), floor(x2), floor(y2)); } void Fl_Scalable_Graphics_Driver::loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3) { @@ -775,17 +782,16 @@ void Fl_Scalable_Graphics_Driver::loop(int x0, int y0, int x1, int y1, int x2, i H = abs(y0 - y1); rect(X, Y, W + 1, H + 1); } else { - float s = scale(); - loop_unscaled(x0*s, y0*s, x1*s, y1*s, x2*s, y2*s, x3*s, y3*s); + loop_unscaled(floor(x0), floor(y0), floor(x1), floor(y1), floor(x2), floor(y2), floor(x3), floor(y3)); } } void Fl_Scalable_Graphics_Driver::polygon(int x0, int y0, int x1, int y1, int x2, int y2) { - polygon_unscaled(x0*scale(), y0*scale(), x1*scale(), y1*scale(), x2*scale(), y2*scale()); + polygon_unscaled(floor(x0), floor(y0), floor(x1), floor(y1), floor(x2), floor(y2)); } void Fl_Scalable_Graphics_Driver::polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3) { - polygon_unscaled(x0*scale(), y0*scale(), x1*scale(), y1*scale(), x2*scale(), y2*scale(), x3*scale(), y3*scale()); + polygon_unscaled(floor(x0), floor(y0), floor(x1), floor(y1), floor(x2), floor(y2), floor(x3), floor(y3)); } void Fl_Scalable_Graphics_Driver::circle(double x, double y, double r) { @@ -837,7 +843,7 @@ int Fl_Scalable_Graphics_Driver::descent() { void Fl_Scalable_Graphics_Driver::draw(const char *str, int n, int x, int y) { if (!size_ || !font_descriptor()) font(FL_HELVETICA, FL_NORMAL_SIZE); Fl_Region r2 = scale_clip(scale()); - draw_unscaled(str, n, int(x*scale()), int(y*scale())); + draw_unscaled(str, n, floor(x), floor(y)); unscale_clip(r2); } @@ -848,7 +854,7 @@ void Fl_Scalable_Graphics_Driver::draw(const char *str, int n, float x, float y) void Fl_Scalable_Graphics_Driver::draw(int angle, const char *str, int n, int x, int y) { if (!size_ || !font_descriptor()) font(FL_HELVETICA, FL_NORMAL_SIZE); Fl_Region r2 = scale_clip(scale()); - draw_unscaled(angle, str, n, int(x*scale()), int(y*scale())); + draw_unscaled(angle, str, n, floor(x), floor(y)); unscale_clip(r2); } @@ -856,8 +862,13 @@ void Fl_Scalable_Graphics_Driver::rtl_draw(const char* str, int n, int x, int y) rtl_draw_unscaled(str, n, int(x * scale()), int(y * scale())); } -void Fl_Scalable_Graphics_Driver::arc(int x,int y,int w,int h,double a1,double a2) { - arc_unscaled(x * scale(), y * scale(), w * scale(), h * scale(), a1, a2); +void Fl_Scalable_Graphics_Driver::arc(int x, int y, int w, int h, double a1, double a2) { + float s = scale(); + int xx = floor(x) + int((s-1)/2); + int yy = floor(y) + int((s-1)/2); + w = floor(x+w) - xx - 1 + line_width_/2 - int(s-1); + h = floor(y+h) - yy - 1 + line_width_/2 - int(s-1); + arc_unscaled(xx, yy, w, h, a1, a2); } void Fl_Scalable_Graphics_Driver::arc(double x, double y, double r, double start, double end) { @@ -865,18 +876,22 @@ void Fl_Scalable_Graphics_Driver::arc(double x, double y, double r, double start } void Fl_Scalable_Graphics_Driver::pie(int x,int y,int w,int h,double a1,double a2) { - pie_unscaled(x * scale(), y * scale(), w * scale(), h * scale(), a1, a2); + int xx = floor(x) - 1; + int yy = floor(y) - 1; + w = floor(x+w) - xx; + h = floor(y+h) - yy; + pie_unscaled(xx, yy, w, h, a1, a2); } void Fl_Scalable_Graphics_Driver::line_style(int style, int width, char* dashes) { if (width == 0) line_width_ = int(scale() < 2 ? 0 : scale()); else line_width_ = int(width>0 ? width*scale() : -width*scale()); - line_style_unscaled(style, float(line_width_), dashes); + line_style_unscaled(style, line_width_, dashes); } /* read the image data from a pointer or with a callback, scale it, and draw it */ void Fl_Scalable_Graphics_Driver::draw_image_rescale(void *buf, Fl_Draw_Image_Cb cb, - int X, int Y, int W, int H, int D, int L, bool mono, float s) { + int X, int Y, int W, int H, int D, int L, bool mono) { int aD = abs(D); if (L == 0) L = W*aD; int depth = mono ? (aD%2==0?2:1) : aD; @@ -899,12 +914,12 @@ void Fl_Scalable_Graphics_Driver::draw_image_rescale(void *buf, Fl_Draw_Image_Cb rgb->alloc_array = 1; Fl_RGB_Scaling keep = Fl_Image::RGB_scaling(); Fl_Image::RGB_scaling(Fl_Image::scaling_algorithm()); - Fl_RGB_Image *scaled_rgb = (Fl_RGB_Image*)rgb->copy(int(ceil(W * s)), int(ceil(H * s))); + Fl_RGB_Image *scaled_rgb = (Fl_RGB_Image*)rgb->copy(floor(X+W)-floor(X), floor(Y+H)-floor(Y)); Fl_Image::RGB_scaling(keep); delete rgb; if (scaled_rgb) { - Fl_Region r2 = scale_clip(s); - draw_image_unscaled(scaled_rgb->array, int(X * s), int(Y * s), scaled_rgb->w(), scaled_rgb->h(), depth); + Fl_Region r2 = scale_clip(scale()); + draw_image_unscaled(scaled_rgb->array, floor(X), floor(Y), scaled_rgb->w(), scaled_rgb->h(), depth); unscale_clip(r2); delete scaled_rgb; } @@ -914,7 +929,7 @@ void Fl_Scalable_Graphics_Driver::draw_image(const uchar* buf, int X,int Y,int W if (scale() == 1) { draw_image_unscaled(buf, X,Y,W,H,D,L); } else { - draw_image_rescale((void*)buf, NULL, X, Y, W, H, D, L, false, scale()); + draw_image_rescale((void*)buf, NULL, X, Y, W, H, D, L, false); } } @@ -922,7 +937,7 @@ void Fl_Scalable_Graphics_Driver::draw_image(Fl_Draw_Image_Cb cb, void* data, in if (scale() == 1) { draw_image_unscaled(cb, data, X,Y,W,H,D); } else { - draw_image_rescale(data, cb, X, Y, W, H, D, 0, false, scale()); + draw_image_rescale(data, cb, X, Y, W, H, D, 0, false); } } @@ -930,7 +945,7 @@ void Fl_Scalable_Graphics_Driver::draw_image_mono(const uchar* buf, int X,int Y, if (scale() == 1) { draw_image_mono_unscaled(buf, X,Y,W,H,D,L); } else { - draw_image_rescale((void*)buf, NULL, X, Y, W, H, D, L, true, scale()); + draw_image_rescale((void*)buf, NULL, X, Y, W, H, D, L, true); } } @@ -938,7 +953,7 @@ void Fl_Scalable_Graphics_Driver::draw_image_mono(Fl_Draw_Image_Cb cb, void* dat if (scale() == 1) { draw_image_mono_unscaled(cb, data, X,Y,W,H,D); } else { - draw_image_rescale(data, cb, X, Y, W, H, D, 0, true, scale()); + draw_image_rescale(data, cb, X, Y, W, H, D, 0, true); } } @@ -961,25 +976,26 @@ Fl_Region Fl_Scalable_Graphics_Driver::scale_clip(float f) { return 0; } void Fl_Scalable_Graphics_Driver::point_unscaled(float x, float y) {} -void Fl_Scalable_Graphics_Driver::rect_unscaled(float x, float y, float w, float h) {} +void Fl_Scalable_Graphics_Driver::rectf_unscaled(int x, int y, int w, int h) {} -void Fl_Scalable_Graphics_Driver::rectf_unscaled(float x, float y, float w, float h) {} +void Fl_Scalable_Graphics_Driver::line_unscaled(int x, int y, int x1, int y1) {} -void Fl_Scalable_Graphics_Driver::line_unscaled(float x, float y, float x1, float y1) {} - -void Fl_Scalable_Graphics_Driver::line_unscaled(float x, float y, float x1, float y1, float x2, float y2) {} +void Fl_Scalable_Graphics_Driver::line_unscaled(int x, int y, int x1, int y1, int x2, int y2) { + line_unscaled(x, y, x1, y1); + line_unscaled(x1, y1, x2, y2); +} -void Fl_Scalable_Graphics_Driver::xyline_unscaled(float x, float y, float x1) {} +void Fl_Scalable_Graphics_Driver::xyline_unscaled(int x, int y, int x1) {} -void Fl_Scalable_Graphics_Driver::yxline_unscaled(float x, float y, float y1) {} +void Fl_Scalable_Graphics_Driver::yxline_unscaled(int x, int y, int y1) {} -void Fl_Scalable_Graphics_Driver::loop_unscaled(float x0, float y0, float x1, float y1, float x2, float y2) {} +void Fl_Scalable_Graphics_Driver::loop_unscaled(int x0, int y0, int x1, int y1, int x2, int y2) {} -void Fl_Scalable_Graphics_Driver::loop_unscaled(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) {} +void Fl_Scalable_Graphics_Driver::loop_unscaled(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3) {} -void Fl_Scalable_Graphics_Driver::polygon_unscaled(float x0, float y0, float x1, float y1, float x2, float y2) {} +void Fl_Scalable_Graphics_Driver::polygon_unscaled(int x0, int y0, int x1, int y1, int x2, int y2) {} -void Fl_Scalable_Graphics_Driver::polygon_unscaled(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) {} +void Fl_Scalable_Graphics_Driver::polygon_unscaled(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3) {} void Fl_Scalable_Graphics_Driver::ellipse_unscaled(double xt, double yt, double rx, double ry) {} @@ -1003,11 +1019,11 @@ void Fl_Scalable_Graphics_Driver::draw_unscaled(int angle, const char *str, int void Fl_Scalable_Graphics_Driver::rtl_draw_unscaled(const char* str, int n, int x, int y) {} -void Fl_Scalable_Graphics_Driver::arc_unscaled(float x, float y, float w, float h, double a1, double a2) {} +void Fl_Scalable_Graphics_Driver::arc_unscaled(int x, int y, int w, int h, double a1, double a2) {} -void Fl_Scalable_Graphics_Driver::pie_unscaled(float x, float y, float w, float h, double a1, double a2) {} +void Fl_Scalable_Graphics_Driver::pie_unscaled(int x, int y, int w, int h, double a1, double a2) {} -void Fl_Scalable_Graphics_Driver::line_style_unscaled(int style, float width, char* dashes) {} +void Fl_Scalable_Graphics_Driver::line_style_unscaled(int style, int width, char* dashes) {} void Fl_Scalable_Graphics_Driver::draw_image_unscaled(const uchar* buf, int X,int Y,int W,int H, int D, int L) {} |
