00001 #ifndef GUI_FRAME_HPP
00002 #define GUI_FRAME_HPP
00003
00004 #include <utils.hpp>
00005 #include "gui_region.hpp"
00006
00007 #include <set>
00008 #include <functional>
00009
00010 namespace gui
00011 {
00012 class backdrop;
00013
00015 struct layer
00016 {
00017 bool bDisabled;
00018 std::vector<layered_region*> lRegionList;
00019
00020 static layer_type get_layer_type(const std::string& sLayer);
00021 };
00022
00024
00027 class frame : public event_receiver, public region
00028 {
00029 public :
00030
00032 explicit frame(manager* pManager);
00033
00035 virtual ~frame();
00036
00038 virtual void render();
00039
00041 virtual void update(float fDelta);
00042
00044
00047 virtual std::string serialize(const std::string& sTab) const;
00048
00050
00053 virtual bool can_use_script(const std::string& sScriptName) const;
00054
00056 void check_position() const;
00057
00059
00061 virtual void copy_from(uiobject* pObj);
00062
00064
00066 void create_title_region();
00067
00069
00071 void disable_draw_layer(layer_type mLayerID);
00072
00074
00076 void enable_draw_layer(layer_type mLayerID);
00077
00079
00081 virtual void enable_keyboard(bool bIsKeyboardEnabled);
00082
00084
00087 virtual void enable_mouse(bool bIsMouseEnabled, bool bAllowWorldInput = false);
00088
00090
00092 virtual void enable_mouse_wheel(bool bIsMouseWheelEnabled);
00093
00095
00098 bool has_script(const std::string& sScriptName) const;
00099
00101
00103 void add_region(layered_region* pRegion);
00104
00106
00108 void remove_region(layered_region* pRegion);
00109
00111
00122 layered_region* create_region(layer_type mLayer, const std::string& sClassName,
00123 const std::string& sName, const std::string& sInheritance = "");
00124
00126
00136 frame* create_child(const std::string& sClassName, const std::string& sName, const std::string& sInheritance = "");
00137
00139
00141 void add_child(frame* pChild);
00142
00144
00146 void remove_child(frame* pChild);
00147
00149
00151 const std::map<uint, frame* >& get_children() const;
00152
00154
00157 frame* get_child(const std::string& sName) const;
00158
00160
00163 layered_region* get_region(const std::string& sName) const;
00164
00166
00168 float get_effective_alpha() const;
00169
00171
00173 float get_effective_scale() const;
00174
00176
00178 int get_frame_level() const;
00179
00181
00183 frame_strata get_frame_strata() const;
00184
00186
00188 utils::wptr<backdrop> get_backdrop() const;
00189
00191
00193 const std::string& get_frame_type() const;
00194
00196
00198 const std::array<int,4>& get_abs_hit_rect_insets() const;
00199
00201
00203 const std::array<float,4>& get_rel_hit_rect_insets() const;
00204
00206
00208 std::array<uint,2> get_max_resize() const;
00209
00211
00213 std::array<uint,2> get_min_resize() const;
00214
00216
00218 uint get_num_children() const;
00219
00221
00223 uint get_num_regions() const;
00224
00226
00230 float get_scale() const;
00231
00233 region* get_title_region() const;
00234
00236
00238 bool is_clamped_to_screen() const;
00239
00241
00245 virtual bool is_in_frame(int iX, int iY) const;
00246
00248
00250 bool is_keyboard_enabled() const;
00251
00253
00255 bool is_mouse_enabled() const;
00256
00258
00260 bool is_world_input_allowed() const;
00261
00263
00265 bool is_mouse_wheel_enabled() const;
00266
00268
00270 bool is_movable() const;
00271
00273
00275 bool is_resizable() const;
00276
00278
00280 bool is_top_level() const;
00281
00283
00285 bool is_user_placed() const;
00286
00288
00294 void define_script(const std::string& sScriptName, const std::string& sContent,
00295 const std::string& sFile, uint uiLineNbr);
00296
00297 typedef std::function<void(frame*, event*)> handler;
00298
00300
00303 void define_script(const std::string& sScriptName, handler mHandler);
00304
00306
00309 void notify_script_defined(const std::string& sScriptName, bool bDefined);
00310
00312
00315 virtual void on(const std::string& sScriptName, event* pEvent = nullptr);
00316
00318
00320 virtual void on_event(const event& mEvent);
00321
00323 void register_all_events();
00324
00326
00328 void register_event(const std::string& sEventName);
00329
00331
00333 void register_for_drag(const std::vector<std::string>& lButtonList);
00334
00336
00339 void set_clamped_to_screen(bool bIsClampedToScreen);
00340
00342
00344 void set_frame_strata(frame_strata mStrata);
00345
00347
00349 void set_frame_strata(const std::string& sStrata);
00350
00352
00354 void set_backdrop(utils::refptr<backdrop> pBackdrop);
00355
00357
00363 void set_abs_hit_rect_insets(int iLeft, int iRight, int iTop, int iBottom);
00364
00366
00372 void set_rel_hit_rect_insets(float fLeft, float fRight, float fTop, float fBottom);
00373
00375
00377 void set_level(int iLevel);
00378
00380
00383 void set_max_resize(uint uiMaxWidth, uint uiMaxHeight);
00384
00386
00389 void set_min_resize(uint uiMinWidth, uint uiMinHeight);
00390
00392
00394 void set_max_height(uint uiMaxHeight);
00395
00397
00399 void set_max_width(uint uiMaxWidth);
00400
00402
00404 void set_min_height(uint uiMinHeight);
00405
00407
00409 void set_min_width(uint uiMinWidth);
00410
00412
00414 void set_movable(bool bIsMovable);
00415
00417
00421 void set_parent(uiobject* pParent);
00422
00424
00426 void set_resizable(bool bIsResizable);
00427
00429
00431 void set_scale(float fScale);
00432
00434
00436 void set_top_level(bool bIsTopLevel);
00437
00439
00442 void raise();
00443
00445
00447 void set_user_placed(bool bIsUserPlaced);
00448
00450 void start_moving();
00451
00453 void stop_moving();
00454
00456
00458 void start_sizing(const anchor_point& mPoint);
00459
00461 void stop_sizing();
00462
00464
00467 virtual void show();
00468
00470
00473 virtual void hide();
00474
00476
00482 virtual void set_shown(bool bIsShown);
00483
00485
00494 virtual void set_manually_rendered(bool bManuallyRendered, uiobject* pRenderer = nullptr);
00495
00497
00499 virtual void set_abs_width(uint uiAbsWidth);
00500
00502
00504 virtual void set_abs_height(uint uiAbsHeight);
00505
00507
00514 virtual void notify_mouse_in_frame(bool bMouseInFrame, int iX, int iY);
00515
00517
00521 virtual void notify_child_strata_changed(frame* pChild);
00522
00524
00526 virtual void notify_renderer_need_redraw() const;
00527
00529
00531 virtual void notify_loaded();
00532
00534
00537 void fire_build_layer_list();
00538
00540 void unregister_all_events();
00541
00543
00545 void unregister_event(const std::string& sEventName);
00546
00548
00550 void set_addon(addon* pAddOn);
00551
00553
00557 addon* get_addon() const;
00558
00560
00564 virtual std::vector<uiobject*> clear_links();
00565
00567 virtual void create_glue();
00568
00570
00572 virtual void parse_block(xml::block* pBlock);
00573
00574 protected :
00575
00576
00577 virtual void parse_attributes_(xml::block* pBlock);
00578 virtual void parse_resize_bounds_block_(xml::block* pBlock);
00579 virtual void parse_title_region_block_(xml::block* pBlock);
00580 virtual void parse_backdrop_block_(xml::block* pBlock);
00581 virtual void parse_hit_rect_insets_block_(xml::block* pBlock);
00582 virtual void parse_layers_block_(xml::block* pBlock);
00583 virtual void parse_frames_block_(xml::block* pBlock);
00584 virtual void parse_scripts_block_(xml::block* pBlock);
00585
00586 virtual void notify_visible_(bool bTriggerEvents = true);
00587 virtual void notify_invisible_(bool bTriggerEvents = true);
00588 virtual void notify_strata_changed_();
00589
00590 virtual void notify_top_level_parent_(bool bTopLevel, frame* pParent);
00591
00592 void add_level_(int iAmount);
00593
00594 virtual void update_borders_() const;
00595
00596 struct script_info
00597 {
00598 std::string sFile;
00599 uint uiLineNbr;
00600 };
00601
00602 std::map<uint, frame*> lChildList_;
00603 std::map<uint, layered_region*> lRegionList_;
00604 std::map<layer_type, layer> lLayerList_;
00605 std::map<std::string, std::string> lDefinedScriptList_;
00606 std::map<std::string, script_info> lXMLScriptInfoList_;
00607 std::vector<std::string> lQueuedEventList_;
00608 std::set<std::string> lRegEventList_;
00609 std::set<std::string> lRegDragList_;
00610
00611 std::map<std::string, handler> lDefinedHandlerList_;
00612
00613 addon* pAddOn_;
00614
00615 int iLevel_;
00616
00617 frame_strata mStrata_;
00618 bool bIsTopLevel_;
00619 frame* pTopLevelParent_;
00620
00621 utils::refptr<backdrop> pBackdrop_;
00622
00623 bool bHasAllEventsRegistred_;
00624
00625 bool bIsKeyboardEnabled_;
00626 bool bIsMouseEnabled_;
00627 bool bAllowWorldInput_;
00628 bool bIsMouseWheelEnabled_;
00629 bool bIsMovable_;
00630 bool bIsClampedToScreen_;
00631 bool bIsResizable_;
00632 bool bIsUserPlaced_;
00633
00634 bool bBuildLayerList_;
00635
00636 std::array<int, 4> lAbsHitRectInsetList_;
00637 std::array<float,4> lRelHitRectInsetList_;
00638
00639 uint uiMinWidth_;
00640 uint uiMaxWidth_;
00641 uint uiMinHeight_;
00642 uint uiMaxHeight_;
00643
00644 float fScale_;
00645
00646 bool bMouseInFrame_;
00647 bool bMouseInTitleRegion_;
00648 int iMousePosX_, iMousePosY_;
00649
00650 region* pTitleRegion_;
00651
00652 frame* pParentFrame_;
00653
00654 std::vector<std::string> lMouseButtonList_;
00655 bool bMouseDragged_;
00656 };
00657
00661 class lua_frame : public lua_uiobject
00662 {
00663 public :
00664
00665 explicit lua_frame(lua_State* pLua);
00666 virtual ~lua_frame() {}
00667
00668 int _create_font_string(lua_State*);
00669 int _create_texture(lua_State*);
00670 int _create_title_region(lua_State*);
00671 int _disable_draw_layer(lua_State*);
00672 int _enable_draw_layer(lua_State*);
00673 int _enable_keyboard(lua_State*);
00674 int _enable_mouse(lua_State*);
00675 int _enable_mouse_wheel(lua_State*);
00676 int _get_backdrop(lua_State*);
00677 int _get_backdrop_border_color(lua_State*);
00678 int _get_backdrop_color(lua_State*);
00679 int _get_children(lua_State*);
00680 int _get_effective_alpha(lua_State*);
00681 int _get_effective_scale(lua_State*);
00682 int _get_frame_level(lua_State*);
00683 int _get_frame_strata(lua_State*);
00684 int _get_frame_type(lua_State*);
00685 int _get_hit_rect_insets(lua_State*);
00686 int _get_id(lua_State*);
00687 int _get_max_resize(lua_State*);
00688 int _get_min_resize(lua_State*);
00689 int _set_max_width(lua_State*);
00690 int _set_max_height(lua_State*);
00691 int _set_min_width(lua_State*);
00692 int _set_min_height(lua_State*);
00693 int _get_num_children(lua_State*);
00694 int _get_num_regions(lua_State*);
00695 int _get_scale(lua_State*);
00696 int _get_script(lua_State*);
00697 int _get_title_region(lua_State*);
00698 int _has_script(lua_State*);
00699 int _is_clamped_to_screen(lua_State*);
00700 int _is_frame_type(lua_State*);
00701 int _is_keyboard_enabled(lua_State*);
00702 int _is_mouse_enabled(lua_State*);
00703 int _is_mouse_wheel_enabled(lua_State*);
00704 int _is_movable(lua_State*);
00705 int _is_resizable(lua_State*);
00706 int _is_top_level(lua_State*);
00707 int _is_user_placed(lua_State*);
00708 int _on(lua_State*);
00709 int _raise(lua_State*);
00710 int _register_all_events(lua_State*);
00711 int _register_event(lua_State*);
00712 int _register_for_drag(lua_State*);
00713 int _set_backdrop(lua_State*);
00714 int _set_backdrop_border_color(lua_State*);
00715 int _set_backdrop_color(lua_State*);
00716 int _set_clamped_to_screen(lua_State*);
00717 int _set_frame_level(lua_State*);
00718 int _set_frame_strata(lua_State*);
00719 int _set_hit_rect_insets(lua_State*);
00720 int _set_max_resize(lua_State*);
00721 int _set_min_resize(lua_State*);
00722 int _set_movable(lua_State*);
00723 int _set_resizable(lua_State*);
00724 int _set_scale(lua_State*);
00725 int _set_script(lua_State*);
00726 int _set_top_level(lua_State*);
00727 int _set_user_placed(lua_State*);
00728 int _start_moving(lua_State*);
00729 int _start_sizing(lua_State*);
00730 int _stop_moving_or_sizing(lua_State*);
00731 int _unregister_all_events(lua_State*);
00732 int _unregister_event(lua_State*);
00733
00734 static const char className[];
00735 static const char* classList[];
00736 static Lunar<lua_frame>::RegType methods[];
00737
00738 protected :
00739
00740 frame* pFrameParent_;
00741 };
00742
00745 }
00746
00747 #endif