diff options
author | Scott Moreau <oreaus@gmail.com> | 2010-02-22 08:44:33 -0700 |
---|---|---|
committer | Scott Moreau <oreaus@gmail.com> | 2010-02-22 11:06:09 -0700 |
commit | 618676e2b02309fbe4af4214fe33de9b9428412b (patch) | |
tree | b8569f24847c5d06457947d3bea1fe26ecfd7d80 | |
parent | b93cac5d0c36f0d7b30e2d1a303859b547dc8586 (diff) | |
download | compiz-core-doc-618676e2b02309fbe4af4214fe33de9b9428412b.tar.gz compiz-core-doc-618676e2b02309fbe4af4214fe33de9b9428412b.tar.bz2 |
Add straight line drawing function.
-rw-r--r-- | plugins/annotate/annotate.xml.in | 13 | ||||
-rw-r--r-- | plugins/annotate/src/annotate.cpp | 163 | ||||
-rw-r--r-- | plugins/annotate/src/annotate.h | 22 |
3 files changed, 141 insertions, 57 deletions
diff --git a/plugins/annotate/annotate.xml.in b/plugins/annotate/annotate.xml.in index 84674cc..4eee3ab 100644 --- a/plugins/annotate/annotate.xml.in +++ b/plugins/annotate/annotate.xml.in @@ -9,15 +9,20 @@ </requirement> </deps> <options> - <option name="initiate_button" type="button"> - <_short>Initiate</_short> - <_long>Initiate annotate drawing</_long> + <option name="initiate_free_draw_button" type="button"> + <_short>Initiate Free Draw</_short> + <_long>Initiate freehand drawing</_long> <default><Super><Alt>Button1</default> </option> + <option name="initiate_line_button" type="button"> + <_short>Initiate Line</_short> + <_long>Initiate line drawing</_long> + <default><Super><Alt>Button2</default> + </option> <option name="initiate_rectangle_button" type="button"> <_short>Initiate Rectangle</_short> <_long>Initiate rectangle drawing</_long> - <default><Super><Alt>Button2</default> + <default><Super><Alt><Shift>Button1</default> </option> <option name="initiate_ellipse_button" type="button"> <_short>Initiate Ellipse</_short> diff --git a/plugins/annotate/src/annotate.cpp b/plugins/annotate/src/annotate.cpp index 5da7feb..1f1e852 100644 --- a/plugins/annotate/src/annotate.cpp +++ b/plugins/annotate/src/annotate.cpp @@ -383,33 +383,6 @@ AnnoScreen::draw (CompAction *action, } bool -AnnoScreen::initiate (CompAction *action, - CompAction::State state, - CompOption::Vector& options) -{ - if (screen->otherGrabExist (NULL)) - return false; - - if (!grabIndex) - grabIndex = screen->pushGrab (None, "annotate"); - - if (state & CompAction::StateInitButton) - action->setState (action->state () | CompAction::StateTermButton); - - if (state & CompAction::StateInitKey) - action->setState (action->state () | CompAction::StateTermKey); - - annoLastPointerX = pointerX; - annoLastPointerY = pointerY; - - drawMode = LineMode; - - screen->handleEventSetEnabled (this, true); - - return true; -} - -bool AnnoScreen::terminate (CompAction *action, CompAction::State state, CompOption::Vector& options) @@ -423,8 +396,16 @@ AnnoScreen::terminate (CompAction *action, action->setState (action->state () & ~(CompAction::StateTermKey | CompAction::StateTermButton)); - if (drawMode == RectangleMode) + switch (drawMode) { + case LineMode: + drawLine (initialPointerX, initialPointerY, + lineVector.x (), lineVector.y (), + optionGetLineWidth (), + optionGetStrokeColor ()); + break; + + case RectangleMode: drawRectangle (rectangle.x (), rectangle.y (), rectangle.width (), @@ -432,9 +413,9 @@ AnnoScreen::terminate (CompAction *action, optionGetFillColor (), optionGetStrokeColor (), optionGetStrokeWidth ()); - } - if (drawMode == EllipseMode) - { + break; + + case EllipseMode: drawEllipse (ellipse.center.x (), ellipse.center.y (), ellipse.radiusX, @@ -442,6 +423,10 @@ AnnoScreen::terminate (CompAction *action, optionGetFillColor (), optionGetStrokeColor (), optionGetStrokeWidth ()); + break; + + default: + break; } drawMode = NoMode; @@ -477,6 +462,60 @@ AnnoScreen::eraseInitiate (CompAction *action, } bool +AnnoScreen::initiateFreeDraw (CompAction *action, + CompAction::State state, + CompOption::Vector& options) +{ + if (screen->otherGrabExist (NULL)) + return false; + + if (!grabIndex) + grabIndex = screen->pushGrab (None, "annotate"); + + if (state & CompAction::StateInitButton) + action->setState (action->state () | CompAction::StateTermButton); + + if (state & CompAction::StateInitKey) + action->setState (action->state () | CompAction::StateTermKey); + + annoLastPointerX = pointerX; + annoLastPointerY = pointerY; + + drawMode = FreeDrawMode; + + screen->handleEventSetEnabled (this, true); + + return true; +} + +bool +AnnoScreen::initiateLine (CompAction *action, + CompAction::State state, + CompOption::Vector& options) +{ + if (screen->otherGrabExist (NULL)) + return false; + + if (!grabIndex) + grabIndex = screen->pushGrab (None, "annotate"); + + if (state & CompAction::StateInitButton) + action->setState (action->state () | CompAction::StateTermButton); + + if (state & CompAction::StateInitKey) + action->setState (action->state () | CompAction::StateTermKey); + + initialPointerX = pointerX; + initialPointerY = pointerY; + + drawMode = LineMode; + + screen->handleEventSetEnabled (this, true); + + return true; +} + +bool AnnoScreen::rectangleInitiate (CompAction *action, CompAction::State state, CompOption::Vector& options) @@ -575,6 +614,8 @@ AnnoScreen::glPaintOutput (const GLScreenPaintAttrib &attrib, GLMatrix sTransform = transform; int numRect; int pos = 0; + float vectorX, vectorY; + int angle; /* This replaced prepareXCoords (s, output, -DEFAULT_Z_CAMERA) */ sTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA); @@ -626,8 +667,18 @@ AnnoScreen::glPaintOutput (const GLScreenPaintAttrib &attrib, } } - if (drawMode == RectangleMode) + switch (drawMode) { + case LineMode: + glColor4usv (optionGetStrokeColor ()); + glLineWidth (optionGetLineWidth ()); + glBegin (GL_LINES); + glVertex2i (initialPointerX, initialPointerY); + glVertex2i (lineVector.x (), lineVector.y ()); + glEnd (); + break; + + case RectangleMode: /* fill rectangle */ glColor4usv (optionGetFillColor ()); glRecti (rectangle.x1 (), rectangle.y2 (), @@ -642,13 +693,9 @@ AnnoScreen::glPaintOutput (const GLScreenPaintAttrib &attrib, glVertex2i (rectangle.x2 (), rectangle.y2 ()); glVertex2i (rectangle.x1 (), rectangle.y2 ()); glEnd (); - } - - if (drawMode == EllipseMode) - { - float vectorX, vectorY; - int angle; + break; + case EllipseMode: /* fill ellipse */ glColor4usv (optionGetFillColor ()); @@ -684,6 +731,10 @@ AnnoScreen::glPaintOutput (const GLScreenPaintAttrib &attrib, glVertex2d (ellipse.center.x (), ellipse.center.y () + ellipse.radiusY); glEnd(); + break; + + default: + break; } /* clean up */ @@ -714,12 +765,24 @@ AnnoScreen::handleMotionEvent (int xRoot, xRoot, yRoot, 20.0, clearColor); break; - case LineMode: + + case FreeDrawMode: drawLine (annoLastPointerX, annoLastPointerY, xRoot, yRoot, optionGetLineWidth (), optionGetStrokeColor ()); break; + + case LineMode: + lineVector.setX (xRoot); + lineVector.setY (yRoot); + + damageRect.setGeometry (MIN(initialPointerX, lineVector.x ()), + MIN(initialPointerY, lineVector.y ()), + abs (lineVector.x () - initialPointerX), + abs (lineVector.y () - initialPointerY)); + break; + case RectangleMode: if ((xRoot < initialPointerX) && (yRoot < initialPointerY)) rectangle.setGeometry (xRoot, yRoot, @@ -740,6 +803,7 @@ AnnoScreen::handleMotionEvent (int xRoot, damageRect = rectangle; break; + case EllipseMode: ellipse.center.setX (initialPointerX + (xRoot - initialPointerX) / 2); @@ -754,11 +818,14 @@ AnnoScreen::handleMotionEvent (int xRoot, ellipse.radiusX * 2, ellipse.radiusY * 2); break; + default: break; } - if (cScreen && (drawMode == EllipseMode || drawMode == RectangleMode)) + if (cScreen && (drawMode == LineMode || + drawMode == RectangleMode || + drawMode == EllipseMode)) { /* Add border width to the damage region */ damageRect.setGeometry (damageRect.x () - optionGetStrokeWidth (), @@ -815,14 +882,20 @@ AnnoScreen::AnnoScreen (CompScreen *screen) : ScreenInterface::setHandler (screen, false); GLScreenInterface::setHandler (gScreen, false); - optionSetInitiateButtonInitiate - (boost::bind (&AnnoScreen::initiate, this, _1, _2, _3)); - optionSetInitiateButtonTerminate - (boost::bind (&AnnoScreen::terminate, this, _1, _2, _3)); + optionSetDrawInitiate + (boost::bind (&AnnoScreen::draw, this, _1, _2, _3)); optionSetEraseButtonInitiate (boost::bind (&AnnoScreen::eraseInitiate, this, _1, _2, _3)); optionSetEraseButtonTerminate (boost::bind (&AnnoScreen::terminate, this, _1, _2, _3)); + optionSetInitiateFreeDrawButtonInitiate + (boost::bind (&AnnoScreen::initiateFreeDraw, this, _1, _2, _3)); + optionSetInitiateFreeDrawButtonTerminate + (boost::bind (&AnnoScreen::terminate, this, _1, _2, _3)); + optionSetInitiateLineButtonInitiate + (boost::bind (&AnnoScreen::initiateLine, this, _1, _2, _3)); + optionSetInitiateLineButtonTerminate + (boost::bind (&AnnoScreen::terminate, this, _1, _2, _3)); optionSetInitiateRectangleButtonInitiate (boost::bind (&AnnoScreen::rectangleInitiate, this, _1, _2, _3)); optionSetInitiateRectangleButtonTerminate @@ -833,8 +906,6 @@ AnnoScreen::AnnoScreen (CompScreen *screen) : (boost::bind (&AnnoScreen::terminate, this, _1, _2, _3)); optionSetClearKeyInitiate (boost::bind (&AnnoScreen::clear, this, _1, _2, _3)); - optionSetDrawInitiate - (boost::bind (&AnnoScreen::draw, this, _1, _2, _3)); drawMode = NoMode; } diff --git a/plugins/annotate/src/annotate.h b/plugins/annotate/src/annotate.h index 0bafc7f..43d4e65 100644 --- a/plugins/annotate/src/annotate.h +++ b/plugins/annotate/src/annotate.h @@ -34,6 +34,8 @@ static int annoLastPointerX = 0; static int annoLastPointerY = 0; +static int initialPointerX = 0; +static int initialPointerY = 0; typedef struct _Ellipse { @@ -46,6 +48,7 @@ enum DrawMode { NoMode = 0, EraseMode, + FreeDrawMode, LineMode, RectangleMode, EllipseMode, @@ -74,11 +77,11 @@ class AnnoScreen : bool content; Damage damage; - int initialPointerX, initialPointerY; CompRect rectangle, lastRect; DrawMode drawMode; - Ellipse ellipse; + CompPoint lineVector; + Ellipse ellipse; void handleEvent (XEvent *); @@ -142,11 +145,6 @@ class AnnoScreen : CompOption::Vector& options); bool - initiate (CompAction *action, - CompAction::State state, - CompOption::Vector& options); - - bool terminate (CompAction *action, CompAction::State state, CompOption::Vector& options); @@ -157,6 +155,16 @@ class AnnoScreen : CompOption::Vector& options); bool + initiateFreeDraw (CompAction *action, + CompAction::State state, + CompOption::Vector& options); + + bool + initiateLine (CompAction *action, + CompAction::State state, + CompOption::Vector& options); + + bool rectangleInitiate (CompAction *action, CompAction::State state, CompOption::Vector& options); |