diff options
Diffstat (limited to 'src/drivers/Xlib')
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx | 8 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H | 105 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx | 51 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver_arci.cxx | 12 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx | 25 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx | 155 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx | 117 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver_line_style.cxx | 11 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver_rect.cxx | 189 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver_vertex.cxx | 23 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx | 14 |
11 files changed, 430 insertions, 280 deletions
diff --git a/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx b/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx index 138564600..b96a4f410 100644 --- a/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx @@ -51,6 +51,8 @@ Fl_Copy_Surface_Driver *Fl_Copy_Surface_Driver::newCopySurfaceDriver(int w, int Fl_Xlib_Copy_Surface_Driver::Fl_Xlib_Copy_Surface_Driver(int w, int h) : Fl_Copy_Surface_Driver(w, h) { driver(new Fl_Xlib_Graphics_Driver()); + float s = Fl_Graphics_Driver::default_driver().scale(); + ((Fl_Xlib_Graphics_Driver*)driver())->scale(s); oldwindow = fl_window; xid = fl_create_offscreen(w,h); driver()->push_no_clip(); @@ -65,10 +67,10 @@ Fl_Xlib_Copy_Surface_Driver::~Fl_Xlib_Copy_Surface_Driver() { driver()->pop_clip(); bool need_push = (Fl_Surface_Device::surface() != this); if (need_push) Fl_Surface_Device::push_current(this); - unsigned char *data = fl_read_image(NULL,0,0,width,height,0); + Fl_RGB_Image *rgb = Fl::screen_driver()->read_win_rectangle(NULL, 0, 0, width, height, 0); if (need_push) Fl_Surface_Device::pop_current(); - Fl_X11_Screen_Driver::copy_image(data, width, height, 1); - delete[] data; + Fl_X11_Screen_Driver::copy_image(rgb->array, rgb->w(), rgb->h(), 1); + delete rgb; fl_delete_offscreen(xid); delete driver(); } diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H index e71eab3cf..d1f6f3fc9 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H @@ -43,7 +43,7 @@ struct _XRegion { #endif // HAVE_X11_XREGION_H #if USE_PANGO -#include <pango/pangoxft.h> +#include <pango/pango.h> #endif @@ -52,11 +52,27 @@ struct _XRegion { * This class is implemented only on the Xlib platform. */ -class FL_EXPORT Fl_Xlib_Graphics_Driver : public Fl_Graphics_Driver { +class FL_EXPORT Fl_Xlib_Graphics_Driver : public Fl_Scalable_Graphics_Driver { private: int offset_x_, offset_y_; // translation between user and graphical coordinates: graphical = user + offset unsigned depth_; // depth of translation stack int stack_x_[20], stack_y_[20]; // translation stack allowing cumulative translations + int line_delta_; +protected: + virtual void draw_unscaled(Fl_Pixmap *pxm, float s, int XP, int YP, int WP, int HP, int cx, int cy); + virtual void draw_unscaled(Fl_Bitmap *pxm, float s, int XP, int YP, int WP, int HP, int cx, int cy); + virtual void draw_unscaled(Fl_RGB_Image *img, float s, int XP, int YP, int WP, int HP, int cx, int cy); + virtual void draw_image_unscaled(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0); + virtual void draw_image_unscaled(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3); + virtual void draw_image_mono_unscaled(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0); + virtual void draw_image_mono_unscaled(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1); +#if HAVE_XRENDER + virtual int draw_scaled(Fl_Image *img, int XP, int YP, int WP, int HP); + int scale_and_render_pixmap(Fl_Offscreen pixmap, int depth, double scale_x, double scale_y, int srcx, int srcy, int XP, int YP, int WP, int HP); +#endif + virtual int height_unscaled(); + virtual int descent_unscaled(); + virtual Region scale_clip(float f); #if USE_XFT void drawUCS4(const void *str, int n, int x, int y); #endif @@ -65,16 +81,11 @@ private: static PangoContext *pctxt_; static PangoFontMap *pfmap_; static PangoLayout *playout_; -protected: PangoFontDescription *pfd_; void do_draw(int from_right, const char *str, int n, int x, int y); static PangoContext *context(); static void init_built_in_fonts(); #endif -#if HAVE_XRENDER - int scale_and_render_pixmap(Fl_Offscreen pixmap, int depth, double scale_x, double scale_y, int srcx, int srcy, int XP, int YP, int WP, int HP); -#endif -protected: static GC gc_; uchar **mask_bitmap_; uchar **mask_bitmap() {return mask_bitmap_;} @@ -93,6 +104,7 @@ public: virtual ~Fl_Xlib_Graphics_Driver(); void translate_all(int dx, int dy); void untranslate_all(); + virtual void scale(float f); virtual int has_feature(driver_feature mask) { return mask & NATIVE; } virtual void *gc() { return gc_; } virtual void gc(void *value); @@ -104,51 +116,43 @@ public: // --- bitmap stuff Fl_Bitmask create_bitmask(int w, int h, const uchar *array); void delete_bitmask(Fl_Bitmask bm); - void draw(const char* str, int n, int x, int y); - void draw(int angle, const char *str, int n, int x, int y); - void rtl_draw(const char* str, int n, int x, int y); - void font(Fl_Font face, Fl_Fontsize size); - void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy); - void draw(Fl_Bitmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy); - void draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy); - void draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0); - void draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3); - void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0); - void draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1); -#if HAVE_XRENDER - int draw_scaled(Fl_Image *img, int XP, int YP, int WP, int HP); -#endif + virtual void draw_unscaled(const char* str, int n, int x, int y); + virtual void draw_unscaled(int angle, const char *str, int n, int x, int y); + virtual void rtl_draw_unscaled(const char* str, int n, int x, int y); + virtual void font_unscaled(Fl_Font face, Fl_Fontsize size); fl_uintptr_t cache(Fl_Pixmap *img, int w, int h, const char *const*array); fl_uintptr_t cache(Fl_Bitmap *img, int w, int h, const uchar *array); void uncache(Fl_RGB_Image *img, fl_uintptr_t &id_, fl_uintptr_t &mask_); - double width(const char *str, int n); - double width(unsigned int c); - void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h); - int height(); - int descent(); - void copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy); + virtual double width_unscaled(const char *str, int n); + virtual double width_unscaled(unsigned int c); + virtual void text_extents_unscaled(const char*, int n, int& dx, int& dy, int& w, int& h); + virtual Fl_Fontsize size_unscaled(); + virtual void copy_offscreen_unscaled(float x, float y, float w, float h, Fl_Offscreen pixmap, float srcx, float srcy); +#if ! defined(FL_DOXYGEN) + void copy_offscreen_with_alpha(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy); +#endif void add_rectangle_to_region(Fl_Region r, int x, int y, int w, int h); Fl_Region XRectangleRegion(int x, int y, int w, int h); void XDestroyRegion(Fl_Region r); protected: - virtual void transformed_vertex0(short x, short y); + 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 - void point(int x, int y); - void rect(int x, int y, int w, int h); - void rectf(int x, int y, int w, int h); - void line(int x, int y, int x1, int y1); - void line(int x, int y, int x1, int y1, int x2, int y2); - void xyline(int x, int y, int x1); - void xyline(int x, int y, int x1, int y2); - void xyline(int x, int y, int x1, int y2, int x3); - void yxline(int x, int y, int y1); - void yxline(int x, int y, int y1, int x2); - void yxline(int x, int y, int y1, int x2, int y3); - void loop(int x0, int y0, int x1, int y1, int x2, int y2); - void loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3); - void polygon(int x0, int y0, int x1, int y1, int x2, int y2); - void polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3); + 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 xyline_unscaled(float x, float y, float x1, float y2); + virtual void xyline_unscaled(float x, float y, float x1, float y2, float x3); + virtual void yxline_unscaled(float x, float y, float y1); + virtual void yxline_unscaled(float x, float y, float y1, float x2); + virtual void yxline_unscaled(float x, float y, float y1, float x2, float y3); + 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); // --- clipping void push_clip(int x, int y, int w, int h); int clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H); @@ -156,25 +160,18 @@ protected: void push_no_clip(); void pop_clip(); void restore_clip(); - // --- implementation is in src/fl_vertex.cxx which includes src/cfg_gfx/xxx_rect.cxx void begin_complex_polygon(); - void transformed_vertex(double xf, double yf); - void vertex(double x, double y); void end_points(); void end_line(); void end_loop(); void end_polygon(); void end_complex_polygon(); void gap(); - void circle(double x, double y, double r); - // --- implementation is in src/fl_arc.cxx which includes src/cfg_gfx/xxx_arc.cxx if needed - // using void Fl_Graphics_Driver::arc(double x, double y, double r, double start, double end); + 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 - void arc(int x, int y, int w, int h, double a1, double a2); - void pie(int x, int y, int w, int h, double a1, double a2); - // --- implementation is in src/fl_line_style.cxx which includes src/cfg_gfx/xxx_line_style.cxx - void line_style(int style, int width=0, char* dashes=0); - // --- implementation is in src/fl_color.cxx which includes src/cfg_gfx/xxx_color.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); 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 6d6cff681..741ceb89a 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx @@ -3,7 +3,7 @@ // // Rectangle drawing routines for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2016 by Bill Spitzak and others. +// Copyright 1998-2017 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -57,6 +57,7 @@ Fl_Xlib_Graphics_Driver::Fl_Xlib_Graphics_Driver(void) { p_size = 0; p = NULL; line_width_ = 0; + line_delta_ = 0; #if USE_PANGO pfd_ = pango_font_description_new(); Fl_Graphics_Driver::font(0, 0); @@ -78,8 +79,30 @@ void Fl_Xlib_Graphics_Driver::gc(void *value) { fl_gc = gc_; } -void Fl_Xlib_Graphics_Driver::copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy) { - XCopyArea(fl_display, pixmap, fl_window, gc_, srcx, srcy, w, h, x+offset_x_, y+offset_y_); +void Fl_Xlib_Graphics_Driver::scale(float f) { +#if USE_XFT + if (f != scale_) { + size_ = 0; + 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.75 ? 1 : 0); + } +#endif +} + +void Fl_Xlib_Graphics_Driver::copy_offscreen_unscaled(float x, float y, float w, float h, Fl_Offscreen pixmap, float srcx, float srcy) { + XCopyArea(fl_display, pixmap, fl_window, gc_, srcx, srcy, w, h, x+offset_x_*scale_, y+offset_y_*scale_); } void Fl_Xlib_Graphics_Driver::add_rectangle_to_region(Fl_Region r, int X, int Y, int W, int H) { @@ -88,7 +111,8 @@ void Fl_Xlib_Graphics_Driver::add_rectangle_to_region(Fl_Region r, int X, int Y, XUnionRectWithRegion(&R, r, r); } -void Fl_Xlib_Graphics_Driver::transformed_vertex0(short x, short y) { +void Fl_Xlib_Graphics_Driver::transformed_vertex0(float fx, float fy) { + short x = short(fx), y = short(fy); if (!n || x != p[n-1].x || y != p[n-1].y) { if (n >= p_size) { p_size = p ? 2*p_size : 16; @@ -205,6 +229,25 @@ void Fl_Xlib_Graphics_Driver::font_name(int num, const char *name) { s->first = 0; } + +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; + float delta = (f >= 2 ? f/3 : 0); + Region r2 = XCreateRegion(); + XRectangle R; + for (int i = 0; i < r->numRects; i++) { + R.x = short((r->rects[i].x1 + offset_x_)*f-delta + line_delta_); + R.y = short((r->rects[i].y1 + offset_y_)*f-delta + line_delta_); + R.width = short(r->rects[i].x2*f) - short(r->rects[i].x1*f); + R.height = short(r->rects[i].y2*f) - short(r->rects[i].y1*f); + XUnionRectWithRegion(&R, r2, r2); + } + rstack[rstackptr] = r2; + return r; +} + + void Fl_Xlib_Graphics_Driver::translate_all(int dx, int dy) { // reversibly adds dx,dy to the offset between user and graphical coordinates stack_x_[depth_] = offset_x_; stack_y_[depth_] = offset_y_; diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_arci.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_arci.cxx index b1a8cd10d..cd0b7915f 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_arci.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_arci.cxx @@ -3,7 +3,7 @@ // // Arc (integer) drawing functions for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2016 by Bill Spitzak and others. +// Copyright 1998-2017 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -26,15 +26,15 @@ \brief Utility functions for drawing circles using integers */ -void Fl_Xlib_Graphics_Driver::arc(int x,int y,int w,int h,double a1,double a2) { +void Fl_Xlib_Graphics_Driver::arc_unscaled(float x,float y,float w,float h,double a1,double a2) { if (w <= 0 || h <= 0) return; - XDrawArc(fl_display, fl_window, gc_, x+offset_x_,y+offset_y_,w-1,h-1, int(a1*64),int((a2-a1)*64)); + 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)); } -void Fl_Xlib_Graphics_Driver::pie(int x,int y,int w,int h,double a1,double a2) { +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_; - y += offset_y_; + 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)); } diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx index a1da5a585..5123f6e02 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx @@ -3,7 +3,7 @@ // // X11 font utilities for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2016 by Bill Spitzak and others. +// Copyright 1998-2017 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -596,7 +596,7 @@ XFontStruct* Fl_XFont_On_Demand::value() { return ptr; } -void Fl_Xlib_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) { +void Fl_Xlib_Graphics_Driver::font_unscaled(Fl_Font fnum, Fl_Fontsize size) { if (fnum==-1) { Fl_Graphics_Driver::font(0, 0); return; @@ -611,27 +611,32 @@ void Fl_Xlib_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) { } } -int Fl_Xlib_Graphics_Driver::height() { +int Fl_Xlib_Graphics_Driver::height_unscaled() { if (font_descriptor()) return font_descriptor()->font->ascent + font_descriptor()->font->descent; else return -1; } -int Fl_Xlib_Graphics_Driver::descent() { +int Fl_Xlib_Graphics_Driver::descent_unscaled() { if (font_descriptor()) return font_descriptor()->font->descent; else return -1; } -double Fl_Xlib_Graphics_Driver::width(const char* c, int n) { +Fl_Fontsize Fl_Xlib_Graphics_Driver::size_unscaled() { + if (font_descriptor()) return size_; + return -1; +} + +double Fl_Xlib_Graphics_Driver::width_unscaled(const char* c, int n) { if (font_descriptor()) return (double) XUtf8TextWidth(font_descriptor()->font, c, n); else return -1; } -double Fl_Xlib_Graphics_Driver::width(unsigned int c) { +double Fl_Xlib_Graphics_Driver::width_unscaled(unsigned int c) { if (font_descriptor()) return (double) XUtf8UcsWidth(font_descriptor()->font, c); else return -1; } -void Fl_Xlib_Graphics_Driver::text_extents(const char *c, int n, int &dx, int &dy, int &W, int &H) { +void Fl_Xlib_Graphics_Driver::text_extents_unscaled(const char *c, int n, int &dx, int &dy, int &W, int &H) { if (font_gc != gc_) { if (!font_descriptor()) font(FL_HELVETICA, FL_NORMAL_SIZE); font_gc = gc_; @@ -649,7 +654,7 @@ void Fl_Xlib_Graphics_Driver::text_extents(const char *c, int n, int &dx, int &d // dy = fl_descent() - H; } -void Fl_Xlib_Graphics_Driver::draw(const char* c, int n, int x, int y) { +void Fl_Xlib_Graphics_Driver::draw_unscaled(const char* c, int n, int x, int y) { if (font_gc != gc_) { if (!font_descriptor()) this->font(FL_HELVETICA, FL_NORMAL_SIZE); font_gc = gc_; @@ -658,7 +663,7 @@ void Fl_Xlib_Graphics_Driver::draw(const char* c, int n, int x, int y) { if (gc_) XUtf8DrawString(fl_display, fl_window, font_descriptor()->font, gc_, x+offset_x_, y+offset_y_, c, n); } -void Fl_Xlib_Graphics_Driver::draw(int angle, const char *str, int n, int x, int y) { +void Fl_Xlib_Graphics_Driver::draw_unscaled(int angle, const char *str, int n, int x, int y) { static char warning = 0; // issue warning only once if (!warning && angle != 0) { warning = 1; @@ -669,7 +674,7 @@ void Fl_Xlib_Graphics_Driver::draw(int angle, const char *str, int n, int x, int this->draw(str, n, (int)x, (int)y); } -void Fl_Xlib_Graphics_Driver::rtl_draw(const char* c, int n, int x, int y) { +void Fl_Xlib_Graphics_Driver::rtl_draw_unscaled(const char* c, int n, int x, int y) { if (font_gc != gc_) { if (!font_descriptor()) this->font(FL_HELVETICA, FL_NORMAL_SIZE); font_gc = gc_; 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 48771d0a2..a2c655455 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx @@ -3,7 +3,7 @@ // // More font utilities for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2016 by Bill Spitzak and others. +// Copyright 1998-2017 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -125,6 +125,30 @@ static Fl_Fontdesc built_in_table[] = { Fl_Fontdesc* fl_fonts = built_in_table; +Fl_Fontsize Fl_Xlib_Graphics_Driver::size_unscaled() { + return (Fl_Fontsize)(size_); +} + +static void correct_extents (float scale_, int &dx, int &dy, int &w, int &h) { + if (int(scale_) == scale_) { // correct for extents non divisible by integral scale_ + int delta = dx - int(dx/scale_)*scale_; + if (delta) { + dx -= delta; w += delta; + } + delta = -dy - int((-dy)/scale_)*scale_; + if (delta) { + dy -= delta; h += delta; + } + delta = h - int(h/scale_)*scale_; + if (delta) { + h += delta; + } + delta = w - int(w/scale_)*scale_; + if (delta) { + w += delta; + } + } +} #if ! USE_PANGO @@ -455,8 +479,8 @@ Fl_Font Fl_Xlib_Graphics_Driver::set_fonts(const char* pattern_name) static const char* fl_encoding_ = "iso10646-1"; -void Fl_Xlib_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) { - fl_xft_font(this,fnum,size,0); +void Fl_Xlib_Graphics_Driver::font_unscaled(Fl_Font fnum, Fl_Fontsize size) { + fl_xft_font(this, fnum, size, 0); } static XftFont* fontopen(const char* name, /*Fl_Fontsize*/double size, bool core, int angle) { @@ -691,17 +715,17 @@ static void utf8extents(Fl_Font_Descriptor *desc, const char *str, int n, XGlyph #endif } -int Fl_Xlib_Graphics_Driver::height() { +int Fl_Xlib_Graphics_Driver::height_unscaled() { if (font_descriptor()) return font_descriptor()->font->ascent + font_descriptor()->font->descent; else return -1; } -int Fl_Xlib_Graphics_Driver::descent() { +int Fl_Xlib_Graphics_Driver::descent_unscaled() { if (font_descriptor()) return font_descriptor()->font->descent; else return -1; } -double Fl_Xlib_Graphics_Driver::width(const char* str, int n) { +double Fl_Xlib_Graphics_Driver::width_unscaled(const char* str, int n) { if (!font_descriptor()) return -1.0; XGlyphInfo i; utf8extents(font_descriptor(), str, n, &i); @@ -715,11 +739,12 @@ static double fl_xft_width(Fl_Font_Descriptor *desc, FcChar32 *str, int n) { return i.xOff; } -double Fl_Xlib_Graphics_Driver::width(unsigned int c) { +double Fl_Xlib_Graphics_Driver::width_unscaled(unsigned int c) { + if (!font_descriptor()) return -1.0; return fl_xft_width(font_descriptor(), (FcChar32 *)(&c), 1); } -void Fl_Xlib_Graphics_Driver::text_extents(const char *c, int n, int &dx, int &dy, int &w, int &h) { +void Fl_Xlib_Graphics_Driver::text_extents_unscaled(const char *c, int n, int &dx, int &dy, int &w, int &h) { if (!font_descriptor()) { w = h = 0; dx = dy = 0; @@ -730,15 +755,12 @@ void Fl_Xlib_Graphics_Driver::text_extents(const char *c, int n, int &dx, int &d w = gi.width; h = gi.height; - dx = -gi.x; - dy = -gi.y; -} // fl_text_extents - + dx = -gi.x + line_delta_; + dy = -gi.y + line_delta_; + correct_extents(scale_, dx, dy, w, h); +} -void Fl_Xlib_Graphics_Driver::draw(const char *str, int n, int x, int y) { - if ( !this->font_descriptor() ) { - this->font(FL_HELVETICA, FL_NORMAL_SIZE); - } +void Fl_Xlib_Graphics_Driver::draw_unscaled(const char *str, int n, int x, int y) { #if USE_OVERLAY XftDraw*& draw_ = fl_overlay ? draw_overlay : ::draw_; if (fl_overlay) { @@ -756,31 +778,32 @@ void Fl_Xlib_Graphics_Driver::draw(const char *str, int n, int x, int y) { XftDrawChange(draw_, draw_window = fl_window); Region region = fl_clip_region(); - if (region && XEmptyRegion(region)) return; - XftDrawSetClip(draw_, region); - - // Use fltk's color allocator, copy the results to match what - // XftCollorAllocValue returns: - XftColor color; - color.pixel = fl_xpixel(Fl_Graphics_Driver::color()); - uchar r,g,b; Fl::get_color(Fl_Graphics_Driver::color(), r,g,b); - color.color.red = ((int)r)*0x101; - color.color.green = ((int)g)*0x101; - color.color.blue = ((int)b)*0x101; - color.color.alpha = 0xffff; - - const wchar_t *buffer = utf8reformat(str, n); + if (!(region && XEmptyRegion(region))) { + XftDrawSetClip(draw_, region); + + // Use fltk's color allocator, copy the results to match what + // XftCollorAllocValue returns: + XftColor color; + color.pixel = fl_xpixel(Fl_Graphics_Driver::color()); + uchar r,g,b; Fl::get_color(Fl_Graphics_Driver::color(), r,g,b); + color.color.red = ((int)r)*0x101; + color.color.green = ((int)g)*0x101; + color.color.blue = ((int)b)*0x101; + color.color.alpha = 0xffff; + + const wchar_t *buffer = utf8reformat(str, n); #ifdef __CYGWIN__ - XftDrawString16(draw_, &color, font_descriptor()->font, x+offset_x_, y+offset_y_, (XftChar16 *)buffer, n); + XftDrawString16(draw_, &color, font_descriptor()->font, x+offset_x_*scale_+line_delta_, y+offset_y_*scale_+line_delta_, (XftChar16 *)buffer, n); #else - XftDrawString32(draw_, &color, font_descriptor()->font, x+offset_x_, y+offset_y_, (XftChar32 *)buffer, n); + XftDrawString32(draw_, &color, font_descriptor()->font, x+offset_x_*scale_+line_delta_, y+offset_y_*scale_+line_delta_, (XftChar32 *)buffer, n); #endif + } } -void Fl_Xlib_Graphics_Driver::draw(int angle, const char *str, int n, int x, int y) { - fl_xft_font(this, this->Fl_Graphics_Driver::font(), this->size(), angle); - this->draw(str, n, (int)x, (int)y); - fl_xft_font(this, this->Fl_Graphics_Driver::font(), this->size(), 0); +void Fl_Xlib_Graphics_Driver::draw_unscaled(int angle, const char *str, int n, int x, int y) { + fl_xft_font(this, this->Fl_Graphics_Driver::font(), this->size_unscaled(), angle); + this->draw_unscaled(str, n, x, y); + fl_xft_font(this, this->Fl_Graphics_Driver::font(), this->size_unscaled(), 0); } void Fl_Xlib_Graphics_Driver::drawUCS4(const void *str, int n, int x, int y) { @@ -814,11 +837,11 @@ 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, font_descriptor()->font, x+offset_x_, y+offset_x_, (FcChar32 *)str, n); + XftDrawString32(draw_, &color, font_descriptor()->font, x+offset_x_*scale_+line_delta_, y+offset_y_*scale_+line_delta_, (FcChar32 *)str, n); } -void Fl_Xlib_Graphics_Driver::rtl_draw(const char* c, int n, int x, int y) { +void Fl_Xlib_Graphics_Driver::rtl_draw_unscaled(const char* c, int n, int x, int y) { #if defined(__GNUC__) // FIXME: warning Need to improve this XFT right to left draw function @@ -902,7 +925,7 @@ int Fl_Xlib_Graphics_Driver::get_font_sizes(Fl_Font fnum, int*& sizep) { float Fl_Xlib_Graphics_Driver::scale_font_for_PostScript(Fl_Font_Descriptor *desc, int s) { // Xft font height is sometimes larger than the required size (see STR 2566). // Increase the PostScript font size by 15% without exceeding the display font height - int max = height(); + int max = height_unscaled(); float ps_size = s * 1.15; if (ps_size > max) ps_size = max; return ps_size; @@ -972,7 +995,7 @@ static void fl_xft_font(Fl_Xlib_Graphics_Driver *driver, Fl_Font fnum, Fl_Fontsi return; } Fl_Font_Descriptor* f = driver->font_descriptor(); - if (fnum == driver->Fl_Graphics_Driver::font() && size == driver->size() && f && f->angle == angle) + if (fnum == driver->Fl_Graphics_Driver::font() && size == driver->size_unscaled() && f && f->angle == angle) return; driver->Fl_Graphics_Driver::font(fnum, size); Fl_Fontdesc *font = fl_fonts + fnum; @@ -1021,7 +1044,7 @@ static void fl_xft_font(Fl_Xlib_Graphics_Driver *driver, Fl_Font fnum, Fl_Fontsi // well for the fltk "built-in" font names. static XFontStruct* load_xfont_for_xft2(Fl_Graphics_Driver *driver) { XFontStruct* xgl_font = 0; - int size = driver->size(); + int size = ((Fl_Xlib_Graphics_Driver*)driver)->size_unscaled(); int fnum = driver->font(); const char *wt_med = "medium"; const char *wt_bold = "bold"; @@ -1112,10 +1135,10 @@ static XFontStruct* fl_xxfont(Fl_Graphics_Driver *driver) { static int glsize = 0; static int glfont = -1; // Do we need to load a new font? - if ((!xgl_font) || (glsize != driver->size()) || (glfont != driver->font())) { + if ((!xgl_font) || (glsize != ((Fl_Xlib_Graphics_Driver*)driver)->size_unscaled()) || (glfont != driver->font())) { // create a dummy XLFD for some font of the appropriate size... if (xgl_font) XFreeFont(fl_display, xgl_font); // font already loaded, free it - this *might* be a Bad Idea - glsize = driver->size(); // record current font size + glsize = ((Fl_Xlib_Graphics_Driver*)driver)->size_unscaled(); // record current font size glfont = driver->font(); // and face xgl_font = load_xfont_for_xft2(driver); } @@ -1126,7 +1149,7 @@ static XFontStruct* fl_xxfont(Fl_Graphics_Driver *driver) { } static XftFont* xftfont; if (xftfont) XftFontClose (fl_display, xftfont); - xftfont = fontopen(fl_fonts[driver->font()].name, driver->size(), true, 0); // else request XFT to load a suitable "core" font instead. + xftfont = fontopen(fl_fonts[driver->font()].name, ((Fl_Xlib_Graphics_Driver*)driver)->size_unscaled(), true, 0); // else request XFT to load a suitable "core" font instead. return xftfont->u.core.font; # endif // XFT_MAJOR > 1 } @@ -1161,9 +1184,13 @@ PangoContext *Fl_Xlib_Graphics_Driver::context() { return pctxt_; } -void Fl_Xlib_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) { +void Fl_Xlib_Graphics_Driver::font_unscaled(Fl_Font fnum, Fl_Fontsize size) { if (!size) return; - if (this->Fl_Graphics_Driver::font() == fnum && this->size() == size) return; + if (size < 0) { + Fl_Graphics_Driver::font(0, 0); + return; + } + if (this->Fl_Graphics_Driver::font() == fnum && this->size_unscaled() == size) return; fl_xft_font(this, fnum, size, 0); init_built_in_fonts(); if (pfd_) pango_font_description_free(pfd_); @@ -1180,21 +1207,21 @@ void Fl_Xlib_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) { } } -void Fl_Xlib_Graphics_Driver::draw(const char *str, int n, int x, int y) { - do_draw(0, str, n, x+offset_x_, y+offset_y_); +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_); } -void Fl_Xlib_Graphics_Driver::draw(int angle, const char *str, int n, int x, int 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_, y+offset_y_); // 1.6 + pango_matrix_translate(&mat, x+offset_x_*scale_, y+offset_y_*scale_); // 1.6 pango_matrix_rotate(&mat, angle); // 1.6 pango_context_set_matrix(pctxt_, &mat); // 1.6 do_draw(0, str, n, 0, 0); pango_context_set_matrix(pctxt_, NULL); // 1.6 } -void Fl_Xlib_Graphics_Driver::rtl_draw(const char* str, int n, int x, int y) { - do_draw(1, str, n, x+offset_x_, y+offset_y_); +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_); } void Fl_Xlib_Graphics_Driver::do_draw(int from_right, const char *str, int n, int x, int y) { @@ -1245,12 +1272,13 @@ void Fl_Xlib_Graphics_Driver::do_draw(int from_right, const char *str, int n, in else XftDrawChange(draw_, draw_window = fl_window); XftDrawSetClip(draw_, region); - pango_xft_render_layout(draw_, &color, playout_, x*PANGO_SCALE, (y-height()+descent())*PANGO_SCALE ); // 1.8 -} + pango_xft_render_layout(draw_, &color, playout_, (x + line_delta_)*PANGO_SCALE, + (y+line_delta_-height_unscaled()+descent_unscaled())*PANGO_SCALE ); // 1.8 + } -double Fl_Xlib_Graphics_Driver::width(const char* str, int n) { +double Fl_Xlib_Graphics_Driver::width_unscaled(const char* str, int n) { if (!n) return 0; - if (!fl_display || fl_size() == 0) return -1; + if (!fl_display || size_ == 0) return -1; if (!playout_) context(); int width, height; pango_layout_set_font_description(playout_, pfd_); @@ -1259,30 +1287,31 @@ double Fl_Xlib_Graphics_Driver::width(const char* str, int n) { return (double)width; } -void Fl_Xlib_Graphics_Driver::text_extents(const char *str, int n, int &dx, int &dy, int &w, int &h) { +void Fl_Xlib_Graphics_Driver::text_extents_unscaled(const char *str, int n, int &dx, int &dy, int &w, int &h) { if (!playout_) context(); pango_layout_set_font_description(playout_, pfd_); pango_layout_set_text(playout_, str, n); PangoRectangle ink_rect, logical_rect; pango_layout_get_pixel_extents(playout_, &ink_rect, &logical_rect); - dx = ink_rect.x; - dy = ink_rect.y - height() + descent(); + dx = ink_rect.x + line_delta_; + dy = ink_rect.y + line_delta_ - height_unscaled() + descent_unscaled(); w = ink_rect.width; h = ink_rect.height; + correct_extents(scale_, dx, dy, w, h); } -int Fl_Xlib_Graphics_Driver::height() { +int Fl_Xlib_Graphics_Driver::height_unscaled() { if (font_descriptor()) return font_descriptor()->height_; else return -1; } -double Fl_Xlib_Graphics_Driver::width(unsigned int c) { +double Fl_Xlib_Graphics_Driver::width_unscaled(unsigned int c) { char buf4[4]; int n = fl_utf8encode(c, buf4); - return width(buf4, n); + return width_unscaled(buf4, n); } -int Fl_Xlib_Graphics_Driver::descent() { +int Fl_Xlib_Graphics_Driver::descent_unscaled() { if (font_descriptor()) return font_descriptor()->descent_; else return -1; } diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx index 44bd17a42..c7b298493 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx @@ -47,10 +47,13 @@ #include <config.h> #include "Fl_Xlib_Graphics_Driver.H" +#include "../X11/Fl_X11_Screen_Driver.H" +#include "../X11/Fl_X11_Window_Driver.H" # include <FL/Fl.H> # include <FL/fl_draw.H> # include <FL/x.H> # include <FL/Fl_Image_Surface.H> +# include <FL/Fl_Screen_Driver.H> # include "../../Fl_XColor.H" # include "../../flstring.h" #if HAVE_XRENDER @@ -476,7 +479,6 @@ static void innards(const uchar *buf, int X, int Y, int W, int H, if (w<=0 || h<=0) return; dx -= X; dy -= Y; - if (!bytes_per_pixel) figure_out_visual(); const unsigned oldbpp = bytes_per_pixel; static GC gc32 = None; @@ -574,32 +576,32 @@ static void innards(const uchar *buf, int X, int Y, int W, int H, } } -void Fl_Xlib_Graphics_Driver::draw_image(const uchar* buf, int x, int y, int w, int h, int d, int l){ +void Fl_Xlib_Graphics_Driver::draw_image_unscaled(const uchar* buf, int x, int y, int w, int h, int d, int l){ const bool alpha = !!(abs(d) & FL_IMAGE_WITH_ALPHA); if (alpha) d ^= FL_IMAGE_WITH_ALPHA; const int mono = (d>-3 && d<3); - innards(buf,x+offset_x_,y+offset_y_,w,h,d,l,mono,0,0,alpha,gc_); + innards(buf,x+offset_x_*scale_,y+offset_y_*scale_,w,h,d,l,mono,0,0,alpha,gc_); } -void Fl_Xlib_Graphics_Driver::draw_image(Fl_Draw_Image_Cb cb, void* data, +void Fl_Xlib_Graphics_Driver::draw_image_unscaled(Fl_Draw_Image_Cb cb, void* data, int x, int y, int w, int h,int d) { const bool alpha = !!(abs(d) & FL_IMAGE_WITH_ALPHA); if (alpha) d ^= FL_IMAGE_WITH_ALPHA; const int mono = (d>-3 && d<3); - innards(0,x+offset_x_,y+offset_y_,w,h,d,0,mono,cb,data,alpha,gc_); + innards(0,x+offset_x_*scale_,y+offset_y_*scale_,w,h,d,0,mono,cb,data,alpha,gc_); } -void Fl_Xlib_Graphics_Driver::draw_image_mono(const uchar* buf, int x, int y, int w, int h, int d, int l){ - innards(buf,x+offset_x_,y+offset_y_,w,h,d,l,1,0,0,0,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_); } -void Fl_Xlib_Graphics_Driver::draw_image_mono(Fl_Draw_Image_Cb cb, void* data, +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_,y+offset_y_,w,h,d,0,1,cb,data,0,gc_); + innards(0,x+offset_x_*scale_,y+offset_y_*scale_,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) { @@ -622,15 +624,14 @@ void Fl_Xlib_Graphics_Driver::delete_bitmask(Fl_Bitmask bm) { XFreePixmap(fl_display, bm); } -void Fl_Xlib_Graphics_Driver::draw(Fl_Bitmap *bm, int XP, int YP, int WP, int HP, int cx, int cy) { - int X, Y, W, H; - if (Fl_Graphics_Driver::prepare(bm, XP+offset_x_, YP+offset_y_, WP, HP, cx, cy, X, Y, W, H)) { - return; - } - +void Fl_Xlib_Graphics_Driver::draw_unscaled(Fl_Bitmap *bm, float s, int X, int Y, int W, int H, int cx, int cy) { + X = (X+offset_x_)*s; + Y = (Y+offset_y_)*s; + cache_size(bm, W, H); + cx *= s; cy *= s; XSetStipple(fl_display, gc_, *Fl_Graphics_Driver::id(bm)); - int ox = X-cx; if (ox < 0) ox += bm->w(); - int oy = Y-cy; if (oy < 0) oy += bm->h(); + int ox = X-cx; if (ox < 0) ox += bm->w()*s; + int oy = Y-cy; if (oy < 0) oy += bm->h()*s; XSetTSOrigin(fl_display, gc_, ox, oy); XSetFillStyle(fl_display, gc_, FillStippled); XFillRectangle(fl_display, fl_window, gc_, X, Y, W, H); @@ -715,33 +716,42 @@ static Fl_Offscreen cache_rgb(Fl_RGB_Image *img) { return off; } -void Fl_Xlib_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy) { - int X, Y, W, H; - XP += offset_x_; - YP += offset_y_; - // Don't draw an empty image... - if (!img->d() || !img->array) { - Fl_Graphics_Driver::draw_empty(img, XP, YP); - return; - } - if (start_image(img, XP, YP, WP, HP, cx, cy, X, Y, W, H)) { - return; - } +// X,Y,W,H,cx,cy are in FLTK units +// if s != 1 and id(img) != 0, the offscreen has been previously scaled by s +// if s != 1 and id(img) == 0, img has been previously scaled by s +void Fl_Xlib_Graphics_Driver::draw_unscaled(Fl_RGB_Image *img, float s, int X, int Y, int W, int H, int cx, int cy) { + X = (X+offset_x_)*s; + Y = (Y+offset_y_)*s; + cache_size(img, W, H); + cx *= s; cy *= s; if (!*Fl_Graphics_Driver::id(img)) { *Fl_Graphics_Driver::id(img) = cache_rgb(img); + *cache_scale(img) = 1; } + Fl_Region r2 = scale_clip(s); if (*Fl_Graphics_Driver::id(img)) { if (img->d() == 4 || img->d() == 2) { #if HAVE_XRENDER - scale_and_render_pixmap(*Fl_Graphics_Driver::id(img), 4, 1, 1, cx, cy, X - offset_x_, Y - offset_y_, W, H); + scale_and_render_pixmap(*Fl_Graphics_Driver::id(img), img->d(), 1, 1, cx, cy, X, Y, W, H); #endif } else { - copy_offscreen(X - offset_x_, Y - offset_y_, W, H, *Fl_Graphics_Driver::id(img), cx, cy); + XCopyArea(fl_display, *Fl_Graphics_Driver::id(img), fl_window, gc_, cx, cy, W, H, X, Y); } } else { // Composite image with alpha manually each time... + scale_ = 1; + int ox = offset_x_, oy = offset_y_; + offset_x_ = offset_y_ = 0; + Fl_X11_Screen_Driver *d = (Fl_X11_Screen_Driver*)Fl::screen_driver(); + int nscreen = Fl_Window::current()->driver()->screen_num(); + float keep = d->scale(nscreen); + d->scale(nscreen, 1); alpha_blend(img, X, Y, W, H, cx, cy); + d->scale(nscreen, keep); + scale_ = s; + offset_x_ = ox; offset_y_ = oy; } + unscale_clip(r2); } void Fl_Xlib_Graphics_Driver::uncache(Fl_RGB_Image*, fl_uintptr_t &id_, fl_uintptr_t &mask_) @@ -752,13 +762,17 @@ void Fl_Xlib_Graphics_Driver::uncache(Fl_RGB_Image*, fl_uintptr_t &id_, fl_uintp } } -fl_uintptr_t Fl_Xlib_Graphics_Driver::cache(Fl_Bitmap*, int w, int h, const uchar *array) { +fl_uintptr_t Fl_Xlib_Graphics_Driver::cache(Fl_Bitmap *bm, int w, int h, const uchar *array) { + *cache_scale(bm) = Fl_Scalable_Graphics_Driver::scale(); return (fl_uintptr_t)create_bitmask(w, h, array); } -void Fl_Xlib_Graphics_Driver::draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy) { - int X, Y, W, H; - if (Fl_Graphics_Driver::prepare(pxm, XP+offset_x_, YP+offset_y_, WP, HP, cx, cy, X, Y, W, H)) return; +void Fl_Xlib_Graphics_Driver::draw_unscaled(Fl_Pixmap *pxm, float s, int X, int Y, int W, int H, int cx, int cy) { + X = (X+offset_x_)*s; + Y = (Y+offset_y_)*s; + cache_size(pxm, W, H); + cx *= s; cy *= s; + Fl_Region r2 = scale_clip(s); if (*Fl_Graphics_Driver::mask(pxm)) { // make X use the bitmap as a mask: XSetClipMask(fl_display, gc_, *Fl_Graphics_Driver::mask(pxm)); @@ -781,21 +795,24 @@ void Fl_Xlib_Graphics_Driver::draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int H Y1 = r->rects[i].y1; W1 = r->rects[i].x2 - r->rects[i].x1; H1 = r->rects[i].y2 - r->rects[i].y1; - copy_offscreen(X1-offset_x_, Y1-offset_y_, W1, H1, *Fl_Graphics_Driver::id(pxm), cx + (X1 - X), cy + (Y1 - Y)); + XCopyArea(fl_display, *Fl_Graphics_Driver::id(pxm), fl_window, gc_, cx + (X1 - X), cy + (Y1 - Y), W1, H1, X1, Y1); } XDestroyRegion(r); } else { - copy_offscreen(X-offset_x_, Y-offset_y_, W, H, *Fl_Graphics_Driver::id(pxm), cx, cy); + XCopyArea(fl_display, *Fl_Graphics_Driver::id(pxm), fl_window, gc_, cx, cy, W, H, X, Y); } // put the old clip region back XSetClipOrigin(fl_display, gc_, 0, 0); + s = scale_; scale_ = 1; restore_clip(); + scale_ = s; } - else copy_offscreen(X-offset_x_, Y-offset_y_, W, H, *Fl_Graphics_Driver::id(pxm), cx, cy); + else XCopyArea(fl_display, *Fl_Graphics_Driver::id(pxm), fl_window, gc_, cx, cy, W, H, X, Y); + unscale_clip(r2); } -fl_uintptr_t Fl_Xlib_Graphics_Driver::cache(Fl_Pixmap *img, int w, int h, const char *const*data) { +fl_uintptr_t Fl_Xlib_Graphics_Driver::cache(Fl_Pixmap *pxm, int w, int h, const char *const*data) { Fl_Offscreen id; id = fl_create_offscreen(w, h); fl_begin_offscreen(id); @@ -804,22 +821,26 @@ fl_uintptr_t Fl_Xlib_Graphics_Driver::cache(Fl_Pixmap *img, int w, int h, const fl_draw_pixmap(data, 0, 0, FL_BLACK); Fl_Surface_Device::surface()->driver()->mask_bitmap(0); if (bitmap) { - *Fl_Graphics_Driver::mask(img) = (fl_uintptr_t)fl_create_bitmask(w, h, bitmap); + *Fl_Graphics_Driver::mask(pxm) = (fl_uintptr_t)create_bitmask(w * scale_, h * scale_, bitmap); delete[] bitmap; } fl_end_offscreen(); + *cache_scale(pxm) = Fl_Scalable_Graphics_Driver::scale(); return (fl_uintptr_t)id; } #if HAVE_XRENDER +/* Draws with Xrender an Fl_Offscreen with optional scaling and accounting for transparency if necessary. + XP,YP,WP,HP are in drawing units + */ int Fl_Xlib_Graphics_Driver::scale_and_render_pixmap(Fl_Offscreen pixmap, int depth, double scale_x, double scale_y, int srcx, int srcy, int XP, int YP, int WP, int HP) { + bool has_alpha = (depth == 2 || depth == 4); XRenderPictureAttributes srcattr; memset(&srcattr, 0, sizeof(XRenderPictureAttributes)); static XRenderPictFormat *fmt32 = XRenderFindStandardFormat(fl_display, PictStandardARGB32); static XRenderPictFormat *fmt24 = XRenderFindStandardFormat(fl_display, PictStandardRGB24); - Picture src = XRenderCreatePicture(fl_display, pixmap, - depth%2 == 0 ?fmt32:fmt24, 0, &srcattr); + Picture src = XRenderCreatePicture(fl_display, pixmap, has_alpha ?fmt32:fmt24, 0, &srcattr); Picture dst = XRenderCreatePicture(fl_display, fl_window, fmt24, 0, &srcattr); if (!src || !dst) { fprintf(stderr, "Failed to create Render pictures (%lu %lu)\n", src, dst); @@ -836,22 +857,24 @@ int Fl_Xlib_Graphics_Driver::scale_and_render_pixmap(Fl_Offscreen pixmap, int de }}; XRenderSetPictureTransform(fl_display, src, &mat); } - XRenderComposite(fl_display, (depth%2 == 0 ? PictOpOver : PictOpSrc), src, None, dst, srcx, srcy, 0, 0, - XP + offset_x_, YP + offset_y_, WP, HP); + XRenderComposite(fl_display, (has_alpha ? PictOpOver : PictOpSrc), src, None, dst, srcx, srcy, 0, 0, + XP, YP, WP, HP); XRenderFreePicture(fl_display, src); XRenderFreePicture(fl_display, dst); return 1; } - +// XP,YP,WP,HP are in FLTK units int Fl_Xlib_Graphics_Driver::draw_scaled(Fl_Image *img, int XP, int YP, int WP, int HP) { Fl_RGB_Image *rgb = img->as_rgb_image(); if (!rgb || !can_do_alpha_blending()) return 0; if (!*Fl_Graphics_Driver::id(rgb)) { *Fl_Graphics_Driver::id(rgb) = cache_rgb(rgb); + *cache_scale(rgb) = 1; } - return scale_and_render_pixmap(*Fl_Graphics_Driver::id(rgb), rgb->d(), rgb->w()/double(WP), rgb->h()/double(HP), - 0, 0, XP, YP, WP, HP); + cache_size(img, WP, HP); + return scale_and_render_pixmap( *Fl_Graphics_Driver::id(rgb), rgb->d(), + rgb->w() / double(WP), rgb->h() / double(HP), 0, 0, (XP + offset_x_)*scale_, (YP + offset_y_)*scale_, WP, HP); } #endif // HAVE_XRENDER 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 a10ce7972..6629d7bfa 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_line_style.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_line_style.cxx @@ -3,7 +3,7 @@ // // Line style code for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2016 by Bill Spitzak and others. +// Copyright 1998-2017 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -34,10 +34,9 @@ #include "Fl_Xlib_Graphics_Driver.H" -void Fl_Xlib_Graphics_Driver::line_style(int style, int width, char* dashes) { - +void Fl_Xlib_Graphics_Driver::line_style_unscaled(int style, float width, char* dashes) { // save line width for X11 clipping - if (width == 0) line_width_ = 1; + if (width == 0) line_width_ = scale_ < 2 ? 0 : scale_; else line_width_ = width>0 ? width : -width; int ndashes = dashes ? strlen(dashes) : 0; @@ -63,10 +62,12 @@ void Fl_Xlib_Graphics_Driver::line_style(int style, int width, char* dashes) { case FL_DASHDOTDOT: *p++ = dash; *p++ = gap; *p++ = dot; *p++ = gap; *p++ = dot; *p++ = gap; break; } ndashes = p-buf; +if (*dashes == 0) ndashes = 0;//against error with very small scaling } static int Cap[4] = {CapButt, CapButt, CapRound, CapProjecting}; static int Join[4] = {JoinMiter, JoinMiter, JoinRound, JoinBevel}; - XSetLineAttributes(fl_display, gc_, width, + XSetLineAttributes(fl_display, gc_, + line_width_, ndashes ? LineOnOffDash : LineSolid, Cap[(style>>8)&3], Join[(style>>12)&3]); if (ndashes) XSetDashes(fl_display, gc_, 0, dashes, ndashes); diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_rect.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_rect.cxx index 71395afdf..bc318a7e9 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_rect.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_rect.cxx @@ -3,7 +3,7 @@ // // Rectangle drawing routines for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2016 by Bill Spitzak and others. +// Copyright 1998-2017 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -161,112 +161,167 @@ void Fl_Xlib_Graphics_Driver::XDestroyRegion(Fl_Region r) { ::XDestroyRegion(r); } -// --- line and polygon drawing with integer coordinates +// --- line and polygon drawing -void Fl_Xlib_Graphics_Driver::point(int x, int y) { - XDrawPoint(fl_display, fl_window, gc_, clip_x(x+offset_x_), clip_x(y+offset_y_)); -} -void Fl_Xlib_Graphics_Driver::rect(int x, int y, int w, int h) { - if (w<=0 || h<=0) return; - x+=offset_x_; y+=offset_y_; +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(int(fx/scale_+fw/scale_+0.5)*scale_) - x - 1 - deltaf; + int h = int(int(fy/scale_+fh/scale_+0.5)*scale_) - y - 1 - deltaf; if (!clip_to_short(x, y, w, h, line_width_)) - XDrawRectangle(fl_display, fl_window, gc_, x, y, w-1, h-1); + XDrawRectangle(fl_display, fl_window, gc_, x+line_delta_, y+line_delta_, w, h); } -void Fl_Xlib_Graphics_Driver::rectf(int x, int y, int w, int h) { - if (w<=0 || h<=0) return; - x+=offset_x_; y+=offset_y_; +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); if (!clip_to_short(x, y, w, h, line_width_)) - XFillRectangle(fl_display, fl_window, gc_, 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; + XFillRectangle(fl_display, fl_window, gc_, x+line_delta_, y+line_delta_, width, width); } -void Fl_Xlib_Graphics_Driver::line(int x, int y, int x1, int y1) { - XDrawLine(fl_display, fl_window, gc_, x+offset_x_, y+offset_y_, x1+offset_x_, y1+offset_y_); +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 XDrawLine(fl_display, fl_window, gc_, 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(int x, int y, int x1, int y1, int x2, int y2) { +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_; p[0].y = y+offset_y_; - p[1].x = x1+offset_x_; p[1].y = y1+offset_y_; - p[2].x = x2+offset_x_; p[2].y = y2+offset_y_; + 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_; XDrawLines(fl_display, fl_window, gc_, p, 3, 0); } -void Fl_Xlib_Graphics_Driver::xyline(int x, int y, int x1) { - XDrawLine(fl_display, fl_window, gc_, clip_x(x+offset_x_), clip_x(y+offset_y_), clip_x(x1+offset_x_), clip_x(y+offset_y_)); +void Fl_Xlib_Graphics_Driver::xyline_unscaled(float x, float y, float x1) {//OK + 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_x(x+line_delta_); if (scale_ >= 2) ix -= int(scale_/2); + int iy = clip_x(y+line_delta_); + int ix1 = int(x1/scale_+1.5)*scale_-1; if (scale_ >= 2) ix1 += int(scale_/2); if (scale_ >= 4) ix1 -= scale_/2; + XDrawLine(fl_display, fl_window, gc_, ix, iy, ix1, iy); + // try and 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 ) XDrawLine(fl_display, fl_window, gc_, ix, iy+1, ix1, iy+1); } -void Fl_Xlib_Graphics_Driver::xyline(int x, int y, int x1, int y2) { +void Fl_Xlib_Graphics_Driver::xyline_unscaled(float x, float y, float x1, float y2) {//OK + x+=offset_x_*scale_; y+=offset_y_*scale_; x1 += offset_x_*scale_; y2+=offset_y_*scale_; + if (scale_ >= 2) { + int delta = int(scale_/2 + 0.5); + if (x > x1) x += delta; else x -= delta; + if (y2 > y) y2 += delta; else y2 -= delta; + } XPoint p[3]; - p[0].x = clip_x(x+offset_x_); p[0].y = p[1].y = clip_x(y+offset_y_); - p[1].x = p[2].x = clip_x(x1+offset_x_); p[2].y = clip_x(y2+offset_y_); + p[0].x = clip_x(x+line_delta_); p[0].y = p[1].y = clip_x(y+line_delta_); + p[1].x = p[2].x = clip_x(x1+line_delta_); p[2].y = clip_x(y2+line_delta_); XDrawLines(fl_display, fl_window, gc_, p, 3, 0); } -void Fl_Xlib_Graphics_Driver::xyline(int x, int y, int x1, int y2, int x3) { +void Fl_Xlib_Graphics_Driver::xyline_unscaled(float x, float y, float x1, float y2, float x3) { + x+=offset_x_*scale_; y+=offset_y_*scale_; x1 += offset_x_*scale_; y2+=offset_y_*scale_; x3 += offset_x_*scale_; + if (scale_ >= 2) { + int delta = int(scale_/2 + 0.5); + if (x > x1) x += delta; else x -= delta; + if (x3 > x1) x3 += delta; else x3 -= delta; + } XPoint p[4]; - p[0].x = clip_x(x+offset_x_); p[0].y = p[1].y = clip_x(y+offset_y_); - p[1].x = p[2].x = clip_x(x1+offset_x_); p[2].y = p[3].y = clip_x(y2+offset_y_); - p[3].x = clip_x(x3+offset_x_); + p[0].x = clip_x(x+line_delta_); p[0].y = p[1].y = clip_x(y+line_delta_); + p[1].x = p[2].x = clip_x(x1+line_delta_); p[2].y = p[3].y = clip_x(y2+line_delta_); + p[3].x = clip_x(x3+line_delta_); XDrawLines(fl_display, fl_window, gc_, p, 4, 0); } -void Fl_Xlib_Graphics_Driver::yxline(int x, int y, int y1) { - XDrawLine(fl_display, fl_window, gc_, clip_x(x+offset_x_), clip_x(y+offset_y_), clip_x(x+offset_x_), clip_x(y1+offset_y_)); +void Fl_Xlib_Graphics_Driver::yxline_unscaled(float x, float y, float y1) {//OK + 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_x(x+line_delta_); + int iy = clip_x(y+line_delta_); if (scale_ >= 2) iy -= int(scale_/2); + int iy1 = int(y1/scale_+1.5)*scale_-1; if (scale_ >= 2) iy1 += int(scale_/2); if (scale_ >= 4) iy1 -= scale_/2; + XDrawLine(fl_display, fl_window, gc_, ix, iy, ix, iy1); + // try and 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) XDrawLine(fl_display, fl_window, gc_, ix+1, iy, ix+1, iy1); } -void Fl_Xlib_Graphics_Driver::yxline(int x, int y, int y1, int x2) { +void Fl_Xlib_Graphics_Driver::yxline_unscaled(float x, float y, float y1, float x2) { + x+=offset_x_*scale_; y+=offset_y_*scale_; y1 += offset_y_*scale_; x2+=offset_x_*scale_; + if (scale_ >= 2) { + int delta = int(scale_/2 + 0.5); + if (y > y1) y += delta; else y -= delta; + if (x2 > x) x2 += delta; else x2 -= delta; + } XPoint p[3]; - p[0].x = p[1].x = clip_x(x+offset_x_); p[0].y = clip_x(y+offset_y_); - p[1].y = p[2].y = clip_x(y1+offset_y_); p[2].x = clip_x(x2+offset_x_); + p[0].x = p[1].x = clip_x(x+line_delta_); p[0].y = clip_x(y+line_delta_); + p[1].y = p[2].y = clip_x(y1+line_delta_); p[2].x = clip_x(x2+line_delta_); XDrawLines(fl_display, fl_window, gc_, p, 3, 0); } -void Fl_Xlib_Graphics_Driver::yxline(int x, int y, int y1, int x2, int y3) { +void Fl_Xlib_Graphics_Driver::yxline_unscaled(float x, float y, float y1, float x2, float y3) { + x+=offset_x_*scale_; y+=offset_y_*scale_; y1 += offset_y_*scale_; x2+=offset_x_*scale_; y3 += offset_y_*scale_; + if (scale_ >= 2) { + int delta = int(scale_/2 + 0.5); + if (y > y1) y += delta; else y -= delta; + if (y3 > y1) y3 += delta; else y3 -= delta; + } XPoint p[4]; - p[0].x = p[1].x = clip_x(x+offset_x_); p[0].y = clip_x(y+offset_y_); - p[1].y = p[2].y = clip_x(y1+offset_y_); p[2].x = p[3].x = clip_x(x2+offset_x_); - p[3].y = clip_x(y3+offset_y_); + p[0].x = p[1].x = clip_x(x+line_delta_); p[0].y = clip_x(y+line_delta_); + p[1].y = p[2].y = clip_x(y1+line_delta_); p[2].x = p[3].x = clip_x(x2+line_delta_); + p[3].y = clip_x(y3+line_delta_); XDrawLines(fl_display, fl_window, gc_, p, 4, 0); } -void Fl_Xlib_Graphics_Driver::loop(int x, int y, int x1, int y1, int x2, int y2) { +void Fl_Xlib_Graphics_Driver::loop_unscaled(float x, float y, float x1, float y1, float x2, float y2) { XPoint p[4]; - p[0].x = x+offset_x_; p[0].y = y+offset_y_; - p[1].x = x1+offset_x_; p[1].y = y1+offset_y_; - p[2].x = x2+offset_x_; p[2].y = y2+offset_y_; - p[3].x = x+offset_x_; p[3].y = y+offset_y_; + 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_; XDrawLines(fl_display, fl_window, gc_, p, 4, 0); } -void Fl_Xlib_Graphics_Driver::loop(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) { +void Fl_Xlib_Graphics_Driver::loop_unscaled(float x, float y, float x1, float y1, float x2, float y2, float x3, float y3) { XPoint p[5]; - p[0].x = x+offset_x_; p[0].y = y+offset_y_; - p[1].x = x1+offset_x_; p[1].y = y1+offset_y_; - p[2].x = x2+offset_x_; p[2].y = y2+offset_y_; - p[3].x = x3+offset_x_; p[3].y = y3+offset_y_; - p[4].x = x+offset_x_; p[4].y = y+offset_y_; + 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_; XDrawLines(fl_display, fl_window, gc_, p, 5, 0); } -void Fl_Xlib_Graphics_Driver::polygon(int x, int y, int x1, int y1, int x2, int y2) { +void Fl_Xlib_Graphics_Driver::polygon_unscaled(float x, float y, float x1, float y1, float x2, float y2) { XPoint p[4]; - p[0].x = x+offset_x_; p[0].y = y+offset_y_; - p[1].x = x1+offset_x_; p[1].y = y1+offset_y_; - p[2].x = x2+offset_x_; p[2].y = y2+offset_y_; - p[3].x = x+offset_x_; p[3].y = y+offset_y_; + 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_; 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(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) { +void Fl_Xlib_Graphics_Driver::polygon_unscaled(float x, float y, float x1, float y1, float x2, float y2, float x3, float y3) { XPoint p[5]; - p[0].x = x+offset_x_; p[0].y = y+offset_y_; - p[1].x = x1+offset_x_; p[1].y = y1+offset_y_; - p[2].x = x2+offset_x_; p[2].y = y2+offset_y_; - p[3].x = x3+offset_x_; p[3].y = y3+offset_y_; - p[4].x = x+offset_x_; p[4].y = y+offset_y_; + 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_; XFillPolygon(fl_display, fl_window, gc_, p, 4, Convex, 0); XDrawLines(fl_display, fl_window, gc_, p, 5, 0); } @@ -276,7 +331,7 @@ void Fl_Xlib_Graphics_Driver::polygon(int x, int y, int x1, int y1, int x2, int void Fl_Xlib_Graphics_Driver::push_clip(int x, int y, int w, int h) { Fl_Region r; if (w > 0 && h > 0) { - r = XRectangleRegion(x+offset_x_,y+offset_y_,w,h); + r = XRectangleRegion(x,y,w,h); Fl_Region current = rstack[rstackptr]; if (current) { Fl_Region temp = XCreateRegion(); @@ -294,8 +349,6 @@ void Fl_Xlib_Graphics_Driver::push_clip(int x, int y, int w, int h) { int Fl_Xlib_Graphics_Driver::clip_box(int x, int y, int w, int h, int& X, int& Y, int& W, int& H){ X = x; Y = y; W = w; H = h; - x += offset_x_; - y += offset_y_; Fl_Region r = rstack[rstackptr]; if (!r) return 0; switch (XRectInRegion(r, x, y, w, h)) { @@ -312,15 +365,13 @@ int Fl_Xlib_Graphics_Driver::clip_box(int x, int y, int w, int h, int& X, int& Y XIntersectRegion(r, rr, temp); XRectangle rect; XClipBox(temp, &rect); - X = rect.x - offset_x_; Y = rect.y - offset_y_; W = rect.width; H = rect.height; + X = rect.x; Y = rect.y; W = rect.width; H = rect.height; XDestroyRegion(temp); XDestroyRegion(rr); return 1; } int Fl_Xlib_Graphics_Driver::not_clipped(int x, int y, int w, int h) { - x += offset_x_; - y += offset_y_; if (x+w <= 0 || y+h <= 0) return 0; Fl_Region r = rstack[rstackptr]; if (!r) return 1; @@ -348,8 +399,12 @@ void Fl_Xlib_Graphics_Driver::pop_clip() { void Fl_Xlib_Graphics_Driver::restore_clip() { fl_clip_state_number++; if (gc_) { - Fl_Region r = rstack[rstackptr]; - if (r) XSetRegion(fl_display, gc_, r); + Region r = rstack[rstackptr]; + if (r) { + Region r2 = scale_clip(scale_); + XSetRegion(fl_display, gc_, rstack[rstackptr]); + unscale_clip(r2); + } else XSetClipMask(fl_display, gc_, 0); } } diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_vertex.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_vertex.cxx index 05c58eb8d..d36b540e7 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_vertex.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_vertex.cxx @@ -3,7 +3,7 @@ // // Portable drawing routines for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2016 by Bill Spitzak and others. +// Copyright 1998-2017 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -30,14 +30,6 @@ #include <FL/math.h> -void Fl_Xlib_Graphics_Driver::transformed_vertex(double xf, double yf) { - transformed_vertex0(short(rint(xf)), short(rint(yf))); -} - -void Fl_Xlib_Graphics_Driver::vertex(double x,double y) { - transformed_vertex0(short(x*m.a + y*m.c + m.x), short(x*m.b + y*m.d + m.y)); -} - void Fl_Xlib_Graphics_Driver::end_points() { if (n>1) XDrawPoints(fl_display, fl_window, gc_, (XPoint*)p, n, 0); } @@ -52,7 +44,9 @@ void Fl_Xlib_Graphics_Driver::end_line() { void Fl_Xlib_Graphics_Driver::end_loop() { fixloop(); - if (n>2) transformed_vertex((short)p[0].x, (short)p[0].y); + if (n>2) { + transformed_vertex0(p[0].x, p[0].y); + } end_line(); } @@ -73,7 +67,7 @@ void Fl_Xlib_Graphics_Driver::begin_complex_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_vertex((short)p[gap_].x, (short)p[gap_].y); + transformed_vertex0(p[gap_].x, p[gap_].y); gap_ = n; } else { n = gap_; @@ -92,12 +86,7 @@ void Fl_Xlib_Graphics_Driver::end_complex_polygon() { // shortcut the closed circles so they use XDrawArc: // warning: these do not draw rotated ellipses correctly! // See fl_arc.c for portable version. - -void Fl_Xlib_Graphics_Driver::circle(double x, double y,double r) { - double xt = transform_x(x,y); - double yt = transform_y(x,y); - double rx = r * (m.c ? sqrt(m.a*m.a+m.c*m.c) : fabs(m.a)); - double ry = r * (m.b ? sqrt(m.b*m.b+m.d*m.d) : fabs(m.d)); +void Fl_Xlib_Graphics_Driver::ellipse_unscaled(double xt, double yt, double rx, double ry) { int llx = (int)rint(xt-rx); int w = (int)rint(xt+rx)-llx; int lly = (int)rint(yt-ry); diff --git a/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx b/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx index 49a84e7d8..fa2aaeb5d 100644 --- a/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx @@ -24,12 +24,13 @@ #include "Fl_Xlib_Graphics_Driver.H" #include <FL/Fl_Image_Surface.H> #include "Fl_Xlib_Graphics_Driver.H" +#include <FL/Fl_Screen_Driver.H> class Fl_Xlib_Image_Surface_Driver : public Fl_Image_Surface_Driver { - friend class Fl_Image_Surface; virtual void end_current_(Fl_Surface_Device *next_current); public: Window pre_window; + int was_high; Fl_Xlib_Image_Surface_Driver(int w, int h, int high_res, Fl_Offscreen off); ~Fl_Xlib_Image_Surface_Driver(); void set_current(); @@ -44,11 +45,18 @@ Fl_Image_Surface_Driver *Fl_Image_Surface_Driver::newImageSurfaceDriver(int w, i } Fl_Xlib_Image_Surface_Driver::Fl_Xlib_Image_Surface_Driver(int w, int h, int high_res, Fl_Offscreen off) : Fl_Image_Surface_Driver(w, h, high_res, off) { + float d = 1; if (!off) { fl_open_display(); + d = fl_graphics_driver->scale(); + if (d != 1 && high_res) { + w = int(w*d); + h = int(h*d); + } offscreen = XCreatePixmap(fl_display, RootWindow(fl_display, fl_screen), w, h, fl_visual->depth); } driver(new Fl_Xlib_Graphics_Driver()); + if (d != 1 && high_res) ((Fl_Xlib_Graphics_Driver*)driver())->scale(d); } Fl_Xlib_Image_Surface_Driver::~Fl_Xlib_Image_Surface_Driver() { @@ -73,9 +81,7 @@ void Fl_Xlib_Image_Surface_Driver::untranslate() { Fl_RGB_Image* Fl_Xlib_Image_Surface_Driver::image() { - unsigned char *data = fl_read_image(NULL, 0, 0, width, height, 0); - Fl_RGB_Image *image = new Fl_RGB_Image(data, width, height); - image->alloc_array = 1; + Fl_RGB_Image *image = Fl::screen_driver()->read_win_rectangle(NULL, 0, 0, width, height, 0); return image; } |
