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 | |
| 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')
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H | 31 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx | 27 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver_arci.cxx | 19 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx | 20 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx | 23 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver_line_style.cxx | 18 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver_rect.cxx | 141 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver_vertex.cxx | 4 |
8 files changed, 124 insertions, 159 deletions
diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H index b59365795..7ee34a9b5 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H @@ -57,7 +57,6 @@ private: unsigned depth_; // depth of translation stack int stack_x_[FL_XLIB_GRAPHICS_TRANSLATION_STACK_SIZE]; // translation stack allowing cumulative translations int stack_y_[FL_XLIB_GRAPHICS_TRANSLATION_STACK_SIZE]; - int line_delta_; virtual void set_current_(); int clip_max_; // +/- x/y coordinate limit (16-bit coordinate space) virtual void draw_fixed(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy); @@ -139,18 +138,17 @@ public: protected: virtual void transformed_vertex0(float x, float y); void fixloop(); - // --- implementation is in src/fl_rect.cxx which includes src/cfg_gfx/xlib_rect.cxx - virtual void point_unscaled(float x, float y); - virtual void rect_unscaled(float x, float y, float w, float h); - virtual void rectf_unscaled(float x, float y, float w, float h); - virtual void line_unscaled(float x, float y, float x1, float y1); - virtual void line_unscaled(float x, float y, float x1, float y1, float x2, float y2); - virtual void xyline_unscaled(float x, float y, float x1); - virtual void yxline_unscaled(float x, float y, float y1); - virtual void loop_unscaled(float x0, float y0, float x1, float y1, float x2, float y2); - virtual void loop_unscaled(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3); - 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); + virtual void focus_rect(int x, int y, int w, int h); + virtual void rectf_unscaled(int x, int y, int w, int h); + virtual void line_unscaled(int x, int y, int x1, int y1); + virtual void xyline_unscaled(int x, int y, int x1); + virtual void *change_pen_width(int lwidth); + virtual void reset_pen_width(void *data); + virtual void yxline_unscaled(int x, int y, int y1); + virtual void loop_unscaled(int x0, int y0, int x1, int y1, int x2, int y2); + virtual void loop_unscaled(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3); + virtual void polygon_unscaled(int x0, int y0, int x1, int y1, int x2, int y2); + virtual void polygon_unscaled(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3); // Scaling and clipping stuff for internal usage. // Currently specific to Fl_Xlib_Graphics_Driver (16-bit coordinate clipping) @@ -194,10 +192,9 @@ protected: void end_complex_polygon(); void gap(); virtual void ellipse_unscaled(double xt, double yt, double rx, double ry); - // --- implementation is in src/fl_arci.cxx which includes src/cfg_gfx/xxx_arci.cxx - virtual void arc_unscaled(float x, float y, float w, float h, double a1, double a2); - virtual void pie_unscaled(float x, float y, float w, float h, double a1, double a2); - virtual void line_style_unscaled(int style, float width, char* dashes); + virtual void arc_unscaled(int x, int y, int w, int h, double a1, double a2); + virtual void pie_unscaled(int x, int y, int w, int h, double a1, double a2); + virtual void line_style_unscaled(int style, int width, char* dashes); void color(Fl_Color c); void set_color(Fl_Color i, unsigned int c); void free_color(Fl_Color i, int overlay); diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx index 3bb14e93c..6401efa97 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx @@ -50,7 +50,6 @@ GC fl_gc = 0; Fl_Xlib_Graphics_Driver::Fl_Xlib_Graphics_Driver(void) { mask_bitmap_ = NULL; p = NULL; - line_delta_ = 0; #if USE_PANGO Fl_Graphics_Driver::font(0, 0); #endif @@ -76,17 +75,6 @@ void Fl_Xlib_Graphics_Driver::scale(float f) { Fl_Graphics_Driver::scale(f); //fprintf(stderr, "scale=%.2f\n", scale_); line_style(FL_SOLID); // scale also default line width - /* Scaling >= 2 transforms 1-pixel wide lines into wider lines. - X11 draws 2-pixel wide lines so that half of the line width is above or at left - of a 1-pixel wide line that would be drawn with the same coordinates. - Thus, if the line starts at coordinates (0,0) half of the line width is invisible. - Similarly, if the line ends at w()-1 the last pixel of the window is not drawn. - What is wanted when scale_ == 2 is a visible 2-pixel wide line in the first case, - and a line at the window's edge in the 2nd case. - Setting line_delta_ to 1 and offsetting all line, rectangle, text and clip - coordinates by line_delta_ achieves what is wanted until scale_ <= 3.5. - */ - line_delta_ = (scale() > 1.9/*1.75*/ ? 1 : 0); } #endif } @@ -109,8 +97,8 @@ void Fl_Xlib_Graphics_Driver::transformed_vertex0(float fx, float fy) { p_size = p ? 2*p_size : 16; p = (XPOINT*)realloc((void*)p, p_size*sizeof(*p)); } - p[n].x = x + line_delta_; - p[n].y = y + line_delta_; + p[n].x = x ; + p[n].y = y ; n++; } } @@ -242,15 +230,12 @@ void Fl_Xlib_Graphics_Driver::font_name(int num, const char *name) { Region Fl_Xlib_Graphics_Driver::scale_clip(float f) { Region r = rstack[rstackptr]; if (r == 0 || (f == 1 && offset_x_ == 0 && offset_y_ == 0) ) return 0; - int deltaf = f/2; Region r2 = XCreateRegion(); for (int i = 0; i < r->numRects; i++) { - int x = (r->rects[i].x1 + offset_x_)*f; - int y = (r->rects[i].y1 + offset_y_)*f; - int w = int((r->rects[i].x2 + offset_x_) * f) - x; - int h = int((r->rects[i].y2 + offset_y_) * f) - y; - x += line_delta_ - deltaf; - y += line_delta_ - deltaf; + int x = floor(r->rects[i].x1 + offset_x_, f); + int y = floor(r->rects[i].y1 + offset_y_, f); + int w = floor((r->rects[i].x2 + offset_x_) , f) - x; + int h = floor((r->rects[i].y2 + offset_y_) , f) - y; Region R = XRectangleRegion(x, y, w, h); XUnionRegion(R, r2, r2); ::XDestroyRegion(R); diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_arci.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_arci.cxx index 381ac0d97..4897cf723 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_arci.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_arci.cxx @@ -24,15 +24,18 @@ \brief Utility functions for drawing circles using integers */ -void Fl_Xlib_Graphics_Driver::arc_unscaled(float x,float y,float w,float h,double a1,double a2) { +void Fl_Xlib_Graphics_Driver::arc_unscaled(int x, int y, int w, int h, double a1, double a2) { if (w <= 0 || h <= 0) return; - XDrawArc(fl_display, fl_window, gc_, int(x+offset_x_*scale()), int(y+offset_y_*scale()), int(w-1), int(h-1), int(a1*64),int((a2-a1)*64)); + x += floor(offset_x_); + y += floor(offset_y_); + XDrawArc(fl_display, fl_window, gc_, x, y, w, h, int(a1*64),int((a2-a1)*64)); } -void Fl_Xlib_Graphics_Driver::pie_unscaled(float x,float y,float w,float h,double a1,double a2) { - if (w <= 0 || h <= 0) return; - x += offset_x_*scale(); - y += offset_y_*scale(); - XDrawArc(fl_display, fl_window, gc_, x,y,w-1,h-1, int(a1*64),int((a2-a1)*64)); - XFillArc(fl_display, fl_window, gc_, x,y,w-1,h-1, int(a1*64),int((a2-a1)*64)); +void Fl_Xlib_Graphics_Driver::pie_unscaled(int x, int y, int w, int h, double a1,double a2) { + if (w <= 2 || h <= 2) return; + x += floor(offset_x_); + y += floor(offset_y_); + int extra = scale() >= 3 ? 1 : 0; + XDrawArc(fl_display, fl_window, gc_, x+1+extra, y+1+extra, w-2-2*extra, h-2-2*extra, int(a1*64), int((a2-a1)*64)); + XFillArc(fl_display, fl_window, gc_, x+1, y+1, w-2, h-2, int(a1*64), int((a2-a1)*64)); } diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx index 2f38a8275..a8039df46 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx @@ -779,8 +779,8 @@ void Fl_Xlib_Graphics_Driver::text_extents_unscaled(const char *c, int n, int &d w = gi.width; h = gi.height; - dx = -gi.x + line_delta_; - dy = -gi.y + line_delta_; + dx = -gi.x ; + dy = -gi.y ; correct_extents(scale(), dx, dy, w, h); } @@ -788,10 +788,10 @@ void Fl_Xlib_Graphics_Driver::draw_unscaled(const char *str, int n, int x, int y // transform coordinates and clip if outside 16-bit space (STR 2798) - int x1 = x + offset_x_ * scale() + line_delta_; + int x1 = x + floor(offset_x_) ; if (x1 < clip_min() || x1 > clip_max()) return; - int y1 = y + offset_y_ * scale() + line_delta_; + int y1 = y + floor(offset_y_) ; if (y1 < clip_min() || y1 > clip_max()) return; #if USE_OVERLAY @@ -870,7 +870,7 @@ void Fl_Xlib_Graphics_Driver::drawUCS4(const void *str, int n, int x, int y) { color.color.blue = ((int)b)*0x101; color.color.alpha = 0xffff; - XftDrawString32(draw_, &color, ((Fl_Xlib_Font_Descriptor*)font_descriptor())->font, x+offset_x_*scale()+line_delta_, y+offset_y_*scale()+line_delta_, (FcChar32 *)str, n); + XftDrawString32(draw_, &color, ((Fl_Xlib_Font_Descriptor*)font_descriptor())->font, x+floor(offset_x_), y+floor(offset_y_), (FcChar32 *)str, n); } @@ -1256,12 +1256,12 @@ void Fl_Xlib_Graphics_Driver::font_unscaled(Fl_Font fnum, Fl_Fontsize size) { } void Fl_Xlib_Graphics_Driver::draw_unscaled(const char *str, int n, int x, int y) { - do_draw(0, str, n, x+offset_x_*scale(), y+offset_y_*scale()); + do_draw(0, str, n, x + floor(offset_x_), y + floor(offset_y_)); } void Fl_Xlib_Graphics_Driver::draw_unscaled(int angle, const char *str, int n, int x, int y) { PangoMatrix mat = PANGO_MATRIX_INIT; // 1.6 - pango_matrix_translate(&mat, x+offset_x_*scale(), y+offset_y_*scale()); // 1.6 + pango_matrix_translate(&mat, x + floor(offset_x_), y + floor(offset_y_)); // 1.6 double l = width_unscaled(str, n); pango_matrix_rotate(&mat, angle); // 1.6 pango_context_set_matrix(pctxt_, &mat); // 1.6 @@ -1275,7 +1275,7 @@ void Fl_Xlib_Graphics_Driver::draw_unscaled(int angle, const char *str, int n, i } void Fl_Xlib_Graphics_Driver::rtl_draw_unscaled(const char* str, int n, int x, int y) { - do_draw(1, str, n, x+offset_x_*scale(), y+offset_y_*scale()); + do_draw(1, str, n, x+floor(offset_x_), y+floor(offset_y_)); } /* Compute dx, dy, w, h so that fl_rect(x+dx, y+dy, w, h) is the bounding box @@ -1343,8 +1343,8 @@ void Fl_Xlib_Graphics_Driver::do_draw(int from_right, const char *str, int n, in if (from_right) { x -= w; } - pango_xft_render_layout(draw_, &color, playout_, (x + line_delta_)*PANGO_SCALE, - (y - y_correction + line_delta_ - lheight + desc)*PANGO_SCALE ); // 1.8 + pango_xft_render_layout(draw_, &color, playout_, x * PANGO_SCALE, + (y - y_correction - lheight + desc) * PANGO_SCALE ); // 1.8 } double Fl_Xlib_Graphics_Driver::width_unscaled(const char* str, int n) { diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx index 9361e5d4a..9b2fc6970 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx @@ -580,7 +580,7 @@ void Fl_Xlib_Graphics_Driver::draw_image_unscaled(const uchar* buf, int x, int y if (alpha) d ^= FL_IMAGE_WITH_ALPHA; const int mono = (d>-3 && d<3); - innards(buf,x+offset_x_*scale(),y+offset_y_*scale(),w,h,d,l,mono,0,0,alpha,gc_); + innards(buf,x+floor(offset_x_),y+floor(offset_y_),w,h,d,l,mono,0,0,alpha,gc_); } void Fl_Xlib_Graphics_Driver::draw_image_unscaled(Fl_Draw_Image_Cb cb, void* data, @@ -590,16 +590,16 @@ void Fl_Xlib_Graphics_Driver::draw_image_unscaled(Fl_Draw_Image_Cb cb, void* dat if (alpha) d ^= FL_IMAGE_WITH_ALPHA; const int mono = (d>-3 && d<3); - innards(0,x+offset_x_*scale(),y+offset_y_*scale(),w,h,d,0,mono,cb,data,alpha,gc_); + innards(0,x+floor(offset_x_),y+floor(offset_y_),w,h,d,0,mono,cb,data,alpha,gc_); } void Fl_Xlib_Graphics_Driver::draw_image_mono_unscaled(const uchar* buf, int x, int y, int w, int h, int d, int l){ - innards(buf,x+offset_x_*scale(),y+offset_y_*scale(),w,h,d,l,1,0,0,0,gc_); + innards(buf,x+floor(offset_x_),y+floor(offset_y_),w,h,d,l,1,0,0,0,gc_); } void Fl_Xlib_Graphics_Driver::draw_image_mono_unscaled(Fl_Draw_Image_Cb cb, void* data, int x, int y, int w, int h,int d) { - innards(0,x+offset_x_*scale(),y+offset_y_*scale(),w,h,d,0,1,cb,data,0,gc_); + innards(0,x+floor(offset_x_),y+floor(offset_y_),w,h,d,0,1,cb,data,0,gc_); } void fl_rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b) { @@ -623,8 +623,8 @@ void Fl_Xlib_Graphics_Driver::delete_bitmask(Fl_Bitmask bm) { } void Fl_Xlib_Graphics_Driver::draw_fixed(Fl_Bitmap *bm, int X, int Y, int W, int H, int cx, int cy) { - X = (X+offset_x_)*scale(); - Y = (Y+offset_y_)*scale(); + X = floor(X)+floor(offset_x_); + Y = floor(Y)+floor(offset_y_); cache_size(bm, W, H); cx *= scale(); cy *= scale(); XSetStipple(fl_display, gc_, *Fl_Graphics_Driver::id(bm)); @@ -737,8 +737,8 @@ void Fl_Xlib_Graphics_Driver::cache(Fl_RGB_Image *img) { void Fl_Xlib_Graphics_Driver::draw_fixed(Fl_RGB_Image *img, int X, int Y, int W, int H, int cx, int cy) { - X = (X+offset_x_)*scale(); - Y = (Y+offset_y_)*scale(); + X = floor(X)+floor(offset_x_); + Y = floor(Y)+floor(offset_y_); cache_size(img, W, H); cx *= scale(); cy *= scale(); if (img->d() == 1 || img->d() == 3) { @@ -783,7 +783,8 @@ void Fl_Xlib_Graphics_Driver::draw_rgb(Fl_RGB_Image *rgb, int XP, int YP, int WP } scale_and_render_pixmap( *Fl_Graphics_Driver::id(rgb), rgb->d(), rgb->data_w() / double(Wfull), rgb->data_h() / double(Hfull), - (XP-cx + offset_x_)*scale()-offset, (YP-cy + offset_y_)*scale()-offset, Wfull, Hfull); + floor(XP-cx) + floor(offset_x_) - offset, floor(YP-cy) + floor(offset_y_) - offset, + Wfull, Hfull); pop_clip(); } @@ -851,8 +852,8 @@ void Fl_Xlib_Graphics_Driver::cache(Fl_Bitmap *bm) { } void Fl_Xlib_Graphics_Driver::draw_fixed(Fl_Pixmap *pxm, int X, int Y, int W, int H, int cx, int cy) { - X = (X+offset_x_)*scale(); - Y = (Y+offset_y_)*scale(); + X = floor(X)+floor(offset_x_); + Y = floor(Y)+floor(offset_y_); cache_size(pxm, W, H); cx *= scale(); cy *= scale(); Fl_Region r2 = scale_clip(scale()); diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_line_style.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_line_style.cxx index 606b82920..1aaeceea1 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_line_style.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_line_style.cxx @@ -26,7 +26,7 @@ #include "Fl_Xlib_Graphics_Driver.H" -void Fl_Xlib_Graphics_Driver::line_style_unscaled(int style, float width, char* dashes) { +void Fl_Xlib_Graphics_Driver::line_style_unscaled(int style, int width, char* dashes) { int ndashes = dashes ? strlen(dashes) : 0; // emulate the Windows dash patterns on X @@ -61,3 +61,19 @@ if (*dashes == 0) ndashes = 0;//against error with very small scaling Cap[(style>>8)&3], Join[(style>>12)&3]); if (ndashes) XSetDashes(fl_display, gc_, 0, dashes, ndashes); } + +void *Fl_Xlib_Graphics_Driver::change_pen_width(int lwidth) { + XGCValues *gc_values = (XGCValues*)malloc(sizeof(XGCValues)); + gc_values->line_width = lwidth; + XChangeGC(fl_display, gc_, GCLineWidth, gc_values); + gc_values->line_width = line_width_; + line_width_ = lwidth; + return gc_values; +} + +void Fl_Xlib_Graphics_Driver::reset_pen_width(void *data) { + XGCValues *gc_values = (XGCValues*)data; + line_width_ = gc_values->line_width; + XChangeGC(fl_display, gc_, GCLineWidth, gc_values); + delete gc_values; +} 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); diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_vertex.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_vertex.cxx index 2f1608d13..59b3e58eb 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_vertex.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_vertex.cxx @@ -43,7 +43,7 @@ void Fl_Xlib_Graphics_Driver::end_line() { void Fl_Xlib_Graphics_Driver::end_loop() { fixloop(); if (n>2) { - transformed_vertex0(p[0].x - line_delta_, p[0].y - line_delta_); + transformed_vertex0(p[0].x , p[0].y ); } end_line(); } @@ -60,7 +60,7 @@ void Fl_Xlib_Graphics_Driver::end_polygon() { void Fl_Xlib_Graphics_Driver::gap() { while (n>gap_+2 && p[n-1].x == p[gap_].x && p[n-1].y == p[gap_].y) n--; if (n > gap_+2) { - transformed_vertex0(p[gap_].x - line_delta_, p[gap_].y - line_delta_); + transformed_vertex0(p[gap_].x, p[gap_].y); gap_ = n; } else { n = gap_; |
