Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CEGUIFrameWindow.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002         filename:       CEGUIFrameWindow.cpp
00003         created:        13/4/2004
00004         author:         Paul D Turner
00005         
00006         purpose:        Implementation of FrameWindow base class
00007 *************************************************************************/
00008 /*************************************************************************
00009     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00010     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00011 
00012     This library is free software; you can redistribute it and/or
00013     modify it under the terms of the GNU Lesser General Public
00014     License as published by the Free Software Foundation; either
00015     version 2.1 of the License, or (at your option) any later version.
00016 
00017     This library is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020     Lesser General Public License for more details.
00021 
00022     You should have received a copy of the GNU Lesser General Public
00023     License along with this library; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 *************************************************************************/
00026 #include "elements/CEGUIFrameWindow.h"
00027 #include "elements/CEGUITitlebar.h"
00028 #include "elements/CEGUIPushButton.h"
00029 #include "CEGUIMouseCursor.h"
00030 #include "CEGUIWindowManager.h"
00031 #include "CEGUIExceptions.h"
00032 #include "CEGUIImagesetManager.h"
00033 #include "CEGUIImageset.h"
00034 
00035 // Start of CEGUI namespace section
00036 namespace CEGUI
00037 {
00038 const String FrameWindow::EventNamespace("FrameWindow");
00039 
00040 /*************************************************************************
00041         Definitions for Properties
00042 *************************************************************************/
00043 FrameWindowProperties::SizingEnabled                    FrameWindow::d_sizingEnabledProperty;
00044 FrameWindowProperties::FrameEnabled                             FrameWindow::d_frameEnabledProperty;
00045 FrameWindowProperties::TitlebarEnabled                  FrameWindow::d_titlebarEnabledProperty;
00046 FrameWindowProperties::CloseButtonEnabled               FrameWindow::d_closeButtonEnabledProperty;
00047 FrameWindowProperties::RollUpState                              FrameWindow::d_rollUpStateProperty;
00048 FrameWindowProperties::RollUpEnabled                    FrameWindow::d_rollUpEnabledProperty;
00049 FrameWindowProperties::DragMovingEnabled                FrameWindow::d_dragMovingEnabledProperty;
00050 FrameWindowProperties::SizingBorderThickness    FrameWindow::d_sizingBorderThicknessProperty;
00051 FrameWindowProperties::TitlebarFont                             FrameWindow::d_titlebarFontProperty;
00052 FrameWindowProperties::CaptionColour                    FrameWindow::d_captionColourProperty;
00053 FrameWindowProperties::NSSizingCursorImage      FrameWindow::d_nsSizingCursorProperty;
00054 FrameWindowProperties::EWSizingCursorImage      FrameWindow::d_ewSizingCursorProperty;
00055 FrameWindowProperties::NWSESizingCursorImage    FrameWindow::d_nwseSizingCursorProperty;
00056 FrameWindowProperties::NESWSizingCursorImage    FrameWindow::d_neswSizingCursorProperty;
00057 
00058 
00059 /*************************************************************************
00060         Constants
00061 *************************************************************************/
00062 // additional event names for this window
00063 const String FrameWindow::EventRollupToggled( (utf8*)"RollupToggled" );
00064 const String FrameWindow::EventCloseClicked( (utf8*)"CloseClicked" );
00065 
00066 // other bits
00067 const float FrameWindow::DefaultSizingBorderSize        = 8.0f;
00068 
00069 
00070 /*************************************************************************
00071         Constructor
00072 *************************************************************************/
00073 FrameWindow::FrameWindow(const String& type, const String& name) :
00074         Window(type, name)
00075 {
00076         d_frameEnabled          = true;
00077         d_rollupEnabled         = true;
00078         d_rolledup                      = false;
00079         d_sizingEnabled         = true;
00080         d_beingSized            = false;
00081         d_dragMovable           = true;
00082 
00083         d_borderSize            = DefaultSizingBorderSize;
00084 
00085         d_nsSizingCursor = d_ewSizingCursor = d_neswSizingCursor = d_nwseSizingCursor = NULL;
00086 
00087         addFrameWindowEvents();
00088         addFrameWindowProperties();
00089 }
00090 
00091 
00092 /*************************************************************************
00093         Destructor
00094 *************************************************************************/
00095 FrameWindow::~FrameWindow(void)
00096 {
00097 }
00098 
00099 
00100 /*************************************************************************
00101         Initialises the Window based object ready for use.
00102 *************************************************************************/
00103 void FrameWindow::initialise(void)
00104 {
00105         // create child windows
00106         d_titlebar              = createTitlebar(getName() + "__auto_titlebar__");
00107         d_closeButton   = createCloseButton(getName() + "__auto_closebutton__");
00108 
00109         // add child controls
00110         if (d_titlebar != NULL)
00111         {
00112                 d_titlebar->setDraggingEnabled(d_dragMovable);
00113                 addChildWindow(d_titlebar);
00114         }
00115 
00116         if (d_closeButton != NULL)
00117         {
00118                 addChildWindow(d_closeButton);
00119 
00120                 // bind handler to close button 'Click' event
00121                 d_closeButton->subscribeEvent(PushButton::EventClicked, Event::Subscriber(&CEGUI::FrameWindow::closeClickHandler, this));
00122         }
00123 
00124         performChildWindowLayout();
00125 }
00126 
00127 
00128 /*************************************************************************
00129         Enables or disables sizing for this window.     
00130 *************************************************************************/
00131 void FrameWindow::setSizingEnabled(bool setting)
00132 {
00133         d_sizingEnabled = setting;
00134 }
00135 
00136 
00137 /*************************************************************************
00138         Enables or disables the frame for this window.  
00139 *************************************************************************/
00140 void FrameWindow::setFrameEnabled(bool setting)
00141 {
00142         d_frameEnabled = setting;
00143         requestRedraw();
00144 }
00145 
00146 
00147 /*************************************************************************
00148         Enables or disables the title bar for the frame window. 
00149 *************************************************************************/
00150 void FrameWindow::setTitleBarEnabled(bool setting)
00151 {
00152     try
00153     {
00154         Window* titlebar = WindowManager::getSingleton().getWindow(getName() + "__auto_titlebar__");
00155         titlebar->setEnabled(setting);
00156         titlebar->setVisible(setting);
00157     }
00158     catch (UnknownObjectException)
00159     {}
00160 }
00161 
00162 
00163 /*************************************************************************
00164         Enables or disables the close button for the frame window.      
00165 *************************************************************************/
00166 void FrameWindow::setCloseButtonEnabled(bool setting)
00167 {
00168     try
00169     {
00170         Window* closebtn = WindowManager::getSingleton().getWindow(getName() + "__auto_closebutton__");
00171         closebtn->setEnabled(setting);
00172         closebtn->setVisible(setting);
00173     }
00174     catch (UnknownObjectException)
00175     {}
00176 }
00177 
00178 
00179 /*************************************************************************
00180         Enables or disables roll-up (shading) for this window.  
00181 *************************************************************************/
00182 void FrameWindow::setRollupEnabled(bool setting)
00183 {
00184         if ((setting == false) && isRolledup())
00185         {
00186                 toggleRollup();
00187         }
00188 
00189         d_rollupEnabled = setting;
00190 }
00191 
00192 
00193 /*************************************************************************
00194         Toggles the state of the window between rolled-up (shaded) and normal
00195         sizes.  This requires roll-up to be enabled.    
00196 *************************************************************************/
00197 void FrameWindow::toggleRollup(void)
00198 {
00199     if (isRollupEnabled())
00200     {
00201         d_rolledup ^= true;
00202         
00203         // event notification.
00204         WindowEventArgs args(this);
00205         onRollupToggled(args);
00206     }
00207 
00208 }
00209 
00210 
00211 /*************************************************************************
00212         Set the font to use for the title bar text      
00213 *************************************************************************/
00214 void FrameWindow::setTitlebarFont(const String& name)
00215 {
00216     try
00217     {
00218         WindowManager::getSingleton().getWindow(getName() + "__auto_titlebar__")->setFont(name);
00219     }
00220     catch (UnknownObjectException)
00221     {}
00222 }
00223 
00224 
00225 /*************************************************************************
00226         Set the font to use for the title bar text      
00227 *************************************************************************/
00228 void FrameWindow::setTitlebarFont(Font* font)
00229 {
00230     try
00231     {
00232         WindowManager::getSingleton().getWindow(getName() + "__auto_titlebar__")->setFont(font);
00233     }
00234     catch (UnknownObjectException)
00235     {}
00236 }
00237 
00238 
00239 /*************************************************************************
00240         Move the window by the pixel offsets specified in 'offset'.     
00241 *************************************************************************/
00242 void FrameWindow::offsetPixelPosition(const Vector2& offset)
00243 {
00244     UVector2 uOffset;
00245 
00246     if (getMetricsMode() == Relative)
00247     {
00248         Size sz = getParentSize();
00249 
00250         uOffset.d_x = cegui_reldim((sz.d_width != 0) ? offset.d_x / sz.d_width : 0);
00251         uOffset.d_y = cegui_reldim((sz.d_height != 0) ? offset.d_y / sz.d_height : 0);
00252     }
00253     else
00254     {
00255         uOffset.d_x = cegui_absdim(PixelAligned(offset.d_x));
00256         uOffset.d_y = cegui_absdim(PixelAligned(offset.d_y));
00257     }
00258 
00259     setWindowPosition(d_area.getPosition() + uOffset);
00260 }
00261 
00262 
00263 /*************************************************************************      
00264         check local pixel co-ordinate point 'pt' and return one of the
00265         SizingLocation enumerated values depending where the point falls on
00266         the sizing border.
00267 *************************************************************************/
00268 FrameWindow::SizingLocation FrameWindow::getSizingBorderAtPoint(const Point& pt) const
00269 {
00270         Rect    frame(getSizingRect());
00271 
00272         // we can only size if the frame is enabled and sizing is on
00273         if (isSizingEnabled() && isFrameEnabled())
00274         {
00275                 // point must be inside the outer edge
00276                 if (frame.isPointInRect(pt))
00277                 {
00278                         // adjust rect to get inner edge
00279                         frame.d_left    += d_borderSize;
00280                         frame.d_top             += d_borderSize;
00281                         frame.d_right   -= d_borderSize;
00282                         frame.d_bottom  -= d_borderSize;
00283 
00284                         // detect which edges we are on
00285                         bool top        = (pt.d_y < frame.d_top);
00286                         bool bottom = (pt.d_y >= frame.d_bottom);
00287                         bool left       = (pt.d_x < frame.d_left);
00288                         bool right      = (pt.d_x >= frame.d_right);
00289 
00290                         // return appropriate 'SizingLocation' value
00291                         if (top && left)
00292                         {
00293                                 return SizingTopLeft;
00294                         }
00295                         else if (top && right)
00296                         {
00297                                 return SizingTopRight;
00298                         }
00299                         else if (bottom && left)
00300                         {
00301                                 return SizingBottomLeft;
00302                         }
00303                         else if (bottom && right)
00304                         {
00305                                 return SizingBottomRight;
00306                         }
00307                         else if (top)
00308                         {
00309                                 return SizingTop;
00310                         }
00311                         else if (bottom)
00312                         {
00313                                 return SizingBottom;
00314                         }
00315                         else if (left)
00316                         {
00317                                 return SizingLeft;
00318                         }
00319                         else if (right)
00320                         {
00321                                 return SizingRight;
00322                         }
00323 
00324                 }
00325 
00326         }
00327 
00328         // deafult: None.
00329         return SizingNone;
00330 }
00331 
00332 
00333 /*************************************************************************
00334         move the window's left edge by 'delta'.  The rest of the window
00335         does not move, thus this changes the size of the Window.        
00336 *************************************************************************/
00337 void FrameWindow::moveLeftEdge(float delta)
00338 {
00339     float orgWidth = getAbsoluteWidth();
00340     float adjustment;
00341     float* minDim;
00342     float* maxDim;
00343     URect area(d_area);
00344 
00345     // ensure that we only size to the set constraints.
00346     //
00347     // NB: We are required to do this here due to our virtually unique sizing nature; the
00348     // normal system for limiting the window size is unable to supply the information we
00349     // require for updating our internal state used to manage the dragging, etc.
00350     float maxWidth(d_maxSize.d_x.asAbsolute(System::getSingleton().getRenderer()->getWidth()));
00351     float minWidth(d_minSize.d_x.asAbsolute(System::getSingleton().getRenderer()->getWidth()));
00352     float newWidth = orgWidth - delta;
00353 
00354     if (newWidth > maxWidth)
00355         delta = orgWidth - maxWidth;
00356     else if (newWidth < minWidth)
00357         delta = orgWidth - minWidth;
00358 
00359     // we use the active metrics mode to decide which component of the window edge to modify
00360     if (getMetricsMode() == Relative)
00361     {
00362         float base = getParentWidth();
00363         adjustment = (base != 0) ? delta / base : 0;
00364         minDim = &area.d_min.d_x.d_scale;
00365         maxDim = &area.d_max.d_x.d_scale;
00366     }
00367     else
00368     {
00369         adjustment = PixelAligned(delta);
00370         minDim = &area.d_min.d_x.d_offset;
00371         maxDim = &area.d_max.d_x.d_offset;
00372     }
00373 
00374     if (d_horzAlign == HA_RIGHT)
00375     {
00376         *maxDim -= adjustment;
00377     }
00378     else if (d_horzAlign == HA_CENTRE)
00379     {
00380         *maxDim -= adjustment * 0.5f;
00381         *minDim += adjustment * 0.5f;
00382     }
00383     else
00384     {
00385         *minDim += adjustment;
00386     }
00387 
00388     setWindowArea_impl(area.d_min, area.getSize(), d_horzAlign == HA_LEFT);
00389 }
00390 /*************************************************************************
00391         move the window's right edge by 'delta'.  The rest of the window
00392         does not move, thus this changes the size of the Window.
00393 *************************************************************************/
00394 void FrameWindow::moveRightEdge(float delta)
00395 {
00396     // store this so we can work out how much size actually changed
00397     float orgWidth = getAbsoluteWidth();
00398     float adjustment;
00399     float* minDim;
00400     float* maxDim;
00401     URect area(d_area);
00402 
00403     // ensure that we only size to the set constraints.
00404     //
00405     // NB: We are required to do this here due to our virtually unique sizing nature; the
00406     // normal system for limiting the window size is unable to supply the information we
00407     // require for updating our internal state used to manage the dragging, etc.
00408     float maxWidth(d_maxSize.d_x.asAbsolute(System::getSingleton().getRenderer()->getWidth()));
00409     float minWidth(d_minSize.d_x.asAbsolute(System::getSingleton().getRenderer()->getWidth()));
00410     float newWidth = orgWidth + delta;
00411 
00412     if (newWidth > maxWidth)
00413         delta = maxWidth - orgWidth;
00414     else if (newWidth < minWidth)
00415         delta = minWidth - orgWidth;
00416     
00417     // we use the active metrics mode to decide which component of the window edge to modify
00418     if (getMetricsMode() == Relative)
00419     {
00420         float base = getParentWidth();
00421         adjustment = (base != 0) ? delta / base : 0;
00422         minDim = &area.d_min.d_x.d_scale;
00423         maxDim = &area.d_max.d_x.d_scale;
00424     }
00425     else
00426     {
00427         adjustment = PixelAligned(delta);
00428         minDim = &area.d_min.d_x.d_offset;
00429         maxDim = &area.d_max.d_x.d_offset;
00430     }
00431 
00432     *maxDim += adjustment;
00433 
00434     if (d_horzAlign == HA_RIGHT)
00435     {
00436         *maxDim += adjustment;
00437         *minDim += adjustment;
00438     }
00439     else if (d_horzAlign == HA_CENTRE)
00440     {
00441         *maxDim += adjustment * 0.5f;
00442         *minDim += adjustment * 0.5f;
00443     }
00444 
00445     setWindowArea_impl(area.d_min, area.getSize(), d_horzAlign == HA_RIGHT);
00446 
00447     // move the dragging point so mouse remains 'attached' to edge of window
00448     d_dragPoint.d_x += getAbsoluteWidth() - orgWidth;
00449 }
00450 
00451 /*************************************************************************
00452         move the window's top edge by 'delta'.  The rest of the window
00453         does not move, thus this changes the size of the Window.
00454 *************************************************************************/
00455 void FrameWindow::moveTopEdge(float delta)
00456 {
00457     float orgHeight = getAbsoluteHeight();
00458     float adjustment;
00459     float* minDim;
00460     float* maxDim;
00461     URect area(d_area);
00462 
00463     // ensure that we only size to the set constraints.
00464     //
00465     // NB: We are required to do this here due to our virtually unique sizing nature; the
00466     // normal system for limiting the window size is unable to supply the information we
00467     // require for updating our internal state used to manage the dragging, etc.
00468     float maxHeight(d_maxSize.d_y.asAbsolute(System::getSingleton().getRenderer()->getHeight()));
00469     float minHeight(d_minSize.d_y.asAbsolute(System::getSingleton().getRenderer()->getHeight()));
00470     float newHeight = orgHeight - delta;
00471 
00472     if (newHeight > maxHeight)
00473         delta = orgHeight - maxHeight;
00474     else if (newHeight < minHeight)
00475         delta = orgHeight - minHeight;
00476 
00477     // we use the active metrics mode to decide which component of the window edge to modify
00478     if (getMetricsMode() == Relative)
00479     {
00480         float base = getParentHeight();
00481         adjustment = (base != 0) ? delta / base : 0;
00482         minDim = &area.d_min.d_y.d_scale;
00483         maxDim = &area.d_max.d_y.d_scale;
00484     }
00485     else
00486     {
00487         adjustment = PixelAligned(delta);
00488         minDim = &area.d_min.d_y.d_offset;
00489         maxDim = &area.d_max.d_y.d_offset;
00490     }
00491 
00492     if (d_vertAlign == VA_BOTTOM)
00493     {
00494         *maxDim -= adjustment;
00495     }
00496     else if (d_vertAlign == VA_CENTRE)
00497     {
00498         *maxDim -= adjustment * 0.5f;
00499         *minDim += adjustment * 0.5f;
00500     }
00501     else
00502     {
00503         *minDim += adjustment;
00504     }
00505 
00506     setWindowArea_impl(area.d_min, area.getSize(), d_vertAlign == VA_TOP);
00507 }
00508 
00509 
00510 /*************************************************************************
00511         move the window's bottom edge by 'delta'.  The rest of the window
00512         does not move, thus this changes the size of the Window.        
00513 *************************************************************************/
00514 void FrameWindow::moveBottomEdge(float delta)
00515 {
00516     // store this so we can work out how much size actually changed
00517     float orgHeight = getAbsoluteHeight();
00518     float adjustment;
00519     float* minDim;
00520     float* maxDim;
00521     URect area(d_area);
00522 
00523     // ensure that we only size to the set constraints.
00524     //
00525     // NB: We are required to do this here due to our virtually unique sizing nature; the
00526     // normal system for limiting the window size is unable to supply the information we
00527     // require for updating our internal state used to manage the dragging, etc.
00528     float maxHeight(d_maxSize.d_y.asAbsolute(System::getSingleton().getRenderer()->getHeight()));
00529     float minHeight(d_minSize.d_y.asAbsolute(System::getSingleton().getRenderer()->getHeight()));
00530     float newHeight = orgHeight + delta;
00531 
00532     if (newHeight > maxHeight)
00533         delta = maxHeight - orgHeight;
00534     else if (newHeight < minHeight)
00535         delta = minHeight - orgHeight;
00536     
00537     // we use the active metrics mode to decide which component of the window edge to modify
00538     if (getMetricsMode() == Relative)
00539     {
00540         float base = getParentHeight();
00541         adjustment = (base != 0) ? delta / base : 0;
00542         minDim = &area.d_min.d_y.d_scale;
00543         maxDim = &area.d_max.d_y.d_scale;
00544     }
00545     else
00546     {
00547         adjustment = PixelAligned(delta);
00548         minDim = &area.d_min.d_y.d_offset;
00549         maxDim = &area.d_max.d_y.d_offset;
00550     }
00551 
00552     *maxDim += adjustment;
00553 
00554     if (d_vertAlign == VA_BOTTOM)
00555     {
00556         *maxDim += adjustment;
00557         *minDim += adjustment;
00558     }
00559     else if (d_vertAlign == VA_CENTRE)
00560     {
00561         *maxDim += adjustment * 0.5f;
00562         *minDim += adjustment * 0.5f;
00563     }
00564 
00565     setWindowArea_impl(area.d_min, area.getSize(), d_vertAlign == VA_BOTTOM);
00566 
00567     // move the dragging point so mouse remains 'attached' to edge of window
00568     d_dragPoint.d_y += getAbsoluteHeight() - orgHeight;
00569 }
00570 
00571 
00572 /*************************************************************************
00573         Add frame window specific events        
00574 *************************************************************************/
00575 void FrameWindow::addFrameWindowEvents(void)
00576 {
00577         addEvent(EventRollupToggled);
00578         addEvent(EventCloseClicked);
00579 }
00580 
00581 
00582 /*************************************************************************
00583         Handler to map close button clicks to FrameWindow 'CloseCliked' events
00584 *************************************************************************/
00585 bool FrameWindow::closeClickHandler(const EventArgs& e)
00586 {
00587     WindowEventArgs args(this);
00588         onCloseClicked(args);
00589 
00590         return true;
00591 }
00592 
00593 
00594 /*************************************************************************
00595         Set the appropriate mouse cursor for the given window-relative pixel
00596         point.
00597 *************************************************************************/
00598 void FrameWindow::setCursorForPoint(const Point& pt) const
00599 {
00600         switch(getSizingBorderAtPoint(pt))
00601         {
00602         case SizingTop:
00603         case SizingBottom:
00604                 MouseCursor::getSingleton().setImage(d_nsSizingCursor);
00605                 break;
00606 
00607         case SizingLeft:
00608         case SizingRight:
00609                 MouseCursor::getSingleton().setImage(d_ewSizingCursor);
00610                 break;
00611 
00612         case SizingTopLeft:
00613         case SizingBottomRight:
00614                 MouseCursor::getSingleton().setImage(d_nwseSizingCursor);
00615                 break;
00616 
00617         case SizingTopRight:
00618         case SizingBottomLeft:
00619                 MouseCursor::getSingleton().setImage(d_neswSizingCursor);
00620                 break;
00621 
00622         default:
00623                 MouseCursor::getSingleton().setImage(getMouseCursor());
00624                 break;
00625         }
00626 
00627 }
00628 
00629 
00630 /*************************************************************************
00631         Event generated internally whenever the roll-up / shade state of the
00632         window changes.
00633 *************************************************************************/
00634 void FrameWindow::onRollupToggled(WindowEventArgs& e)
00635 {
00636     requestRedraw();
00637 
00638         fireEvent(EventRollupToggled, e, EventNamespace);
00639 }
00640 
00641 
00642 /*************************************************************************
00643         Event generated internally whenever the close button is clicked.        
00644 *************************************************************************/
00645 void FrameWindow::onCloseClicked(WindowEventArgs& e)
00646 {
00647         fireEvent(EventCloseClicked, e, EventNamespace);
00648 }
00649 
00650 
00651 /*************************************************************************
00652         Handler for mouse move events
00653 *************************************************************************/
00654 void FrameWindow::onMouseMove(MouseEventArgs& e)
00655 {
00656         // default processing (this is now essential as it controls event firing).
00657         Window::onMouseMove(e);
00658 
00659         // if we are not the window containing the mouse, do NOT change the cursor
00660         if (System::getSingleton().getWindowContainingMouse() != this)
00661         {
00662                 return;
00663         }
00664 
00665         if (isSizingEnabled())
00666         {
00667                 Point localMousePos(screenToWindow(e.position));
00668 
00669                 if (getMetricsMode() == Relative)
00670                 {
00671                         localMousePos = relativeToAbsolute(localMousePos);
00672                 }
00673 
00674                 if (d_beingSized)
00675                 {
00676                         SizingLocation dragEdge = getSizingBorderAtPoint(d_dragPoint);
00677 
00678                         // calculate sizing deltas...
00679                         float   deltaX = localMousePos.d_x - d_dragPoint.d_x;
00680                         float   deltaY = localMousePos.d_y - d_dragPoint.d_y;
00681 
00682                         // size left or right edges
00683                         if (isLeftSizingLocation(dragEdge))
00684                         {
00685                                 moveLeftEdge(deltaX);
00686                         }
00687                         else if (isRightSizingLocation(dragEdge))
00688                         {
00689                                 moveRightEdge(deltaX);
00690                         }
00691 
00692                         // size top or bottom edges
00693                         if (isTopSizingLocation(dragEdge))
00694                         {
00695                                 moveTopEdge(deltaY);
00696                         }
00697                         else if (isBottomSizingLocation(dragEdge))
00698                         {
00699                                 moveBottomEdge(deltaY);
00700                         }
00701 
00702                 }
00703                 else
00704                 {
00705                         setCursorForPoint(localMousePos);
00706                 }
00707 
00708         }
00709 
00710         // mark event as handled
00711         e.handled = true;
00712 }
00713 
00714 
00715 /*************************************************************************
00716         Handler for mouse button down events
00717 *************************************************************************/
00718 void FrameWindow::onMouseButtonDown(MouseEventArgs& e)
00719 {
00720         // default processing (this is now essential as it controls event firing).
00721         Window::onMouseButtonDown(e);
00722 
00723         if (e.button == LeftButton)
00724         {
00725                 if (isSizingEnabled())
00726                 {
00727                         // get position of mouse as co-ordinates local to this window.
00728                         Point localPos(screenToWindow(e.position));
00729 
00730                         if (getMetricsMode() == Relative)
00731                         {
00732                                 localPos = relativeToAbsolute(localPos);
00733                         }
00734 
00735                         // if the mouse is on the sizing border
00736                         if (getSizingBorderAtPoint(localPos) != SizingNone)
00737                         {
00738                                 // ensure all inputs come to us for now
00739                                 if (captureInput())
00740                                 {
00741                                         // setup the 'dragging' state variables
00742                                         d_beingSized = true;
00743                                         d_dragPoint = localPos;
00744                                 }
00745 
00746                         }
00747 
00748                 }
00749 
00750                 e.handled = true;
00751         }
00752 
00753 }
00754 
00755 
00756 /*************************************************************************
00757         Handler for mouse button up events
00758 *************************************************************************/
00759 void FrameWindow::onMouseButtonUp(MouseEventArgs& e)
00760 {
00761         // default processing (this is now essential as it controls event firing).
00762         Window::onMouseButtonUp(e);
00763 
00764         if (e.button == LeftButton)
00765         {
00766                 // release our capture on the input data
00767                 releaseInput();
00768                 e.handled = true;
00769         }
00770 
00771 }
00772 
00773 
00774 /*************************************************************************
00775         Handler for when mouse capture is lost
00776 *************************************************************************/
00777 void FrameWindow::onCaptureLost(WindowEventArgs& e)
00778 {
00779         // default processing (this is now essential as it controls event firing).
00780         Window::onCaptureLost(e);
00781 
00782         // reset sizing state
00783         d_beingSized = false;
00784 
00785         e.handled = true;
00786 }
00787 
00788 
00789 /*************************************************************************
00790     Handler for when text changes
00791 *************************************************************************/
00792 void FrameWindow::onTextChanged(WindowEventArgs& e)
00793 {
00794     // pass this onto titlebar component.
00795     WindowManager::getSingleton().getWindow(getName() + "__auto_titlebar__")->setText(d_text);
00796 }
00797 
00798 
00799 /*************************************************************************
00800     Handler for when this Window is activated
00801 *************************************************************************/
00802 void FrameWindow::onActivated(ActivationEventArgs& e)
00803 {
00804         Window::onActivated(e);
00805         d_titlebar->requestRedraw();
00806 }
00807 
00808 
00809 /*************************************************************************
00810     Handler for when this Window is deactivated
00811 *************************************************************************/
00812 void FrameWindow::onDeactivated(ActivationEventArgs& e)
00813 {
00814         Window::onDeactivated(e);
00815         d_titlebar->requestRedraw();
00816 }
00817 
00818 
00819 /*************************************************************************
00820         Set whether this FrameWindow can be moved by dragging the title bar.    
00821 *************************************************************************/
00822 void FrameWindow::setDragMovingEnabled(bool setting)
00823 {
00824         if (d_dragMovable != setting)
00825         {
00826                 d_dragMovable = setting;
00827 
00828         try
00829         {
00830             static_cast<Titlebar*>(WindowManager::getSingleton().getWindow(getName() + "__auto_titlebar__"))->setDraggingEnabled(setting);
00831         }
00832         catch (UnknownObjectException)
00833         {}
00834     }
00835 
00836 }
00837 
00838 
00839 /*************************************************************************
00840         Return the font being used for the title bar text
00841 *************************************************************************/
00842 const Font* FrameWindow::getTitlebarFont(void) const
00843 {
00844     try
00845     {
00846         return WindowManager::getSingleton().getWindow(getName() + "__auto_titlebar__")->getFont();
00847     }
00848     catch (UnknownObjectException)
00849     {
00850         return 0;
00851     }
00852 }
00853 
00854 
00855 /*************************************************************************
00856         Add properties for this class
00857 *************************************************************************/
00858 void FrameWindow::addFrameWindowProperties(void)
00859 {
00860         addProperty(&d_sizingEnabledProperty);
00861         addProperty(&d_frameEnabledProperty);
00862         addProperty(&d_titlebarEnabledProperty);
00863         addProperty(&d_closeButtonEnabledProperty);
00864         addProperty(&d_rollUpEnabledProperty);
00865         addProperty(&d_rollUpStateProperty);
00866         addProperty(&d_dragMovingEnabledProperty);
00867         addProperty(&d_sizingBorderThicknessProperty);
00868         addProperty(&d_titlebarFontProperty);
00869         addProperty(&d_captionColourProperty);
00870     addProperty(&d_nsSizingCursorProperty);
00871     addProperty(&d_ewSizingCursorProperty);
00872     addProperty(&d_nwseSizingCursorProperty);
00873     addProperty(&d_neswSizingCursorProperty);
00874 }
00875 
00876 
00877 /*************************************************************************
00878         Return the current colour used for rendering the caption text
00879 *************************************************************************/
00880 colour FrameWindow::getCaptionColour(void) const
00881 {
00882     return static_cast<Titlebar*>(WindowManager::getSingleton().getWindow(getName() + "__auto_titlebar__"))->getCaptionColour();
00883 }
00884 
00885 
00886 /*************************************************************************
00887         Sets the colour to be used for rendering the caption text.
00888 *************************************************************************/
00889 void FrameWindow::setCaptionColour(colour col)
00890 {
00891     static_cast<Titlebar*>(WindowManager::getSingleton().getWindow(getName() + "__auto_titlebar__"))->setCaptionColour(col);
00892 }
00893 
00894 
00895 const Image* FrameWindow::getNSSizingCursorImage() const
00896 {
00897     return d_nsSizingCursor;
00898 }
00899 
00900 const Image* FrameWindow::getEWSizingCursorImage() const
00901 {
00902     return d_ewSizingCursor;
00903 }
00904 
00905 const Image* FrameWindow::getNWSESizingCursorImage() const
00906 {
00907     return d_nwseSizingCursor;
00908 }
00909 
00910 const Image* FrameWindow::getNESWSizingCursorImage() const
00911 {
00912     return d_neswSizingCursor;
00913 }
00914 
00915 void FrameWindow::setNSSizingCursorImage(const Image* image)
00916 {
00917     d_nsSizingCursor = image;
00918 }
00919 
00920 void FrameWindow::setEWSizingCursorImage(const Image* image)
00921 {
00922     d_ewSizingCursor = image;
00923 }
00924 
00925 void FrameWindow::setNWSESizingCursorImage(const Image* image)
00926 {
00927     d_nwseSizingCursor = image;
00928 }
00929 
00930 void FrameWindow::setNESWSizingCursorImage(const Image* image)
00931 {
00932     d_neswSizingCursor = image;
00933 }
00934 
00935 void FrameWindow::setNSSizingCursorImage(const String& imageset, const String& image)
00936 {
00937     d_nsSizingCursor = &ImagesetManager::getSingleton().getImageset(imageset)->getImage(image);
00938 }
00939 
00940 void FrameWindow::setEWSizingCursorImage(const String& imageset, const String& image)
00941 {
00942     d_ewSizingCursor = &ImagesetManager::getSingleton().getImageset(imageset)->getImage(image);
00943 }
00944 
00945 void FrameWindow::setNWSESizingCursorImage(const String& imageset, const String& image)
00946 {
00947     d_nwseSizingCursor = &ImagesetManager::getSingleton().getImageset(imageset)->getImage(image);
00948 }
00949 
00950 void FrameWindow::setNESWSizingCursorImage(const String& imageset, const String& image)
00951 {
00952     d_neswSizingCursor = &ImagesetManager::getSingleton().getImageset(imageset)->getImage(image);
00953 }
00954 
00955 } // End of  CEGUI namespace section

Generated on Wed Sep 7 09:56:31 2005 for Crazy Eddies GUI System by  doxygen 1.4.3