00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef DRAW_H
00010 #define DRAW_H
00011
00012 #include <set>
00013
00014 #include "command.h"
00015
00019 enum EDrawTool {
00020 TOOL_NOTOOL = 0,
00021 TOOL_BRUSH,
00022 TOOL_RUBBER,
00023 TOOL_LINE,
00024 TOOL_RECT,
00025 TOOL_CIRCLE,
00026 TOOL_ELLIPSE,
00027 TOOL_TEXT,
00028 TOOL_SELECT
00029 };
00031 enum { iDrawToolCnt = 9 };
00032
00036 struct DrawContext {
00037 EDrawTool tool;
00038 int fgBrushWidth;
00039 int bgBrushWidth;
00040 Pixel fgColor;
00041 Pixel bgColor;
00042
00048 static const char *toolLabel (EDrawTool et);
00049
00055 static EDrawTool toolByLabel (const char *szLabel);
00056
00063 DrawContext (EDrawTool initTool, int initFgBrushWidht, int initBgBrushWidth):
00064 tool(initTool), fgBrushWidth (initFgBrushWidht), bgBrushWidth(initBgBrushWidth)
00065 {
00066 fgColor.red = 0;
00067 fgColor.green = 0;
00068 fgColor.blue = 0;
00069 fgColor.alpha = 0xFF;
00070
00071 bgColor.red = 0xFF;
00072 bgColor.green = 0xFF;
00073 bgColor.blue = 0xFF;
00074 bgColor.alpha = 0xFF;
00075 }
00076 };
00077
00083 class BrushCmd: public SlowUndoSelectCmd {
00084 public:
00091 BrushCmd (FrameBuffer *pFB, const DrawContext &dc, bool bBack=false);
00092
00097 void add (Point p);
00098
00099 virtual void exec ();
00100 virtual std::string name () { return szCmdName; }
00101 virtual std::string args ();
00102
00108 BrushCmd (FrameBuffer *pFB, const std::string &args);
00109
00110 static const char *const szCmdName;
00111
00112 private:
00113 int _iBrushWidth;
00114 Pixel _brushColor;
00115 std::set<int> _pixSet;
00116 };
00117
00123 class PlacementCmd: public SlowUndoSelectCmd {
00124 public:
00125 virtual std::string args ();
00126
00127 protected:
00135 PlacementCmd (FrameBuffer *pFB, Rect &placement, DrawContext &dc, bool bBack);
00136
00142 PlacementCmd (FrameBuffer *pFB, const std::string &args);
00143
00148 void impressBrush (Point pos);
00149
00150
00151
00152
00153 int _iBrushWidth;
00154 Pixel _brushColor;
00155 Rect _place;
00156 };
00157
00162 class LineCmd: public PlacementCmd {
00163 public:
00171 LineCmd (FrameBuffer *pFB, Rect placement, DrawContext dc, bool bBack=false):
00172 PlacementCmd (pFB, placement, dc, bBack) { }
00173
00174 virtual void exec ();
00175 virtual std::string name () { return szCmdName; }
00176 static const char *const szCmdName;
00177
00183 LineCmd (FrameBuffer *pFB, const std::string &args):
00184 PlacementCmd (pFB, args) { }
00185 };
00186
00191 class RectCmd: public PlacementCmd {
00192 public:
00200 RectCmd (FrameBuffer *pFB, Rect placement, DrawContext dc, bool bBack=false):
00201 PlacementCmd (pFB, placement, dc, bBack) { }
00202
00203 virtual void exec ();
00204 virtual std::string name () { return szCmdName; }
00205 static const char *const szCmdName;
00206
00212 RectCmd (FrameBuffer *pFB, const std::string &args):
00213 PlacementCmd (pFB, args) { }
00214 };
00215
00220 class CircleCmd: public PlacementCmd {
00221 public:
00229 CircleCmd (FrameBuffer *pFB, Rect placement, DrawContext dc, bool bBack=false):
00230 PlacementCmd (pFB, placement, dc, bBack) { init(); }
00231
00232 virtual void exec ();
00233 virtual std::string name () { return szCmdName; }
00234 static const char *const szCmdName;
00235
00241 CircleCmd (FrameBuffer *pFB, const std::string &args):
00242 PlacementCmd (pFB, args) { init(); }
00243
00244 private:
00245 void drawCirclePoints (int x, int y);
00246
00247 int _iRadius;
00248 int _iCenterX;
00249 int _iCenterY;
00250
00251 void init () {
00252 _iRadius = (_place.size.width - _iBrushWidth) >> 1;
00253 _iCenterX = _place.at.x + _iRadius;
00254 _iCenterY = _place.at.y + _iRadius;
00255 }
00256 };
00257
00262 class EllipseCmd: public PlacementCmd {
00263 public:
00271 EllipseCmd (FrameBuffer *pFB, Rect placement, DrawContext dc, bool bBack=false):
00272 PlacementCmd (pFB, placement, dc, bBack) { init(); }
00273
00274 virtual void exec ();
00275 virtual std::string name () { return szCmdName; }
00276 static const char *const szCmdName;
00277
00283 EllipseCmd (FrameBuffer *pFB, const std::string &args):
00284 PlacementCmd (pFB, args) { init(); }
00285
00286 private:
00287 void drawEllipsePoints (int x, int y);
00288
00289 int _iHalfAxisA, _iHalfAxisB;
00290 int _iCenterX, _iCenterY;
00291
00292 void init () {
00293 _iHalfAxisA = (_place.size.width - _iBrushWidth) >> 1;
00294 _iHalfAxisB = (_place.size.height- _iBrushWidth) >> 1;
00295 _iCenterX = _place.at.x + _iHalfAxisA;
00296 _iCenterY = _place.at.y + _iHalfAxisB;
00297 }
00298 };
00299
00304 class TextCmd: public SlowUndoSelectCmd {
00305 public:
00313 TextCmd (FrameBuffer *pFB, DrawContext dc, Point position, const char *szText);
00314
00315 virtual void exec ();
00316 virtual std::string name () { return szCmdName; }
00317 virtual std::string args ();
00318
00324 TextCmd (FrameBuffer *pFB, const std::string &args);
00325
00331 class ErrFreeType { };
00332
00333 static const char *const szCmdName;
00334
00335 private:
00336 void init ();
00337
00338 int _iSize;
00339 int _iDpi;
00340 Pixel _fgColor;
00341 Pixel _bgColor;
00342 Point _pos;
00343 std::string _fontFile;
00344 std::string _strText;
00345 };
00346
00351 class SelectCmd: public Cmd {
00352 public:
00357 SelectCmd (FrameBuffer *pFB);
00358
00364 SelectCmd (FrameBuffer *pFB, const Rect &sel);
00365
00366 virtual void exec ();
00367 virtual void unExec ();
00368 virtual std::string name () { return szCmdName; }
00369 virtual std::string args ();
00370
00376 SelectCmd (FrameBuffer *pFB, const std::string &args);
00377
00378 static const char *const szCmdName;
00379
00380 private:
00381 Rect _newSel;
00382 Rect _oldSel;
00383 };
00384
00385 class GrayScaleCmd: public SlowUndoSelectCmd {
00386 public:
00391 GrayScaleCmd (FrameBuffer *pFB):
00392 SlowUndoSelectCmd (pFB)
00393 {
00394 }
00395
00396 virtual void exec ();
00397 virtual std::string name () { return szCmdName; }
00398 virtual std::string args () { return std::string(); }
00399
00404 GrayScaleCmd (FrameBuffer *pFB, const std::string &):
00405 SlowUndoSelectCmd (pFB)
00406 {
00407 }
00408
00409 static const char *const szCmdName;
00410 };
00411
00412 class InvertCmd: public SlowUndoSelectCmd {
00413 public:
00418 InvertCmd (FrameBuffer *pFB):
00419 SlowUndoSelectCmd (pFB)
00420 {
00421 }
00422
00423 virtual void exec ();
00424 virtual std::string name () { return szCmdName; }
00425 virtual std::string args () { return std::string(); }
00426
00431 InvertCmd (FrameBuffer *pFB, const std::string &):
00432 SlowUndoSelectCmd (pFB)
00433 {
00434 }
00435
00436 static const char *const szCmdName;
00437 };
00438
00439 #endif // DRAW_H