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/Xlib/Fl_Xlib_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/Xlib/Fl_Xlib_Graphics_Driver_rect.cxx')
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver_rect.cxx | 141 |
1 files changed, 52 insertions, 89 deletions
diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_rect.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_rect.cxx index 4a2b48af9..7bf905fd5 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_rect.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_rect.cxx @@ -208,123 +208,86 @@ void Fl_Xlib_Graphics_Driver::XDestroyRegion(Fl_Region r) { // --- line and polygon drawing -// called only when scale_ has integer value -void Fl_Xlib_Graphics_Driver::rect_unscaled(float fx, float fy, float fw, float fh) { - if (fw<=0 || fh<=0) return; - int deltaf = scale() >= 2 ? scale()-1 : 0; - fx += offset_x_*scale(); fy += offset_y_*scale(); - int x = fx; int y = fy; - int w = int(fw) - 1 - deltaf; - int h = int(fh) - 1 - deltaf; - if (!clip_rect(x, y, w, h)) - XDrawRectangle(fl_display, fl_window, gc_, x+line_delta_, y+line_delta_, w, h); +void Fl_Xlib_Graphics_Driver::focus_rect(int x, int y, int w, int h) +{ + w = this->floor(x + w) - this->floor(x); + h = this->floor(y + h) - this->floor(y); + x = this->floor(x) + floor(offset_x_); + y = this->floor(y) + floor(offset_y_); + if (!clip_rect(x, y, w, h)) { + line_style(FL_DOT); + XDrawRectangle(fl_display, fl_window, gc_, x, y, w, h); + line_style(FL_SOLID); + } } -void Fl_Xlib_Graphics_Driver::rectf_unscaled(float fx, float fy, float fw, float fh) { - if (fw<=0 || fh<=0) return; - int deltaf = scale() >= 2 ? scale()/2 : 0; - fx += offset_x_*scale(); fy += offset_y_*scale(); - int x = fx-deltaf; int y = fy-deltaf; - // make sure no unfilled area lies between rectf(x,y,w,h) and rectf(x+w,y,1,h) or rectf(x,y+w,w,1) - int w = int(int(fx/scale()+fw/scale()+0.5)*scale()) - int(fx); - int h = int(int(fy/scale()+fh/scale()+0.5)*scale()) - int(fy); +void Fl_Xlib_Graphics_Driver::rectf_unscaled(int x, int y, int w, int h) { + x += floor(offset_x_); + y += floor(offset_y_); if (!clip_rect(x, y, w, h)) - XFillRectangle(fl_display, fl_window, gc_, x+line_delta_, y+line_delta_, w, h); -} - -void Fl_Xlib_Graphics_Driver::point_unscaled(float fx, float fy) { - int deltaf = scale() >= 2 ? scale()/2 : 0; - int x = fx+offset_x_*scale()-deltaf; - int y = fy+offset_y_*scale()-deltaf; - int width = scale() >= 1 ? scale() : 1; - // *FIXME* This needs X coordinate clipping: - XFillRectangle(fl_display, fl_window, gc_, x+line_delta_, y+line_delta_, width, width); + XFillRectangle(fl_display, fl_window, gc_, x, y, w, h); } -void Fl_Xlib_Graphics_Driver::line_unscaled(float x, float y, float x1, float y1) { - if (x == x1) yxline_unscaled(x, y, y1); - else if (y == y1) xyline_unscaled(x, y, x1); - else draw_clipped_line(x+offset_x_*scale()+line_delta_, y+offset_y_*scale()+line_delta_, x1+offset_x_*scale()+line_delta_, y1+offset_y_*scale()+line_delta_); -} - -void Fl_Xlib_Graphics_Driver::line_unscaled(float x, float y, float x1, float y1, float x2, float y2) { - XPoint p[3]; - p[0].x = x+offset_x_*scale()+line_delta_; p[0].y = y+offset_y_*scale()+line_delta_; - p[1].x = x1+offset_x_*scale()+line_delta_; p[1].y = y1+offset_y_*scale()+line_delta_; - p[2].x = x2+offset_x_*scale()+line_delta_; p[2].y = y2+offset_y_*scale()+line_delta_; - // *FIXME* This needs X coordinate clipping! - XDrawLines(fl_display, fl_window, gc_, p, 3, 0); +void Fl_Xlib_Graphics_Driver::line_unscaled(int x, int y, int x1, int y1) { + draw_clipped_line(x + this->floor(offset_x_) , y + this->floor(offset_y_) , + x1 + this->floor(offset_x_) , y1 + this->floor(offset_y_) ); } -void Fl_Xlib_Graphics_Driver::xyline_unscaled(float x, float y, float x1) { - x+=offset_x_*scale(); y+=offset_y_*scale(); x1 += offset_x_*scale(); - int tw = line_width_ ? line_width_ : 1; // true line width - if (x > x1) { float exch = x; x = x1; x1 = exch; } - int ix = clip_xy(x+line_delta_); if (scale() >= 2) ix -= int(scale()/2); - int iy = clip_xy(y+line_delta_); - // make sure that line output by xyline(a,b,c) extends to pixel just at left of where xyline(c+1,b,d) begins - int ix1 = int(x1/scale()+1.5)*scale()-1; - ix1 += line_delta_; if (scale() >= 4) ix1 -= 1; - draw_clipped_line(ix, iy, ix1, iy); - // make sure no unfilled area lies between xyline(x,y,x1) and xyline(x,y+1,x1) - if (y+line_delta_ + scale() >= iy + tw+1 - 0.001 ) - draw_clipped_line(ix, iy+1, ix1, iy+1); +void Fl_Xlib_Graphics_Driver::xyline_unscaled(int x, int y, int x1) { + if (line_width_ >= 2) x1++; + x += floor(offset_x_) ; + y += floor(offset_y_) ; + x1 += floor(offset_x_) ; + draw_clipped_line(x, y, x1, y); } -void Fl_Xlib_Graphics_Driver::yxline_unscaled(float x, float y, float y1) { - x+=offset_x_*scale(); y+=offset_y_*scale(); y1 += offset_y_*scale(); - int tw = line_width_ ? line_width_ : 1; // true line width - if (y > y1) { float exch = y; y = y1; y1 = exch; } - int ix = clip_xy(x+line_delta_); - int iy = clip_xy(y+line_delta_); if (scale() >= 2) iy -= int(scale()/2); - int iy1 = int(y1/scale()+1.5)*scale()-1; - // make sure that line output by yxline(a,b,c) extends to pixel just above where yxline(a,c+1,d) begins - iy1 += line_delta_; if (scale() >= 4) iy1 -= 1; - draw_clipped_line(ix, iy, ix, iy1); - // make sure no unfilled area lies between yxline(x,y,y1) and yxline(x+1,y,y1) - if (x+line_delta_+scale() >= ix + tw+1 -0.001) - draw_clipped_line(ix+1, iy, ix+1, iy1); +void Fl_Xlib_Graphics_Driver::yxline_unscaled(int x, int y, int y1) { + if (line_width_ >= 2) y1++; + x += floor(offset_x_) ; + y += floor(offset_y_) ; + y1 += floor(offset_y_) ; + draw_clipped_line(x, y, x, y1); } -void Fl_Xlib_Graphics_Driver::loop_unscaled(float x, float y, float x1, float y1, float x2, float y2) { +void Fl_Xlib_Graphics_Driver::loop_unscaled(int x, int y, int x1, int y1, int x2, int y2) { XPoint p[4]; - p[0].x = x +offset_x_*scale()+line_delta_; p[0].y = y +offset_y_*scale()+line_delta_; - p[1].x = x1 +offset_x_*scale()+line_delta_; p[1].y = y1 +offset_y_*scale()+line_delta_; - p[2].x = x2 +offset_x_*scale()+line_delta_; p[2].y = y2 +offset_y_*scale()+line_delta_; - p[3].x = x +offset_x_*scale()+line_delta_; p[3].y = y +offset_y_*scale()+line_delta_; + p[0].x = x + floor(offset_x_) ; p[0].y = y + floor(offset_y_) ; + p[1].x = x1 + floor(offset_x_) ; p[1].y = y1 + floor(offset_y_) ; + p[2].x = x2 + floor(offset_x_) ; p[2].y = y2 + floor(offset_y_) ; + p[3].x = p[0].x; p[3].y = p[0].y; // *FIXME* This needs X coordinate clipping! XDrawLines(fl_display, fl_window, gc_, p, 4, 0); } -void Fl_Xlib_Graphics_Driver::loop_unscaled(float x, float y, float x1, float y1, float x2, float y2, float x3, float y3) { +void Fl_Xlib_Graphics_Driver::loop_unscaled(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) { XPoint p[5]; - p[0].x = x+offset_x_*scale()+line_delta_; p[0].y = y+offset_y_*scale()+line_delta_; - p[1].x = x1 +offset_x_*scale()+line_delta_; p[1].y = y1+offset_y_*scale()+line_delta_; - p[2].x = x2+offset_x_*scale()+line_delta_; p[2].y = y2+offset_y_*scale()+line_delta_; - p[3].x = x3+offset_x_*scale()+line_delta_; p[3].y = y3+offset_y_*scale()+line_delta_; - p[4].x = x+offset_x_*scale()+line_delta_; p[4].y = y+offset_y_*scale()+line_delta_; + p[0].x = x + floor(offset_x_) ; p[0].y = y + floor(offset_y_) ; + p[1].x = x1 + floor(offset_x_) ; p[1].y = y1 + floor(offset_y_) ; + p[2].x = x2 + floor(offset_x_) ; p[2].y = y2 + floor(offset_y_) ; + p[3].x = x3 + floor(offset_x_) ; p[3].y = y3 + floor(offset_y_) ; + p[4].x = p[0].x; p[4].y = p[0].y; // *FIXME* This needs X coordinate clipping! XDrawLines(fl_display, fl_window, gc_, p, 5, 0); } -void Fl_Xlib_Graphics_Driver::polygon_unscaled(float x, float y, float x1, float y1, float x2, float y2) { +void Fl_Xlib_Graphics_Driver::polygon_unscaled(int x, int y, int x1, int y1, int x2, int y2) { XPoint p[4]; - p[0].x = x+offset_x_*scale()+line_delta_; p[0].y = y+offset_y_*scale()+line_delta_; - p[1].x = x1+offset_x_*scale()+line_delta_; p[1].y = y1+offset_y_*scale()+line_delta_; - p[2].x = x2+offset_x_*scale()+line_delta_; p[2].y = y2+offset_y_*scale()+line_delta_; - p[3].x = x+offset_x_*scale()+line_delta_; p[3].y = y+offset_y_*scale()+line_delta_; + p[0].x = x + floor(offset_x_) ; p[0].y = y + floor(offset_y_) ; + p[1].x = x1 + floor(offset_x_) ; p[1].y = y1 + floor(offset_y_) ; + p[2].x = x2 + floor(offset_x_) ; p[2].y = y2 + floor(offset_y_) ; + p[3].x = p[0].x; p[3].y = p[0].y; // *FIXME* This needs X coordinate clipping! XFillPolygon(fl_display, fl_window, gc_, p, 3, Convex, 0); XDrawLines(fl_display, fl_window, gc_, p, 4, 0); } -void Fl_Xlib_Graphics_Driver::polygon_unscaled(float x, float y, float x1, float y1, float x2, float y2, float x3, float y3) { +void Fl_Xlib_Graphics_Driver::polygon_unscaled(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) { XPoint p[5]; - p[0].x = x+offset_x_*scale()+line_delta_; p[0].y = y+offset_y_*scale()+line_delta_; - p[1].x = x1+offset_x_*scale()+line_delta_; p[1].y = y1+offset_y_*scale()+line_delta_; - p[2].x = x2+offset_x_*scale()+line_delta_; p[2].y = y2+offset_y_*scale()+line_delta_; - p[3].x = x3+offset_x_*scale()+line_delta_; p[3].y = y3+offset_y_*scale()+line_delta_; - p[4].x = x+offset_x_*scale()+line_delta_; p[4].y = y+offset_y_*scale()+line_delta_; + p[0].x = x + floor(offset_x_) ; p[0].y = y + floor(offset_y_) ; + p[1].x = x1 + floor(offset_x_) ; p[1].y = y1 + floor(offset_y_) ; + p[2].x = x2 + floor(offset_x_) ; p[2].y = y2 + floor(offset_y_) ; + p[3].x = x3 + floor(offset_x_) ; p[3].y = y3 + floor(offset_y_) ; + p[4].x = p[0].x; p[4].y = p[0].y; // *FIXME* This needs X coordinate clipping! XFillPolygon(fl_display, fl_window, gc_, p, 4, Convex, 0); XDrawLines(fl_display, fl_window, gc_, p, 5, 0); |
