00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _CEGUIWindow_h_
00027 #define _CEGUIWindow_h_
00028
00029 #include "CEGUIBase.h"
00030 #include "CEGUIString.h"
00031 #include "CEGUIVector.h"
00032 #include "CEGUIRect.h"
00033 #include "CEGUISize.h"
00034 #include "CEGUIEventSet.h"
00035 #include "CEGUIPropertySet.h"
00036 #include "CEGUISystem.h"
00037 #include "CEGUIInputEvent.h"
00038 #include "CEGUIWindowProperties.h"
00039 #include <vector>
00040
00041
00042 #if defined(_MSC_VER)
00043 # pragma warning(push)
00044 # pragma warning(disable : 4251)
00045 #endif
00046
00047
00048
00049 namespace CEGUI
00050 {
00051
00060 enum CEGUIBASE_API MetricsMode
00061 {
00062 Relative,
00063 Absolute,
00064 Inherited
00065 };
00066
00067
00077 class CEGUIBASE_API Window : public PropertySet, public EventSet
00078 {
00079 public:
00080 static const String EventNamespace;
00081
00082
00083
00084
00085
00086 static const String EventParentSized;
00087 static const String EventSized;
00088 static const String EventMoved;
00089 static const String EventTextChanged;
00090 static const String EventFontChanged;
00091 static const String EventAlphaChanged;
00092 static const String EventIDChanged;
00093 static const String EventActivated;
00094 static const String EventDeactivated;
00095 static const String EventShown;
00096 static const String EventHidden;
00097 static const String EventEnabled;
00098 static const String EventDisabled;
00099 static const String EventMetricsModeChanged;
00100 static const String EventClippedByParentChanged;
00101 static const String EventDestroyedByParentChanged;
00102 static const String EventInheritsAlphaChanged;
00103 static const String EventAlwaysOnTopChanged;
00104 static const String EventInputCaptureGained;
00105 static const String EventInputCaptureLost;
00106 static const String EventRenderingStarted;
00107 static const String EventRenderingEnded;
00108 static const String EventChildAdded;
00109 static const String EventChildRemoved;
00110 static const String EventDestructionStarted;
00111 static const String EventZOrderChanged;
00112
00113
00114 static const String EventMouseEnters;
00115 static const String EventMouseLeaves;
00116 static const String EventMouseMove;
00117 static const String EventMouseWheel;
00118 static const String EventMouseButtonDown;
00119 static const String EventMouseButtonUp;
00120 static const String EventMouseClick;
00121 static const String EventMouseDoubleClick;
00122 static const String EventMouseTripleClick;
00123 static const String EventKeyDown;
00124 static const String EventKeyUp;
00125 static const String EventCharacterKey;
00126
00127
00128
00129
00130
00141 Window(const String& type, const String& name);
00142
00143
00148 virtual ~Window(void);
00149
00150
00151
00152
00153
00161 const String& getType(void) const {return d_type;}
00162
00163
00171 const String& getName(void) const {return d_name;}
00172
00173
00181 bool isDestroyedByParent(void) const {return d_destroyedByParent;}
00182
00183
00191 bool isAlwaysOnTop(void) const {return d_alwaysOnTop;}
00192
00193
00201 bool isDisabled(void) const;
00202
00203
00214 bool isVisible(void) const;
00215
00216
00227 bool isActive(void) const;
00228
00229
00237 bool isClippedByParent(void) const {return d_clippedByParent;}
00238
00239
00247 uint getID(void) const {return d_ID;}
00248
00249
00257 uint getChildCount(void) const {return (uint)d_children.size();}
00258
00259
00270 bool isChild(const String& name) const;
00271
00272
00287 bool isChild(uint ID) const;
00288
00289
00300 bool isChild(const Window* window) const;
00301
00302
00320 Window* getChild(const String& name) const;
00321
00322
00340 Window* getChild(uint ID) const;
00341
00342
00358 Window* getChildAtIdx(uint idx) const {return d_children[idx];}
00359
00360
00370 Window* getActiveChild(void);
00371 const Window* getActiveChild(void) const;
00372
00373
00384 bool isAncestor(const String& name) const;
00385
00386
00397 bool isAncestor(uint ID) const;
00398
00399
00410 bool isAncestor(const Window* window) const;
00411
00412
00420 const Font* getFont(void) const;
00421
00422
00430 const String& getText(void) const {return d_text;}
00431
00432
00440 bool inheritsAlpha(void) const {return d_inheritsAlpha;}
00441
00442
00456 float getAlpha(void) const {return d_alpha;}
00457
00458
00467 float getEffectiveAlpha(void) const;
00468
00469
00478 Rect getRect(void) const;
00479
00480
00492 virtual Rect getPixelRect(void) const;
00493
00494
00502 Rect getInnerRect(void) const;
00503
00504
00513 Rect getUnclippedPixelRect(void) const;
00514
00515
00524 virtual Rect getUnclippedInnerRect(void) const;
00525
00526
00534 static Window* getCaptureWindow(void) {return d_captureWindow;}
00535
00536
00544 bool isCapturedByThis(void) const {return getCaptureWindow() == this;}
00545
00546
00554 bool isCapturedByAncestor(void) const {return isAncestor(getCaptureWindow());}
00555
00556
00564 bool isCapturedByChild(void) const {return isChild(getCaptureWindow());}
00565
00566
00577 virtual bool isHit(const Point& position) const;
00578
00579
00590 Window* getChildAtPosition(const Point& position) const;
00591
00592
00600 MetricsMode getMetricsMode(void) const;
00601
00602
00611 float getXPosition(void) const;
00612
00613
00622 float getYPosition(void) const;
00623
00624
00633 Point getPosition(void) const;
00634
00635
00644 float getWidth(void) const;
00645
00654 float getHeight(void) const;
00655
00656
00665 Size getSize(void) const;
00666
00667
00676 Window* getParent(void) const {return d_parent;}
00677
00678
00687 Size getMaximumSize(void) const;
00688
00689
00698 Size getMinimumSize(void) const;
00699
00700
00708 const Image* getMouseCursor(void) const;
00709
00710
00718 Rect getRelativeRect(void) const {return d_rel_area;}
00719
00720
00728 Point getRelativePosition(void) const {return d_rel_area.getPosition();}
00729
00730
00738 float getRelativeXPosition(void) const {return d_rel_area.d_left;}
00739
00740
00748 float getRelativeYPosition(void) const {return d_rel_area.d_top;}
00749
00750
00758 Size getRelativeSize(void) const {return d_rel_area.getSize();}
00759
00760
00768 float getRelativeWidth(void) const {return d_rel_area.getWidth();}
00769
00770
00778 float getRelativeHeight(void) const {return d_rel_area.getHeight();}
00779
00780
00788 Rect getAbsoluteRect(void) const {return d_abs_area;}
00789
00790
00798 Point getAbsolutePosition(void) const {return d_abs_area.getPosition();}
00799
00800
00808 float getAbsoluteXPosition(void) const {return d_abs_area.d_left;}
00809
00810
00818 float getAbsoluteYPosition(void) const {return d_abs_area.d_top;}
00819
00820
00828 Size getAbsoluteSize(void) const {return d_abs_area.getSize();}
00829
00830
00838 float getAbsoluteWidth(void) const {return d_abs_area.getWidth();}
00839
00840
00848 float getAbsoluteHeight(void) const {return d_abs_area.getHeight();}
00849
00850
00861 void* getUserData(void) const {return d_userData;}
00862
00863
00874 float getXPosition(MetricsMode mode) const;
00875
00876
00887 float getYPosition(MetricsMode mode) const;
00888
00889
00900 Point getPosition(MetricsMode mode) const;
00901
00902
00913 float getWidth(MetricsMode mode) const;
00914
00915
00926 float getHeight(MetricsMode mode) const;
00927
00928
00939 Size getSize(MetricsMode mode) const;
00940
00941
00952 Rect getRect(MetricsMode mode) const;
00953
00954
00965 bool restoresOldCapture(void) const {return d_restoreOldCapture;}
00966
00967
00976 bool isZOrderingEnabled(void) const;
00977
00978
00987 bool wantsMultiClickEvents(void) const;
00988
00989
00998 bool isMouseAutoRepeatEnabled(void) const;
00999
01000
01008 float getAutoRepeatDelay(void) const;
01009
01010
01018 float getAutoRepeatRate(void) const;
01019
01020
01021
01022
01023
01034 virtual void initialise(void) {}
01035
01036
01048 void setDestroyedByParent(bool setting);
01049
01050
01061 void setAlwaysOnTop(bool setting);
01062
01063
01074 void setEnabled(bool setting);
01075
01076
01084 void enable(void) {setEnabled(true);}
01085
01086
01094 void disable(void) {setEnabled(false);}
01095
01096
01107 void setVisible(bool setting);
01108
01109
01117 void show(void) {setVisible(true);}
01118
01119
01127 void hide(void) {setVisible(false);}
01128
01129
01137 void activate(void);
01138
01139
01148 void deactivate(void);
01149
01150
01162 void setClippedByParent(bool setting);
01163
01164
01175 void setID(uint ID);
01176
01177
01188 void setText(const String& text);
01189
01190
01201 void setWidth(float width);
01202
01203
01214 void setHeight(float height);
01215
01216
01227 void setSize(const Size& size);
01228
01229
01240 void setXPosition(float x);
01241
01242
01253 void setYPosition(float y);
01254
01255
01266 void setPosition(const Point& position);
01267
01268
01280 void setAreaRect(const Rect& area);
01281
01282
01293 void setFont(const Font* font);
01294
01295
01308 void setFont(const String& name);
01309
01310
01325 void addChildWindow(const String& name);
01326
01327
01341 void addChildWindow(Window* window);
01342
01343
01354 void removeChildWindow(const String& name);
01355
01356
01367 void removeChildWindow(Window* window);
01368
01369
01381 void removeChildWindow(uint ID);
01382
01383
01395 void moveToFront();
01396
01397
01408 void moveToBack();
01409
01410
01419 bool captureInput(void);
01420
01421
01429 void releaseInput(void);
01430
01431
01447 void setRestoreCapture(bool setting);
01448
01449
01466 void setAlpha(float alpha);
01467
01468
01479 void setInheritsAlpha(bool setting);
01480
01481
01489 void requestRedraw(void) const;
01490
01491
01502 void setMetricsMode(MetricsMode mode);
01503
01504
01513 void setMinimumSize(const Size& sz);
01514
01515
01524 void setMaximumSize(const Size& sz);
01525
01526
01537 void setMouseCursor(const Image* image) {d_mouseCursor = image;}
01538
01539
01550 void setMouseCursor(MouseCursorImage image) {d_mouseCursor = (const Image*)image;}
01551
01552
01568 void setMouseCursor(const String& imageset, const String& image_name);
01569
01570
01584 void setUserData(void* user_data) {d_userData = user_data;}
01585
01586
01600 void setXPosition(MetricsMode mode, float x);
01601
01602
01616 void setYPosition(MetricsMode mode, float y);
01617
01618
01632 void setPosition(MetricsMode mode, const Point& position);
01633
01634
01648 void setWidth(MetricsMode mode, float width);
01649
01650
01664 void setHeight(MetricsMode mode, float height);
01665
01666
01680 void setSize(MetricsMode mode, const Size& size);
01681
01682
01696 void setRect(MetricsMode mode, const Rect& area);
01697
01698
01710 void setZOrderingEnabled(bool setting);
01711
01712
01724 void setWantsMultiClickEvents(bool setting);
01725
01726
01738 void setMouseAutoRepeatEnabled(bool setting);
01739
01740
01751 void setAutoRepeatDelay(float delay);
01752
01753
01764 void setAutoRepeatRate(float rate);
01765
01766
01767
01768
01769
01780 float absoluteToRelativeX(float val) const;
01781
01782
01793 float absoluteToRelativeY(float val) const;
01794
01795
01806 Point absoluteToRelative(const Point& pt) const;
01807
01808
01819 Size absoluteToRelative(const Size& sze) const;
01820
01821
01832 Rect absoluteToRelative(const Rect& rect) const;
01833
01834
01845 float relativeToAbsoluteX(float val) const;
01846
01847
01858 float relativeToAbsoluteY(float val) const;
01859
01860
01871 Point relativeToAbsolute(const Point& pt) const;
01872
01873
01884 Size relativeToAbsolute(const Size& sze) const;
01885
01886
01897 Rect relativeToAbsolute(const Rect& rect) const;
01898
01899
01910 float windowToScreenX(float x) const;
01911
01912
01923 float windowToScreenY(float y) const;
01924
01925
01936 Point windowToScreen(const Point& pt) const;
01937
01938
01949 Size windowToScreen(const Size& sze) const;
01950
01951
01962 Rect windowToScreen(const Rect& rect) const;
01963
01964
01975 float screenToWindowX(float x) const;
01976
01977
01988 float screenToWindowY(float y) const;
01989
01990
02001 Point screenToWindow(const Point& pt) const;
02002
02003
02014 Size screenToWindow(const Size& sze) const;
02015
02016
02027 Rect screenToWindow(const Rect& rect) const;
02028
02029
02030
02031
02032
02040 void render(void);
02041
02042
02058 void update(float elapsed);
02059
02060
02061 protected:
02062
02063
02064
02065 friend class System;
02066
02067
02068
02069
02070
02079 virtual void onSized(WindowEventArgs& e);
02080
02081
02090 virtual void onMoved(WindowEventArgs& e);
02091
02092
02101 virtual void onTextChanged(WindowEventArgs& e);
02102
02103
02112 virtual void onFontChanged(WindowEventArgs& e);
02113
02114
02123 virtual void onAlphaChanged(WindowEventArgs& e);
02124
02125
02134 virtual void onIDChanged(WindowEventArgs& e);
02135
02136
02145 virtual void onShown(WindowEventArgs& e);
02146
02147
02156 virtual void onHidden(WindowEventArgs& e);
02157
02158
02167 virtual void onEnabled(WindowEventArgs& e);
02168
02169
02178 virtual void onDisabled(WindowEventArgs& e);
02179
02180
02189 virtual void onMetricsChanged(WindowEventArgs& e);
02190
02191
02200 virtual void onClippingChanged(WindowEventArgs& e);
02201
02202
02211 virtual void onParentDestroyChanged(WindowEventArgs& e);
02212
02213
02222 virtual void onInheritsAlphaChanged(WindowEventArgs& e);
02223
02224
02233 virtual void onAlwaysOnTopChanged(WindowEventArgs& e);
02234
02235
02244 virtual void onCaptureGained(WindowEventArgs& e);
02245
02246
02255 virtual void onCaptureLost(WindowEventArgs& e);
02256
02257
02266 virtual void onRenderingStarted(WindowEventArgs& e);
02267
02268
02277 virtual void onRenderingEnded(WindowEventArgs& e);
02278
02279
02288 virtual void onZChanged(WindowEventArgs& e);
02289
02290
02299 virtual void onDestructionStarted(WindowEventArgs& e);
02300
02301
02309 virtual void onActivated(ActivationEventArgs& e);
02310
02311
02319 virtual void onDeactivated(ActivationEventArgs& e);
02320
02321
02331 virtual void onParentSized(WindowEventArgs& e);
02332
02333
02341 virtual void onChildAdded(WindowEventArgs& e);
02342
02343
02351 virtual void onChildRemoved(WindowEventArgs& e);
02352
02353
02361 virtual void onMouseEnters(MouseEventArgs& e);
02362
02363
02371 virtual void onMouseLeaves(MouseEventArgs& e);
02372
02373
02381 virtual void onMouseMove(MouseEventArgs& e);
02382
02383
02391 virtual void onMouseWheel(MouseEventArgs& e);
02392
02393
02401 virtual void onMouseButtonDown(MouseEventArgs& e);
02402
02403
02411 virtual void onMouseButtonUp(MouseEventArgs& e);
02412
02413
02422 virtual void onMouseClicked(MouseEventArgs& e);
02423
02424
02432 virtual void onMouseDoubleClicked(MouseEventArgs& e);
02433
02434
02442 virtual void onMouseTripleClicked(MouseEventArgs& e);
02443
02444
02453 virtual void onKeyDown(KeyEventArgs& e);
02454
02455
02465 virtual void onKeyUp(KeyEventArgs& e);
02466
02467
02477 virtual void onCharacter(KeyEventArgs& e);
02478
02479
02480
02481
02482
02493 virtual void updateSelf(float elapsed);
02494
02495
02506 virtual void drawSelf(float z) = 0;
02507
02508
02519 void setParent(Window* parent);
02520
02521
02529 float getParentWidth(void) const;
02530
02531
02539 float getParentHeight(void) const;
02540
02541
02549 Size getParentSize(void) const;
02550
02551
02566 Rect absoluteToRelative_impl(const Window* window, const Rect& rect) const;
02567 Size absoluteToRelative_impl(const Window* window, const Size& sz) const;
02568 Point absoluteToRelative_impl(const Window* window, const Point& pt) const;
02569 float absoluteToRelativeX_impl(const Window* window, float x) const;
02570 float absoluteToRelativeY_impl(const Window* window, float y) const;
02571
02572
02587 Rect relativeToAbsolute_impl(const Window* window, const Rect& rect) const;
02588 Size relativeToAbsolute_impl(const Window* window, const Size& sz) const;
02589 Point relativeToAbsolute_impl(const Window* window, const Point& pt) const;
02590 float relativeToAbsoluteX_impl(const Window* window, float x) const;
02591 float relativeToAbsoluteY_impl(const Window* window, float y) const;
02592
02593 Size getWindowSize_impl(const Window* window) const;
02594
02595
02601 MetricsMode getInheritedMetricsMode(void) const;
02602
02603
02608 void generateAutoRepeatEvent(MouseButton button);
02609
02610
02611
02612
02613
02614
02615 typedef std::vector<Window*> ChildList;
02616 ChildList d_children;
02617
02618
02619 MetricsMode d_metricsMode;
02620 static Window* d_captureWindow;
02621 Window* d_oldCapture;
02622 Window* d_parent;
02623 const Font* d_font;
02624 String d_text;
02625 uint d_ID;
02626 float d_alpha;
02627 Rect d_abs_area;
02628 Rect d_rel_area;
02629 const Image* d_mouseCursor;
02630 void* d_userData;
02631
02632
02633 Size d_minSize;
02634 Size d_maxSize;
02635
02636
02637 bool d_enabled;
02638 bool d_visible;
02639 bool d_active;
02640 bool d_clippedByParent;
02641 bool d_destroyedByParent;
02642 bool d_alwaysOnTop;
02643 bool d_inheritsAlpha;
02644 bool d_restoreOldCapture;
02645 bool d_zOrderingEnabled;
02646 bool d_wantsMultiClicks;
02647
02648
02649 bool d_autoRepeat;
02650 float d_repeatDelay;
02651 float d_repeatRate;
02652 bool d_repeating;
02653 float d_repeatElapsed;
02654 MouseButton d_repeatButton;
02655
02656 protected:
02657
02658
02659
02660 static WindowProperties::AbsoluteHeight d_absHeightProperty;
02661 static WindowProperties::AbsoluteMaxSize d_absMaxSizeProperty;
02662 static WindowProperties::AbsoluteMinSize d_absMinSizeProperty;
02663 static WindowProperties::AbsolutePosition d_absPositionProperty;
02664 static WindowProperties::AbsoluteRect d_absRectProperty;
02665 static WindowProperties::AbsoluteSize d_absSizeProperty;
02666 static WindowProperties::AbsoluteWidth d_absWidthProperty;
02667 static WindowProperties::AbsoluteXPosition d_absXPosProperty;
02668 static WindowProperties::AbsoluteYPosition d_absYPosProperty;
02669 static WindowProperties::Alpha d_alphaProperty;
02670 static WindowProperties::AlwaysOnTop d_alwaysOnTopProperty;
02671 static WindowProperties::ClippedByParent d_clippedByParentProperty;
02672 static WindowProperties::DestroyedByParent d_destroyedByParentProperty;
02673 static WindowProperties::Disabled d_disabledProperty;
02674 static WindowProperties::Font d_fontProperty;
02675 static WindowProperties::Height d_heightProperty;
02676 static WindowProperties::ID d_IDProperty;
02677 static WindowProperties::InheritsAlpha d_inheritsAlphaProperty;
02678 static WindowProperties::MetricsMode d_metricsModeProperty;
02679 static WindowProperties::MouseCursorImage d_mouseCursorProperty;
02680 static WindowProperties::Position d_positionProperty;
02681 static WindowProperties::Rect d_rectProperty;
02682 static WindowProperties::RelativeHeight d_relHeightProperty;
02683 static WindowProperties::RelativeMaxSize d_relMaxSizeProperty;
02684 static WindowProperties::RelativeMinSize d_relMinSizeProperty;
02685 static WindowProperties::RelativePosition d_relPositionProperty;
02686 static WindowProperties::RelativeRect d_relRectProperty;
02687 static WindowProperties::RelativeSize d_relSizeProperty;
02688 static WindowProperties::RelativeWidth d_relWidthProperty;
02689 static WindowProperties::RelativeXPosition d_relXPosProperty;
02690 static WindowProperties::RelativeYPosition d_relYPosProperty;
02691 static WindowProperties::RestoreOldCapture d_restoreOldCaptureProperty;
02692 static WindowProperties::Size d_sizeProperty;
02693 static WindowProperties::Text d_textProperty;
02694 static WindowProperties::Visible d_visibleProperty;
02695 static WindowProperties::Width d_widthProperty;
02696 static WindowProperties::XPosition d_xPosProperty;
02697 static WindowProperties::YPosition d_yPosProperty;
02698 static WindowProperties::ZOrderChangeEnabled d_zOrderChangeProperty;
02699 static WindowProperties::WantsMultiClickEvents d_wantsMultiClicksProperty;
02700 static WindowProperties::MouseButtonDownAutoRepeat d_autoRepeatProperty;
02701 static WindowProperties::AutoRepeatDelay d_autoRepeatDelayProperty;
02702 static WindowProperties::AutoRepeatRate d_autoRepeatRateProperty;
02703
02704
02705
02706
02707
02712 void addStandardEvents(void);
02713
02718 virtual void cleanupChildren(void);
02719
02724 virtual void addChild_impl(Window* wnd);
02725
02730 virtual void removeChild_impl(Window* wnd);
02731
02736 virtual void onZChange_impl(void);
02737
02738
02743 void addStandardProperties(void);
02744
02745
02746
02747
02748
02749 Window(const Window& wnd) {}
02750 Window& operator=(const Window& wnd) {return *this;}
02751
02752
02753
02754
02755 const String d_type;
02756 const String d_name;
02757 };
02758
02759 }
02760
02761
02762 #if defined(_MSC_VER)
02763 # pragma warning(pop)
02764 #endif
02765
02766 #endif // end of guard _CEGUIWindow_h_