00001 #ifndef __DW_FLTKVIEWBASE_HH__
00002 #define __DW_FLTKVIEWBASE_HH__
00003
00004 #include <time.h>
00005 #include <sys/time.h>
00006
00007 #include <FL/Fl_Group.H>
00008 #include <FL/x.H>
00009
00010 #include "fltkcore.hh"
00011
00012 namespace dw {
00013 namespace fltk {
00014
00015 class FltkViewBase: public FltkView, public Fl_Group
00016 {
00017 private:
00018 class BackBuffer {
00019 private:
00020 int w;
00021 int h;
00022 bool created;
00023
00024 public:
00025 Fl_Offscreen offscreen;
00026
00027 BackBuffer ();
00028 ~BackBuffer ();
00029 void setSize(int w, int h);
00030 };
00031
00032 typedef enum { DRAW_PLAIN, DRAW_CLIPPED, DRAW_BUFFERED } DrawType;
00033
00034 int bgColor;
00035 core::Region drawRegion;
00036 core::Rectangle *exposeArea;
00037 static BackBuffer *backBuffer;
00038 static bool backBufferInUse;
00039
00040 void draw (const core::Rectangle *rect, DrawType type);
00041 void drawChildWidgets ();
00042 inline void clipPoint (int *x, int *y, int border) {
00043 if (exposeArea) {
00044 if (*x < exposeArea->x - border)
00045 *x = exposeArea->x - border;
00046 if (*x > exposeArea->x + exposeArea->width + border)
00047 *x = exposeArea->x + exposeArea->width + border;
00048 if (*y < exposeArea->y - border)
00049 *y = exposeArea->y - border;
00050 if (*y > exposeArea->y + exposeArea->height + border)
00051 *y = exposeArea->y + exposeArea->height + border;
00052 }
00053 }
00054 protected:
00055 core::Layout *theLayout;
00056 int canvasWidth, canvasHeight;
00057 int mouse_x, mouse_y;
00058 Fl_Widget *focused_child;
00059
00060 virtual int translateViewXToCanvasX (int x) = 0;
00061 virtual int translateViewYToCanvasY (int y) = 0;
00062 virtual int translateCanvasXToViewX (int x) = 0;
00063 virtual int translateCanvasYToViewY (int y) = 0;
00064
00065 public:
00066 FltkViewBase (int x, int y, int w, int h, const char *label = 0);
00067 ~FltkViewBase ();
00068
00069 void draw();
00070 int handle (int event);
00071
00072 void setLayout (core::Layout *layout);
00073 void setCanvasSize (int width, int ascent, int descent);
00074 void setCursor (core::style::Cursor cursor);
00075 void setBgColor (core::style::Color *color);
00076
00077 void startDrawing (core::Rectangle *area);
00078 void finishDrawing (core::Rectangle *area);
00079 void queueDraw (core::Rectangle *area);
00080 void queueDrawTotal ();
00081 void cancelQueueDraw ();
00082 void drawPoint (core::style::Color *color,
00083 core::style::Color::Shading shading,
00084 int x, int y);
00085 void drawLine (core::style::Color *color,
00086 core::style::Color::Shading shading,
00087 int x1, int y1, int x2, int y2);
00088 void drawTypedLine (core::style::Color *color,
00089 core::style::Color::Shading shading,
00090 core::style::LineType type, int width,
00091 int x1, int y1, int x2, int y2);
00092 void drawRectangle (core::style::Color *color,
00093 core::style::Color::Shading shading, bool filled,
00094 int x, int y, int width, int height);
00095 void drawArc (core::style::Color *color,
00096 core::style::Color::Shading shading, bool filled,
00097 int centerX, int centerY, int width, int height,
00098 int angle1, int angle2);
00099 void drawPolygon (core::style::Color *color,
00100 core::style::Color::Shading shading,
00101 bool filled, bool convex,
00102 core::Point *points, int npoints);
00103
00104 core::View *getClippingView (int x, int y, int width, int height);
00105 void mergeClippingView (core::View *clippingView);
00106 void setBufferedDrawing (bool b);
00107 };
00108
00109
00110 class FltkWidgetView: public FltkViewBase
00111 {
00112 public:
00113 FltkWidgetView (int x, int y, int w, int h, const char *label = 0);
00114 ~FltkWidgetView ();
00115
00116 void drawText (core::style::Font *font,
00117 core::style::Color *color,
00118 core::style::Color::Shading shading,
00119 int x, int y, const char *text, int len);
00120 void drawSimpleWrappedText (core::style::Font *font,
00121 core::style::Color *color,
00122 core::style::Color::Shading shading,
00123 int x, int y, int w, int h,
00124 const char *text);
00125 void drawImage (core::Imgbuf *imgbuf, int xRoot, int yRoot,
00126 int x, int y, int width, int height);
00127
00128 bool usesFltkWidgets ();
00129 void addFltkWidget (Fl_Widget *widget, core::Allocation *allocation);
00130 void removeFltkWidget (Fl_Widget *widget);
00131 void allocateFltkWidget (Fl_Widget *widget,
00132 core::Allocation *allocation);
00133 void drawFltkWidget (Fl_Widget *widget, core::Rectangle *area);
00134 };
00135
00136 }
00137 }
00138
00139 #endif // __DW_FLTKVIEWBASE_HH__
00140