summaryrefslogtreecommitdiff
path: root/FL
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2011-02-04 23:32:53 +0000
committerManolo Gouy <Manolo>2011-02-04 23:32:53 +0000
commit668dfd109f183ad8c4731f7fb8af39977ea89920 (patch)
treef0f1ef1ca07aeb68c97689537355f1300d4ce511 /FL
parent31bbbf7ae60f07d5f87454db0be9e27eea676ded (diff)
Fix STR #2535: clipping + coordinate transformations are now managed separately for each
surface device. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8368 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'FL')
-rw-r--r--FL/Fl_Device.H79
-rw-r--r--FL/fl_draw.H50
-rw-r--r--FL/win32.H2
3 files changed, 118 insertions, 13 deletions
diff --git a/FL/Fl_Device.H b/FL/Fl_Device.H
index bc757ee2e..c51e99c1d 100644
--- a/FL/Fl_Device.H
+++ b/FL/Fl_Device.H
@@ -33,6 +33,7 @@
#ifndef Fl_Device_H
#define Fl_Device_H
+#include <FL/x.H>
#include <FL/Fl_Plugin.H>
#include <FL/Fl_Image.H>
#include <FL/Fl_Bitmap.H>
@@ -53,6 +54,27 @@ FL_EXPORT extern Fl_Graphics_Driver *fl_graphics_driver;
*/
typedef void (*Fl_Draw_Image_Cb)(void* data,int x,int y,int w,uchar* buf);
+#define REGION_STACK_SIZE 10
+#define REGION_STACK_MAX (REGION_STACK_SIZE - 1)
+
+#define MATRIX_STACK_SIZE 32
+#define MATRIX_STACK_MAX (MATRIX_STACK_SIZE - 1)
+struct matrix {double a, b, c, d, x, y;};
+
+// typedef what the x,y fields in a point are:
+#ifdef WIN32
+typedef int COORD_T;
+# define XPOINT XPoint
+#elif defined(__APPLE__)
+typedef float COORD_T;
+typedef struct { float x; float y; } QPoint;
+# define XPOINT QPoint
+extern float fl_quartz_line_width_;
+#else
+typedef short COORD_T;
+# define XPOINT XPoint
+#endif
+
/**
\brief All graphical output devices and all graphics systems.
*/
@@ -88,6 +110,23 @@ public:
in the \ref fl_drawings and \ref fl_attributes modules.
*/
class FL_EXPORT Fl_Graphics_Driver : public Fl_Device {
+ enum {LINE, LOOP, POLYGON, POINT_};
+ int sptr;
+ matrix stack[MATRIX_STACK_SIZE];
+ matrix m;
+ int n, p_size, gap_;
+ XPOINT *p;
+ int what;
+ int fl_clip_state_number;
+ int rstackptr;
+ Fl_Region rstack[REGION_STACK_MAX];
+#ifdef WIN32
+ int numcount;
+ int counts[20];
+#endif
+ void transformed_vertex0(COORD_T x, COORD_T y);
+ void fixloop();
+
protected:
/* ** \brief red color for background and/or mixing if device does not support masking or alpha *
uchar bg_r_;
@@ -143,13 +182,27 @@ protected:
friend void fl_begin_complex_polygon();
friend void fl_gap();
friend void fl_end_complex_polygon();
+ friend void fl_push_matrix();
+ friend void fl_pop_matrix();
+ friend void fl_mult_matrix(double a, double b, double c, double d, double x, double y);
+ friend double fl_transform_x(double x, double y);
+ friend double fl_transform_y(double x, double y);
+ friend double fl_transform_dx(double x, double y);
+ friend double fl_transform_dy(double x, double y);
+ friend Fl_Region fl_clip_region();
+ friend void fl_clip_region(Fl_Region r);
+ friend void fl_restore_clip();
+
friend void fl_draw_image(const uchar* buf, int X,int Y,int W,int H, int D, int L);
friend void fl_draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D, int L);
friend void fl_draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D);
friend FL_EXPORT void fl_draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D);
-
+ friend void gl_start();
+
+ matrix *fl_matrix;
+
/** \brief The constructor. */
- Fl_Graphics_Driver() {};
+ Fl_Graphics_Driver();
/** \brief see fl_rect(int x, int y, int w, int h). */
virtual void rect(int x, int y, int w, int h);
/** \brief see fl_rectf(int x, int y, int w, int h). */
@@ -238,6 +291,28 @@ protected:
virtual void push_no_clip();
/** \brief see fl_pop_clip(). */
virtual void pop_clip();
+
+ /** \brief see fl_push_matrix(). */
+ void push_matrix();
+ /** \brief see fl_pop_matrix(). */
+ void pop_matrix();
+ /** \brief see fl_mult_matrix(double a, double b, double c, double d, double x, double y). */
+ void mult_matrix(double a, double b, double c, double d, double x, double y);
+ /** \brief see fl_transform_x(double x, double y). */
+ double transform_x(double x, double y);
+ /** \brief see fl_transform_y(double x, double y). */
+ double transform_y(double x, double y);
+ /** \brief see fl_transform_dx(double x, double y). */
+ double transform_dx(double x, double y);
+ /** \brief see fl_transform_dy(double x, double y). */
+ double transform_dy(double x, double y);
+ /** \brief see fl_clip_region(). */
+ Fl_Region clip_region();
+ /** \brief see fl_clip_region(Fl_Region r). */
+ void clip_region(Fl_Region r);
+ /** \brief see fl_restore_clip(). */
+ void restore_clip();
+
// Images
/** \brief see fl_draw_image(const uchar* buf, int X,int Y,int W,int H, int D, int L). */
virtual void draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0) = 0;
diff --git a/FL/fl_draw.H b/FL/fl_draw.H
index 3413af1c0..a17737d3f 100644
--- a/FL/fl_draw.H
+++ b/FL/fl_draw.H
@@ -133,18 +133,18 @@ inline int fl_not_clipped(int x, int y, int w, int h) {return fl_graphics_driver
inline int fl_clip_box(int x , int y, int w, int h, int& X, int& Y, int& W, int& H)
{return fl_graphics_driver->clip_box(x,y,w,h,X,Y,W,H); }
/** Undoes any clobbering of clip done by your program */
-extern void fl_restore_clip();
+inline void fl_restore_clip() { fl_graphics_driver->restore_clip(); };
/**
Replaces the top of the clipping stack with a clipping region of any shape.
Fl_Region is an operating system specific type.
\param[in] r clipping region
*/
-FL_EXPORT void fl_clip_region(Fl_Region r);
+inline void fl_clip_region(Fl_Region r) { fl_graphics_driver->clip_region(r); };
/**
returns the current clipping region.
*/
-extern Fl_Region fl_clip_region();
+inline Fl_Region fl_clip_region() { return fl_graphics_driver->clip_region(); };
// points:
@@ -326,13 +326,27 @@ inline void fl_pie(int x, int y, int w, int h, double a1, double a2) {fl_graphic
FL_EXPORT void fl_chord(int x, int y, int w, int h, double a1, double a2); // nyi
// scalable drawing code (code in fl_vertex.C and fl_arc.C):
-FL_EXPORT void fl_push_matrix();
-FL_EXPORT void fl_pop_matrix();
+/**
+ Saves the current transformation matrix on the stack.
+ The maximum depth of the stack is 4.
+ */
+inline void fl_push_matrix() { fl_graphics_driver->push_matrix(); };
+/**
+ Restores the current transformation matrix from the stack.
+ */
+inline void fl_pop_matrix() { fl_graphics_driver->pop_matrix(); };
FL_EXPORT void fl_scale(double x, double y);
FL_EXPORT void fl_scale(double x);
FL_EXPORT void fl_translate(double x, double y);
FL_EXPORT void fl_rotate(double d);
-FL_EXPORT void fl_mult_matrix(double a, double b, double c, double d, double x,double y);
+/**
+ Concatenates another transformation onto the current one.
+
+ \param[in] a,b,c,d,x,y transformation matrix elements such that
+ <tt> X' = aX + cY + x </tt> and <tt> Y' = bX +dY + y </tt>
+ */
+inline void fl_mult_matrix(double a, double b, double c, double d, double x,double y)
+ { fl_graphics_driver->mult_matrix(a, b, c, d, x, y); };
/**
Starts drawing a list of points. Points are added to the list with fl_vertex()
*/
@@ -424,10 +438,26 @@ inline void fl_gap() {fl_graphics_driver->gap(); }
*/
inline void fl_end_complex_polygon() {fl_graphics_driver->end_complex_polygon(); }
// get and use transformed positions:
-FL_EXPORT double fl_transform_x(double x, double y);
-FL_EXPORT double fl_transform_y(double x, double y);
-FL_EXPORT double fl_transform_dx(double x, double y);
-FL_EXPORT double fl_transform_dy(double x, double y);
+/**
+ Transforms coordinate using the current transformation matrix.
+ \param[in] x,y coordinate
+ */
+inline double fl_transform_x(double x, double y) {return fl_graphics_driver->transform_x(x, y); };
+/**
+ Transform coordinate using the current transformation matrix.
+ \param[in] x,y coordinate
+ */
+inline double fl_transform_y(double x, double y) {return fl_graphics_driver->transform_y(x, y); };
+/**
+ Transforms distance using current transformation matrix.
+ \param[in] x,y coordinate
+ */
+inline double fl_transform_dx(double x, double y) {return fl_graphics_driver->transform_dx(x, y); };
+/**
+ Transforms distance using current transformation matrix.
+ \param[in] x,y coordinate
+ */
+inline double fl_transform_dy(double x, double y) {return fl_graphics_driver->transform_dy(x, y); };
/**
Adds coordinate pair to the vertex list without further transformations.
\param[in] xf,yf transformed coordinate
diff --git a/FL/win32.H b/FL/win32.H
index ac484db6b..702299b17 100644
--- a/FL/win32.H
+++ b/FL/win32.H
@@ -37,6 +37,7 @@
#include <windows.h>
typedef HRGN Fl_Region;
typedef HWND Window;
+typedef POINT XPoint;
// this part is included only when compiling the FLTK library or if requested explicitly
#if defined(FL_LIBRARY) || defined(FL_INTERNALS)
@@ -52,7 +53,6 @@ typedef HWND Window;
#endif
// some random X equivalents
-typedef POINT XPoint;
struct XRectangle {int x, y, width, height;};
extern Fl_Region XRectangleRegion(int x, int y, int w, int h);
inline void XDestroyRegion(Fl_Region r) {DeleteObject(r);}