JNR
uiContainer.h
1 /*
2 
3 Jump'n'Run Engine
4 http://www.atanaslaskov.com/jnr/
5 
6 BSD LICENSE
7 Copyright (c) 2007-2013, Atanas Laskov
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 */
29 
31 
32 
39 
40 #define CUI_CONTAINER_MAX 64
41 
42 class uiContainer :
43  public uiWindow
44 {
45 protected:
46  //Controls
47  //uiWindow* m_arControls[CUI_CONTAINER_MAX];
48  //unsigned m_nCnt;
49  std::vector<uiWindow*> _vControls;
50 
51  //Border Textures
52  laTexture tbg;
53  laTexture tborder_h;
54  laTexture tborder_v;
55  laTexture tangle;
56 
57  laColor col;
58  laPoint3 ptShadowOffset;
59 
60  //Flags
61  M_BOOL _bDisplayBorders; // borders visible
62  M_BOOL _bMoveable; // dragging enabled
63  unsigned _nDragButton; // index of the drag button {0,1,2}
64 
65  static uiContainer* _pDrag; // are we currently dragging any window?
66  laPoint3 _ptDragOffset;
67 
68  // Handle different alignments
69  // called by load()
70  void loadAlignment(laFileParser *fp, uiWindow* pw);
71 
72 protected:
73 
74  // Internal construction method,
75  // called by create() and load()
76  virtual void init();
77 
78  //Draw borders
79  virtual void drawBorders();
80 
81 public:
84  /*uiHR caption_hr;*/
85 
87  void toggleBorders(M_BOOL bEnable){
88  _bDisplayBorders = bEnable;
89  _ptDecorationSize = bEnable ? laPoint3(tangle.w, tangle.h) : laPoint3();
90 
91  if(bEnable)caption.show(); else caption.hide();
92  }
93 
95  void toggleMoveable(M_BOOL bEnable, unsigned nButton=0){
96  _bMoveable = bEnable;
97  _nDragButton = nButton;
98  }
99 
101  // @{
102  uiContainer(void);
103  uiContainer(char* strFile);
104  ~uiContainer(void);
105  // @}
106 
107  // Create/destroy
108  virtual void create(laPoint3 pos, laPoint3 size);
109  void kill();
110 
111  // Child management
112  unsigned insert(uiWindow* pWnd); //< add child window
113  uiWindow* get(unsigned id); //< get child by ID
114  uiWindow* remove(unsigned id); //< remove child window
115 
116  // Reply & draw
117  virtual void reply();
118  virtual void draw();
119 
120  // Handle the movse movement event; Drag the window container
121  // if dragging is enabled
122  virtual void onMouseMove(laPoint3 ptRelativePos);
123  virtual void onUp(unsigned nButton);
124 
125  // File loading methods
126  // @{
127  virtual void load(char* strFile); //< load as a separate .cui file
128  virtual void load(class laFileParser *fp); //< load as a control embedded in a .cui file
129  // @}
130 
131  //Authomatic window placement with regard
132  //to this window
133  /*void MetricLeft(uiWindow *w) { w->move( _ptPos.x(), w->_ptPos.y()) }
134  void MetricCenter(uiWindow *w) w->move( laPoint3(_ptPos.x()+(_ptSize.x()-w->_ptSize.x())/2, w->_ptPos.y()) );
135  void MetricRight(uiWindow *w) w->move( laPoint3(_ptPos.x()+(_ptSize.x()-w->_ptSize.x()), w->_ptPos.y()) );
136 
137  void MetricTop(uiWindow *w) w->move( laPoint3(w->_ptPos.x(), _ptPos.y()) );
138  void MetricMiddle(uiWindow *w) w->move( laPoint3(w->_ptPos.x(), _ptPos.y()+(_ptSize.y()-(w->_ptSize.y()))/2) );
139  void MetricBottom(uiWindow *w) w->move( laPoint3(w->_ptPos.x(), _ptPos.y()+(_ptSize.y()-w->_ptSize.y())) );*/
140 };
141 
142 
void kill()
Discard window and all children.
GUI Container Window.
Definition: uiContainer.h:42
virtual void create(laPoint3 pos, laPoint3 size)
Create new empty window.
Definition: uiContainer.cpp:97
uiLabel caption
Caption.
Definition: uiContainer.h:83
virtual void draw()
Display the window.
2D Texture
Definition: laTexture.h:45
Base class for GUI windows.
Definition: uiWindow.h:45
laPoint3 _ptDecorationSize
Size of border elements; defaults to 0.
Definition: uiWindow.h:77
void toggleBorders(M_BOOL bEnable)
Toggle border visbility.
Definition: uiContainer.h:87
Text Label.
Definition: uiLabel.h:41
void toggleMoveable(M_BOOL bEnable, unsigned nButton=0)
Toggle moveable flag.
Definition: uiContainer.h:95
virtual void reply()
Handle input message.
File Parser.
Definition: laFileParser.h:41