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/drivers/GDI/Fl_GDI_Graphics_Driver_rect.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/drivers/GDI/Fl_GDI_Graphics_Driver_rect.cxx')
| -rw-r--r-- | src/drivers/GDI/Fl_GDI_Graphics_Driver_rect.cxx | 145 |
1 files changed, 42 insertions, 103 deletions
diff --git a/src/drivers/GDI/Fl_GDI_Graphics_Driver_rect.cxx b/src/drivers/GDI/Fl_GDI_Graphics_Driver_rect.cxx index 4a8daebb1..e7aac901c 100644 --- a/src/drivers/GDI/Fl_GDI_Graphics_Driver_rect.cxx +++ b/src/drivers/GDI/Fl_GDI_Graphics_Driver_rect.cxx @@ -47,16 +47,6 @@ void Fl_GDI_Graphics_Driver::overlay_rect(int x, int y, int w , int h) { LineTo(gc_, x, y); } -void Fl_GDI_Graphics_Driver::rect(int x, int y, int w, int h) -{ - 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_GDI_Graphics_Driver::focus_rect(int x, int y, int w, int h) { // Windows 95/98/ME do not implement the dotted line style, so draw // every other pixel around the focus area... @@ -71,127 +61,76 @@ void Fl_GDI_Graphics_Driver::focus_rect(int x, int y, int w, int h) { for (yy = h; yy > 0; yy--, i++) if (i & 1) SetPixel(gc_, x, y+yy, c); } -void Fl_GDI_Graphics_Driver::rectf(int x, int y, int w, int h) { - if (w<=0 || h<=0) return; +void Fl_GDI_Graphics_Driver::rectf_unscaled(int x, int y, int w, int h) { RECT rect; - rect.left = this->floor(x); rect.top = this->floor(y); - rect.right = this->floor(x + w); rect.bottom = this->floor(y + h); + rect.left = x; rect.top = y; + rect.right = (x + w); rect.bottom = (y + h); FillRect(gc_, &rect, fl_brush()); } -void Fl_GDI_Graphics_Driver::line_unscaled(float x, float y, float x1, float y1) { - MoveToEx(gc_, int(x), int(y), 0L); - LineTo(gc_, int(x1), int(y1)); - SetPixel(gc_, int(x1), int(y1), fl_RGB()); +void Fl_GDI_Graphics_Driver::line_unscaled(int x, int y, int x1, int y1) { + MoveToEx(gc_, x, y, 0L); + LineTo(gc_, x1, y1); + SetPixel(gc_, x1, y1, fl_RGB()); } -void Fl_GDI_Graphics_Driver::line_unscaled(float x, float y, float x1, float y1, float x2, float y2) { - MoveToEx(gc_, int(x), int(y), 0L); - LineTo(gc_, int(x1), int(y1)); - LineTo(gc_, int(x2), int(y2)); - SetPixel(gc_, int(x2), int(y2), fl_RGB()); +void Fl_GDI_Graphics_Driver::line_unscaled(int x, int y, int x1, int y1, int x2, int y2) { + MoveToEx(gc_, x, y, 0L); + LineTo(gc_, x1, y1); + LineTo(gc_, x2, y2); + SetPixel(gc_, x2, y2, fl_RGB()); } -static HPEN change_pen_width(int width, HDC gc) { // set the width of the pen, return previous pen +void* Fl_GDI_Graphics_Driver::change_pen_width(int width) { // set the width of the pen, return previous pen LOGBRUSH penbrush = {BS_SOLID, fl_RGB(), 0}; HPEN newpen = ExtCreatePen(PS_GEOMETRIC | PS_ENDCAP_FLAT | PS_JOIN_ROUND, width, &penbrush, 0, 0); - return (HPEN)SelectObject(gc, newpen); -} - -void Fl_GDI_Graphics_Driver::xyline(int x, int y, int x1) { - if (y < 0) return; - float s = scale(); - int xx = (x < x1 ? x : x1); - int xx1 = (x < x1 ? x1 : x); - if (s != int(s) && line_width_ <= int(s)) { - int lwidth = this->floor((y+1)) - this->floor(y); - bool need_pen = (lwidth != int(s)); - HPEN oldpen = (need_pen ? change_pen_width(lwidth, gc_) : NULL); - MoveToEx(gc_, this->floor(xx), this->floor(y) + int(lwidth/2.f) , 0L); - LineTo(gc_, this->floor((xx1+1)), this->floor(y) + int(lwidth/2.f)); - if (need_pen) { - DeleteObject(SelectObject(gc_, oldpen)); - } - } else { - y = int((y + 0.5f) * s); - MoveToEx(gc_, this->floor(xx), y, 0L); - LineTo(gc_, this->floor(xx1) + int(s) , y); - } -} - -void Fl_GDI_Graphics_Driver::xyline(int x, int y, int x1, int y2) { - xyline(x, y, x1); - yxline(x1, y, y2); -} - -void Fl_GDI_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); + return SelectObject(gc_, newpen); } -void Fl_GDI_Graphics_Driver::yxline(int x, int y, int y1) { - if (x < 0) return; - double s = scale(); - int yy = (y < y1 ? y : y1); - int yy1 = (y < y1 ? y1 : y); - if (s != int(s) && line_width_ <= int(s)) { - int lwidth = (this->floor((x+1)) - this->floor(x)); - bool need_pen = (lwidth != int(s)); - HPEN oldpen = (need_pen ? change_pen_width(lwidth, gc_) : NULL); - MoveToEx(gc_, this->floor(x) + int(lwidth/2.f), this->floor(yy), 0L); - LineTo(gc_, this->floor(x) + int(lwidth/2.f), this->floor((yy1+1)) ); - if (need_pen) { - DeleteObject(SelectObject(gc_, oldpen)); - } - } else { - x = int((x + 0.5f) * s); - MoveToEx(gc_, x, this->floor(yy), 0L); - LineTo(gc_, x, this->floor(yy1) + int(s)); - } +void Fl_GDI_Graphics_Driver::reset_pen_width(void *data) { + DeleteObject(SelectObject(gc_, (HPEN)data)); } -void Fl_GDI_Graphics_Driver::yxline(int x, int y, int y1, int x2) { - yxline(x, y, y1); - xyline(x, y1, x2); +void Fl_GDI_Graphics_Driver::xyline_unscaled(int x, int y, int x1) { + MoveToEx(gc_, x, y, 0L); + LineTo(gc_, x1+1 , y); } -void Fl_GDI_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_GDI_Graphics_Driver::yxline_unscaled(int x, int y, int y1) { + MoveToEx(gc_, x, y, 0L); + LineTo(gc_, x, y1+1); } -void Fl_GDI_Graphics_Driver::loop_unscaled(float x, float y, float x1, float y1, float x2, float y2) { - MoveToEx(gc_, int(x), int(y), 0L); - LineTo(gc_, int(x1), int(y1)); - LineTo(gc_, int(x2), int(y2)); - LineTo(gc_, int(x), int(y)); +void Fl_GDI_Graphics_Driver::loop_unscaled(int x, int y, int x1, int y1, int x2, int y2) { + MoveToEx(gc_, x, y, 0L); + LineTo(gc_, x1, y1); + LineTo(gc_, x2, y2); + LineTo(gc_, x, y); } -void Fl_GDI_Graphics_Driver::loop_unscaled(float x, float y, float x1, float y1, float x2, float y2, float x3, float y3) { - MoveToEx(gc_, int(x), int(y), 0L); - LineTo(gc_, int(x1), int(y1)); - LineTo(gc_, int(x2), int(y2)); - LineTo(gc_, int(x3), int(y3)); - LineTo(gc_, int(x), int(y)); +void Fl_GDI_Graphics_Driver::loop_unscaled(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) { + MoveToEx(gc_, x, y, 0L); + LineTo(gc_, x1, y1); + LineTo(gc_, x2, y2); + LineTo(gc_, x3, y3); + LineTo(gc_, x, y); } -void Fl_GDI_Graphics_Driver::polygon_unscaled(float x, float y, float x1, float y1, float x2, float y2) { +void Fl_GDI_Graphics_Driver::polygon_unscaled(int x, int y, int x1, int y1, int x2, int y2) { POINT p[3]; - p[0].x = int(x); p[0].y = int(y); - p[1].x = int(x1); p[1].y = int(y1); - p[2].x = int(x2); p[2].y = int(y2); + p[0].x = x; p[0].y = y; + p[1].x = x1; p[1].y = y1; + p[2].x = x2; p[2].y = y2; SelectObject(gc_, fl_brush()); Polygon(gc_, p, 3); } -void Fl_GDI_Graphics_Driver::polygon_unscaled(float x, float y, float x1, float y1, float x2, float y2, float x3, float y3) { +void Fl_GDI_Graphics_Driver::polygon_unscaled(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) { POINT p[4]; - p[0].x = int(x); p[0].y = int(y); - p[1].x = int(x1); p[1].y = int(y1); - p[2].x = int(x2); p[2].y = int(y2); - p[3].x = int(x3); p[3].y = int(y3); + p[0].x = x; p[0].y = y; + p[1].x = x1; p[1].y = y1; + p[2].x = x2; p[2].y = y2; + p[3].x = x3; p[3].y = y3; SelectObject(gc_, fl_brush()); Polygon(gc_, p, 4); } |
