00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(_XRB_WIDGET_HPP_)
00012 #define _XRB_WIDGET_HPP_
00013
00014 #include "xrb.hpp"
00015
00016 #include <string>
00017
00018 #include "xrb_color.hpp"
00019 #include "xrb_eventhandler.hpp"
00020 #include "xrb_framehandler.hpp"
00021 #include "xrb_rect.hpp"
00022 #include "xrb_rendercontext.hpp"
00023 #include "xrb_resourcelibrary.hpp"
00024 #include "xrb_screencoord.hpp"
00025 #include "xrb_signalhandler.hpp"
00026 #include "xrb_sizeproperties.hpp"
00027 #include "xrb_vector.hpp"
00028 #include "xrb_widgetskin.hpp"
00029 #include "xrb_widgetskinhandler.hpp"
00030
00036 namespace Xrb
00037 {
00038
00039 class ContainerWidget;
00040 class EventCustom;
00041 class EventDeleteChildWidget;
00042 class EventFocus;
00043 class EventJoy;
00044 class EventKey;
00045 class EventMouse;
00046 class EventMouseButton;
00047 class EventMouseMotion;
00048 class EventMouseWheel;
00049 class EventMouseover;
00050 class EventStateMachineInput;
00051 class Screen;
00052 class WidgetBackground;
00053
00097 class Widget : public WidgetSkinHandler, public FrameHandler, public EventHandler, public SignalHandler
00098 {
00099 public:
00100
00101
00102
00103
00104
00114 Widget (ContainerWidget *parent, std::string const &name = "Widget");
00119 virtual ~Widget ();
00120
00121
00122
00123
00124
00128 inline SignalReceiver1<bool> const *ReceiverSetIsEnabled () { return &m_receiver_set_is_enabled; }
00132 inline SignalReceiver0 const *ReceiverEnable () { return &m_receiver_enable; }
00136 inline SignalReceiver0 const *ReceiverDisable () { return &m_receiver_disable; }
00137
00141 inline SignalReceiver1<bool> const *ReceiverSetIsHidden () { return &m_receiver_set_is_hidden; }
00145 inline SignalReceiver0 const *ReceiverHide () { return &m_receiver_hide; }
00149 inline SignalReceiver0 const *ReceiverShow () { return &m_receiver_show; }
00150
00151
00152
00153
00154
00157 inline std::string const &Name () const { return m_name; }
00160 inline ContainerWidget const *Parent () const { return m_parent; }
00163 inline ContainerWidget *Parent () { return m_parent; }
00172 ContainerWidget const *EffectiveParent () const;
00181 ContainerWidget *EffectiveParent ();
00185 Screen const *TopLevelParent () const;
00189 Screen *TopLevelParent ();
00193 inline bool IsTopLevelParent () const { return m_parent == NULL; }
00197 bool IsFocused () const;
00203 inline bool AcceptsFocus () const { return m_accepts_focus; }
00208 bool IsMouseover () const;
00214 inline bool AcceptsMouseover () const { return m_accepts_mouseover; }
00219 bool IsMouseGrabbed () const;
00222 inline bool IsEnabled () const { return m_is_enabled; }
00225 inline bool IsHidden () const { return m_is_hidden; }
00228 inline bool IsModal () const { return m_is_modal; }
00232 inline StackPriority GetStackPriority () const { return m_stack_priority; }
00236 inline WidgetBackground *Background () const { return m_background; }
00239 inline ScreenCoordVector2 const &FrameMargins () const { return m_frame_margins; }
00245 inline ScreenCoordVector2 const &ContentMargins () const { return m_content_margins; }
00249 inline ScreenCoordVector2 const &LastMousePosition () const { return m_last_mouse_position; }
00253 inline ScreenCoordVector2 Position () const { return m_screen_rect.BottomLeft(); }
00256 inline ScreenCoordVector2 Size () const { return m_screen_rect.Size(); }
00259 inline ScreenCoord Width () const { return m_screen_rect.Width(); }
00262 inline ScreenCoord Height () const { return m_screen_rect.Height(); }
00267 virtual Bool2 const &MinSizeEnabled () const { return m_size_properties.m_min_size_enabled; }
00271 virtual ScreenCoordVector2 const &MinSize () const { return m_size_properties.m_min_size; }
00276 virtual Bool2 const &MaxSizeEnabled () const { return m_size_properties.m_max_size_enabled; }
00280 virtual ScreenCoordVector2 const &MaxSize () const { return m_size_properties.m_max_size; }
00288 virtual ScreenCoordVector2 AdjustedSize (ScreenCoordVector2 const &size) const;
00291 inline ScreenCoordRect const &ScreenRect () const { return m_screen_rect; }
00297 inline ScreenCoordRect ContentsRect () const
00298 {
00299 return ScreenRect().Grown(-(FrameMargins() + ContentMargins()));
00300 }
00304 inline Color const &ColorBias () const { return m_color_bias; }
00308 inline Color const &ColorMask () const { return m_color_mask; }
00314 inline Color &ColorBias () { return m_color_bias; }
00319 inline Color &ColorMask () { return m_color_mask; }
00320
00321
00322
00323
00324
00342 virtual void SetSizePropertyEnabled (
00343 SizeProperties::Property property,
00344 Uint32 component,
00345 bool value,
00346 bool defer_parent_update = false);
00362 virtual void SetSizePropertyEnabled (
00363 SizeProperties::Property property,
00364 Bool2 const &value,
00365 bool defer_parent_update = false);
00383 virtual void SetSizeProperty (
00384 SizeProperties::Property property,
00385 Uint32 component,
00386 ScreenCoord value,
00387 bool defer_parent_update = false);
00403 virtual void SetSizeProperty (
00404 SizeProperties::Property property,
00405 ScreenCoordVector2 const &value,
00406 bool defer_parent_update = false);
00426 void SetSizePropertyRatio (
00427 SizeProperties::Property property,
00428 Uint32 component,
00429 Float ratio,
00430 bool defer_parent_update = false);
00450 void SetSizePropertyRatios (
00451 SizeProperties::Property property,
00452 FloatVector2 const &ratios,
00453 bool defer_parent_update = false);
00454
00460 void SetIsModal (bool is_modal);
00466 void SetStackPriority (StackPriority stack_priority);
00470 void SetBackground (WidgetBackground *background);
00474 void SetFrameMargins (ScreenCoordVector2 const &frame_margins);
00480 void SetFrameMarginRatios (FloatVector2 const &frame_margin_ratios);
00483 void SetContentMargins (ScreenCoordVector2 const &content_margins);
00489 void SetContentMarginRatios (FloatVector2 const &content_margin_ratios);
00490
00491
00492
00493
00494
00498 void FixSize (ScreenCoordVector2 const &size);
00503 void FixSizeRatios (FloatVector2 const &size_ratios);
00507 void UnfixSize ();
00511 void FixWidth (ScreenCoord width);
00516 void FixWidthRatio (Float width_ratio);
00520 void UnfixWidth ();
00525 void FixHeight (ScreenCoord height);
00530 void FixHeightRatio (Float height_ratio);
00534 void UnfixHeight ();
00535
00551 virtual void Draw (RenderContext const &render_context) const;
00556 void MoveTo (ScreenCoordVector2 const &position);
00560 virtual void MoveBy (ScreenCoordVector2 const &delta);
00579 virtual ScreenCoordVector2 Resize (ScreenCoordVector2 const &size);
00583 ScreenCoordVector2 ResizeByRatios (FloatVector2 const &ratios);
00588 ScreenCoordVector2 MoveToAndResize (ScreenCoordRect const &screen_rect);
00591 void CenterOnWidget (Widget const *widget);
00597 bool Focus ();
00601 void Unfocus ();
00606 void GrabMouse ();
00610 void UnGrabMouse ();
00614 void DetachFromParent ();
00615
00619 virtual void SetIsEnabled (bool is_enabled);
00622 inline void Enable () { SetIsEnabled(true); }
00626 inline void Disable () { SetIsEnabled(false); }
00627
00631 void ToggleIsHidden ();
00641 void SetIsHidden (bool is_hidden);
00645 inline void Hide () { SetIsHidden(true); }
00649 inline void Show () { SetIsHidden(false); }
00650
00651 protected:
00652
00656 virtual Uint32 WidgetSkinHandlerChildCount () const { return 0; }
00660 virtual WidgetSkinHandler *WidgetSkinHandlerChild (Uint32 index) { return NULL; }
00664 virtual WidgetSkinHandler *WidgetSkinHandlerParent ();
00665
00669 inline WidgetBackground const *RenderBackground () const { return m_render_background; }
00670
00673 inline void SetRenderBackground (WidgetBackground const *render_background) { m_render_background = render_background; }
00674
00677 void InitializeFromWidgetSkinProperties ();
00678
00688 virtual void HandleFrame () { }
00695 virtual bool HandleEvent (Event const *e);
00699 virtual bool ProcessKeyEvent (EventKey const *e) { return false; }
00703 virtual bool ProcessMouseButtonEvent (EventMouseButton const *e) { return false; }
00707 virtual bool ProcessMouseWheelEvent (EventMouseWheel const *e) { return false; }
00711 virtual bool ProcessMouseMotionEvent (EventMouseMotion const *e) { return false; }
00715 virtual bool ProcessJoyEvent (EventJoy const *e) { return false; }
00719 virtual bool ProcessStateMachineInputEvent (EventStateMachineInput const *e) { return false; }
00724 virtual bool ProcessCustomEvent (EventCustom const *e) { return false; }
00728 virtual bool ProcessDeleteChildWidgetEvent (EventDeleteChildWidget const *e);
00729
00734 virtual void HandleFocus () { }
00739 virtual void HandleUnfocus () { }
00745 virtual void HandleMouseoverOn () { }
00751 virtual void HandleMouseoverOff () { }
00756 virtual void HandleMouseGrabOn () { }
00762 virtual void HandleMouseGrabOff () { }
00772 virtual void HandleChangedBackground ();
00779 virtual void HandleChangedFrameMargins () { }
00786 virtual void HandleChangedContentMargins () { }
00787
00792 virtual void UpdateRenderBackground ();
00800 void ParentChildSizePropertiesUpdate (bool defer_parent_update);
00804 bool AdjustFromMinSize (ScreenCoordRect *screen_rect) const;
00808 bool AdjustFromMaxSize (ScreenCoordRect *screen_rect) const;
00812 void MinSizeUpdated ();
00816 void MaxSizeUpdated ();
00820 void SizeRangeAdjustment (ScreenCoordRect *rect) const;
00821
00825 SizeProperties m_size_properties;
00830 bool m_accepts_focus;
00835 bool m_accepts_mouseover;
00840 Color m_color_bias;
00846 Color m_color_mask;
00847
00848 private:
00849
00853 void FocusWidgetLine ();
00858 void UnfocusWidgetLine ();
00862 bool MouseoverOn ();
00865 void MouseoverOff ();
00869 void MouseoverOnWidgetLine ();
00873 void MouseoverOffWidgetLine ();
00877 virtual bool InternalProcessKeyEvent (EventKey const *e);
00881 virtual bool InternalProcessMouseEvent (EventMouse const *e);
00885 virtual bool InternalProcessJoyEvent (EventJoy const *e);
00888 virtual bool InternalProcessFocusEvent (EventFocus const *e);
00891 virtual bool InternalProcessMouseoverEvent (EventMouseover const *e);
00892
00896 std::string m_name;
00901 ContainerWidget *m_parent;
00904 bool m_is_enabled;
00908 bool m_enabled_sender_blocking_state;
00911 bool m_is_hidden;
00915 ScreenCoordRect m_screen_rect;
00918 ScreenCoordVector2 m_last_mouse_position;
00921 bool m_is_modal;
00926 StackPriority m_stack_priority;
00929 WidgetBackground *m_background;
00935 WidgetBackground const *m_render_background;
00939 ScreenCoordVector2 m_frame_margins;
00942 ScreenCoordVector2 m_content_margins;
00943
00944
00945
00946
00947
00951 SignalReceiver1<bool> m_receiver_set_is_enabled;
00954 SignalReceiver0 m_receiver_enable;
00957 SignalReceiver0 m_receiver_disable;
00958
00962 SignalReceiver1<bool> m_receiver_set_is_hidden;
00965 SignalReceiver0 m_receiver_hide;
00968 SignalReceiver0 m_receiver_show;
00969
00970
00971 friend class ContainerWidget;
00972 };
00973
00974 }
00975
00976 #endif // !defined(_XRB_WIDGET_HPP_)
00977