00001 #ifndef GUI_UIOBJECT_HPP
00002 #define GUI_UIOBJECT_HPP
00003
00004 #include <utils.hpp>
00005 #include "gui_anchor.hpp"
00006 #include "gui_manager.hpp"
00007 #include <luapp_state.hpp>
00008 #include "gui_vector2.hpp"
00009 #include <xml.hpp>
00010
00011 #include <array>
00012
00013 namespace gui
00014 {
00015 class lua_glue;
00016
00017 enum border_type
00018 {
00019 BORDER_LEFT = 0,
00020 BORDER_RIGHT = 1,
00021 BORDER_TOP = 2,
00022 BORDER_BOTTOM = 3
00023 };
00024
00025 enum layer_type
00026 {
00027 LAYER_BACKGROUND,
00028 LAYER_BORDER,
00029 LAYER_ARTWORK,
00030 LAYER_OVERLAY,
00031 LAYER_HIGHLIGHT,
00032 LAYER_SPECIALHIGH
00033 };
00034
00036
00045 class uiobject
00046 {
00047 friend manager;
00048 public :
00049
00051 explicit uiobject(manager* pManager);
00052
00054 virtual ~uiobject();
00055
00057 virtual void render() = 0;
00058
00060
00062 virtual void update_anchors();
00063
00065 virtual void update(float fDelta);
00066
00068
00071 virtual std::string serialize(const std::string& sTab) const;
00072
00074
00076 virtual void copy_from(uiobject* pObj);
00077
00079 virtual void fire_update_borders() const;
00080
00082 void fire_update_dimensions() const;
00083
00085
00087 const std::string& get_name() const;
00088
00090
00092 const std::string& get_lua_name() const;
00093
00095
00099 const std::string& get_raw_name() const;
00100
00102
00105 void set_name(const std::string& sName);
00106
00108
00111 virtual void set_parent(uiobject* pParent);
00112
00114
00116 const uiobject* get_parent() const;
00117
00119
00121 uiobject* get_parent();
00122
00124
00126 uiobject* get_base();
00127
00129
00132 void set_alpha(float fAlpha);
00133
00135
00137 float get_alpha() const;
00138
00140
00143 virtual void show();
00144
00146
00149 virtual void hide();
00150
00152
00158 virtual void set_shown(bool bIsShown);
00159
00161
00163 bool is_shown() const;
00164
00166
00168 virtual bool is_visible() const;
00169
00171
00173 virtual void set_abs_width(uint uiAbsWidth);
00174
00176
00178 virtual void set_abs_height(uint uiAbsHeight);
00179
00181
00183 bool is_width_absolute() const;
00184
00186
00188 bool is_height_absolute() const;
00189
00191
00195 void set_rel_width(float fRelWidth);
00196
00198
00202 void set_rel_height(float fRelHeight);
00203
00205
00210 uint get_abs_width() const;
00211
00213
00218 uint get_apparent_width() const;
00219
00221
00226 uint get_abs_height() const;
00227
00229
00234 uint get_apparent_height() const;
00235
00237
00239 float get_rel_width() const;
00240
00242
00244 float get_rel_height() const;
00245
00247
00249 const std::string& get_object_type() const;
00250
00252
00255 bool is_object_type(const std::string& sType) const;
00256
00258
00260 const std::vector<std::string>& get_object_typeList() const;
00261
00263
00265 int get_bottom() const;
00266
00268
00270 vector2<int> get_center() const;
00271
00273
00275 int get_left() const;
00276
00278
00280 int get_right() const;
00281
00283
00285 int get_top() const;
00286
00288
00290 const std::array<int,4>& get_borders() const;
00291
00293
00296 void clear_all_points();
00297
00299
00302 void set_all_points(uiobject* pObj);
00303
00305
00310 void set_all_points(const std::string& sObjName);
00311
00313
00319 void set_abs_point(anchor_point mPoint, const std::string& sParentName,
00320 anchor_point mRelativePoint, int iX = 0, int iY = 0);
00321
00323
00329 void set_rel_point(anchor_point mPoint, const std::string& sParentName,
00330 anchor_point mRelativePoint, float fX = 0, float fY = 0);
00331
00333
00335 void set_point(const anchor& mAnchor);
00336
00338
00341 bool depends_on(uiobject* pObj) const;
00342
00344
00346 uint get_num_point() const;
00347
00349
00352 anchor* modify_point(anchor_point mPoint);
00353
00355
00358 const anchor* get_point(anchor_point mPoint) const;
00359
00361
00363 const std::map<anchor_point, anchor>& get_point_list() const;
00364
00366
00369 void notify_anchored_object(uiobject* pObj, bool bAnchored) const;
00370
00372
00375 bool is_virtual() const;
00376
00378
00380 void set_virtual();
00381
00383
00385 uint get_id() const;
00386
00388
00391 void set_id(uint uiID);
00392
00394
00400 void set_special();
00401
00403
00406 bool is_special() const;
00407
00409
00416 virtual void set_manually_rendered(bool bManuallyRendered, uiobject* pRenderer = nullptr);
00417
00419
00422 bool is_manually_rendered() const;
00423
00425
00429 void set_newly_created();
00430
00432
00435 bool is_newly_created() const;
00436
00438
00440 virtual void notify_renderer_need_redraw() const;
00441
00443
00445 virtual void fire_redraw() const;
00446
00448
00454 void mark_for_copy(const std::string& sVariable);
00455
00457
00461 virtual std::vector<uiobject*> clear_links();
00462
00464
00466 std::map<uint, uiobject*> get_anchored_objects() const;
00467
00469 virtual void notify_loaded();
00470
00472
00474 manager* get_manager();
00475
00477
00479 const manager* get_manager() const;
00480
00482
00484 virtual void create_glue() = 0;
00485
00487 void remove_glue();
00488
00490
00492 virtual void push_on_lua(lua::state* pLua) const;
00493
00495
00497 virtual void parse_block(xml::block* pBlock) = 0;
00498
00499 protected :
00500
00501
00502 virtual void parse_size_block_(xml::block* pBlock);
00503 virtual void parse_anchor_block_(xml::block* pBlock);
00504
00505 void read_anchors_(float& iLeft, float& iRight, float& iTop, float& iBottom, float& iXCenter, float& iYCenter) const;
00506 void make_borders_(float& iMin, float& iMax, float iCenter, float iSize) const;
00507 virtual void update_borders_() const;
00508 virtual void update_dimensions_() const;
00509
00510 virtual void notify_manually_rendered_object_(uiobject* pObject, bool bManuallyRendered);
00511
00512 manager* pManager_;
00513
00514 std::string sName_;
00515 std::string sRawName_;
00516 std::string sLuaName_;
00517 uint uiID_;
00518 uiobject* pParent_;
00519 uiobject* pInheritance_;
00520 bool bSpecial_;
00521 bool bManuallyRendered_;
00522 bool bNewlyCreated_;
00523 uiobject* pRenderer_;
00524 bool bInherits_;
00525
00526 bool bVirtual_;
00527 bool bLoaded_;
00528 mutable bool bReady_;
00529
00530 std::vector<lua_glue*> lGlueList_;
00531 std::vector<std::string> lCopyList_;
00532
00533 std::vector<std::string> lType_;
00534
00535 std::map<anchor_point, anchor> lAnchorList_;
00536 std::vector<const uiobject*> lPreviousAnchorParentList_;
00537 std::array<bool, 4> lDefinedBorderList_;
00538 mutable std::array<int, 4> lBorderList_;
00539
00540 float fAlpha_;
00541 bool bIsShown_;
00542 bool bIsVisible_;
00543
00544 mutable bool bIsWidthAbs_;
00545 mutable bool bIsHeightAbs_;
00546 mutable uint uiAbsWidth_;
00547 mutable uint uiAbsHeight_;
00548 mutable float fRelWidth_;
00549 mutable float fRelHeight_;
00550
00551 mutable bool bUpdateAnchors_;
00552 mutable bool bUpdateBorders_;
00553 mutable bool bUpdateDimensions_;
00554
00555 mutable std::map<uint, uiobject*> lAnchoredObjectList_;
00556 };
00557
00561
00562 class lua_glue
00563 {
00564 public :
00565
00566 explicit lua_glue(lua_State* luaVM);
00567 virtual ~lua_glue();
00568
00569 virtual void notify_deleted() = 0;
00570
00571 int get_data_table(lua_State *L);
00572
00573 protected :
00574
00575 lua_State* pLua_;
00576 int iRef_;
00577 };
00578
00579
00580 class lua_virtual_glue : public lua_glue
00581 {
00582 public :
00583
00584 explicit lua_virtual_glue(lua_State* luaVM);
00585 virtual ~lua_virtual_glue();
00586
00587 virtual void notify_deleted();
00588
00589 int _mark_for_copy(lua_State*);
00590 int _get_base(lua_State*);
00591 int _get_name(lua_State*);
00592
00593 static const char className[];
00594 static const char* classList[];
00595 static Lunar<lua_virtual_glue>::RegType methods[];
00596
00597 protected :
00598
00599 uint uiID_;
00600 uiobject* pParent_;
00601 };
00602
00603
00604 class lua_uiobject : public lua_glue
00605 {
00606 public :
00607
00608 explicit lua_uiobject(lua_State* luaVM);
00609 virtual ~lua_uiobject();
00610
00611 virtual void notify_deleted();
00612
00613 uiobject* get_parent();
00614
00615
00616 int _get_alpha(lua_State*);
00617 int _get_name(lua_State*);
00618 int _get_object_type(lua_State*);
00619 int _is_object_type(lua_State*);
00620 int _set_alpha(lua_State*);
00621
00622 int _clear_all_points(lua_State*);
00623 int _get_base(lua_State*);
00624 int _get_bottom(lua_State*);
00625 int _get_center(lua_State*);
00626 int _get_height(lua_State*);
00627 int _get_left(lua_State*);
00628 int _get_num_point(lua_State*);
00629 int _get_parent(lua_State*);
00630 int _get_point(lua_State*);
00631 int _get_right(lua_State*);
00632 int _get_top(lua_State*);
00633 int _get_width(lua_State*);
00634 int _hide(lua_State*);
00635 int _is_shown(lua_State*);
00636 int _is_visible(lua_State*);
00637 int _set_all_points(lua_State*);
00638 int _set_height(lua_State*);
00639 int _set_parent(lua_State*);
00640 int _set_point(lua_State*);
00641 int _set_rel_point(lua_State*);
00642 int _set_width(lua_State*);
00643 int _show(lua_State*);
00644
00645 static const char className[];
00646 static const char* classList[];
00647 static Lunar<lua_uiobject>::RegType methods[];
00648
00649 protected :
00650
00651 bool check_parent_();
00652
00653 std::string sName_;
00654 uiobject* pParent_;
00655 };
00656
00659 }
00660
00661 #endif