ubit
uboxgeom.hpp
1 /************************************************************************
2  *
3  * uboxgeom.hpp: attributes for controlling UBox geometry
4  * Ubit GUI Toolkit - Version 6
5  * (C) 2009 | Eric Lecolinet | TELECOM ParisTech | http://www.enst.fr/~elc/ubit
6  *
7  * ***********************************************************************
8  * COPYRIGHT NOTICE :
9  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
10  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
11  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
12  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
13  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
14  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
15  * ***********************************************************************/
16 
17 #ifndef uboxgeom_hpp
18 #define uboxgeom_hpp 1
19 #include <ubit/uattr.hpp>
20 #include <ubit/ulength.hpp>
21 #include <ubit/ugeom.hpp>
22 namespace ubit {
23 
31  class UScale : public UAttr {
32  public:
33  UCLASS(UScale)
34 
35  UScale(float value = 1.);
37 
38  UScale(const UFloat&);
40 
41  operator float() const {return value;}
43 
44  UScale& operator=(float v) {set(v); return *this;}
45  UScale& operator=(const UFloat& v) {set(v); return *this;}
46  UScale& operator=(const UScale& v) {set(v.value); return *this;}
47 
48  bool operator==(float v) const {return v == value;}
49  bool operator==(const UFloat& v) const {return v == value;}
50  bool operator==(const UScale& v) const {return value == v.value;}
51 
52  virtual void set(float);
53  virtual void mult(float);
54  virtual void div(float);
55  virtual void update();
56 
57  private:
58  float value;
59  virtual void putProp(UUpdateContext*, UElem&);
60  };
61 
62  inline UScale& uscale(float v = 1.) {return *new UScale(v);}
64 
65  inline UScale& uscale(const UFloat& v) {return *new UScale(v);}
67 
68 
69  // ==================================================== Ubit Toolkit =========
91  class UPos : public UAttr, public UPosSpec {
92  public:
93  UCLASS(UPos)
94 
95  static const ULength::Modes TOP, LEFT, RIGHT, BOTTOM;
96 
97  UPos() : UPosSpec(0,0) {}
99 
100  UPos(ULength x, ULength y) : UPosSpec(x, y) {}
102 
103  UPos(const UPoint& p) : UPosSpec(p.x, p.y) {}
105 
106  UPos(const UPos& p) : UPosSpec(p.x, p.y) {}
108 
109  //UPos(const UStr& xSpec, const UStr& ySpec);
110  //creates a new position attribute.
111 
112  virtual ~UPos() {destructs();}
113 
114  const ULength& getX() const {return x;}
115  const ULength& getY() const {return y;}
116 
117  UPos& setX(const ULength& _x) {return set(_x, y);}
118  UPos& setY(const ULength& _y) {return set(x, _y);}
119 
120  virtual UPos& set(const ULength& x, const ULength& y);
121  UPos& operator=(const UPos& p) {return set(p.x, p.y);}
122  UPos& operator=(const UPoint& p) {return set(p.x, p.y);}
123 
124  virtual bool equals(const ULength& x, const ULength& y) const;
125  bool operator==(const UPos& p) const {return equals(p.x, p.y);}
126  bool operator==(const UPoint& p) const {return equals(p.x, p.y);}
127 
128  bool isFloating() const;
134  virtual bool is3Dpos() const {return false;}
136 
137  virtual void update();
138 
139  private:
140  friend class UView;
141  friend class UBox;
142  friend class UWin;
143  virtual void putProp(UUpdateContext*, UElem&);
144  virtual void addingTo(UChild&, UElem& parent);
145  virtual void removingFrom(UChild&, UElem& parent);
146  //NB: removingFrom() requires UPos to have a destructor.
147  };
148 
149  inline UPos& upos(const ULength& x, const ULength& y) {return *new UPos(x, y);}
151 
152  inline UPos& upos(const UPoint& p) {return *new UPos(p);}
154 
155 
156  // ==================================================== Ubit Toolkit =========
162  class UPosControl : public UAttr {
163  public:
164  UCLASS(UPosControl)
165 
166  UPosControl(UPos* = null);
167  ~UPosControl();
168 
169  UPosControl& setModel(UPos*);
170  UPosControl& changeCursor(bool state);
171  UPosControl& freezeX(bool state);
172  UPosControl& freezeY(bool state);
173 
174  // - - - impl - - - - -- - - - - - - - - - - - - - - - - - - - - - - -
175 #ifndef NO_DOC
176  protected:
177  static const int MARGIN = 5;
178  UPoint box_pos0, pt_in_pane0;
179  bool change_cursor, freeze_x, freeze_y;
180  UView* moved_view;
181  uptr<UCall> callbacks;
182  uptr<UPos> posAttr;
183 
184  virtual void putProp(UUpdateContext*, UElem&) {}
185  virtual void addingTo(UChild&, UElem& parent);
186  virtual void removingFrom(UChild&, UElem& parent);
187  // NOTE that removingFrom() requires a destructor to be defined.
188 
189  virtual void mouseCB(UMouseEvent&);
190  virtual void pressCB(UMouseEvent&);
191  virtual void releaseCB(UMouseEvent&);
192  virtual void dragCB(UMouseEvent&);
193 #endif
194  };
195 
200  public:
201  UCLASS(UMagicLensControl)
202  UMagicLensControl(UPos* = null, UScrollpane* = null);
203  UMagicLensControl& setModel(UPos*, UScrollpane*);
204  private:
205  uptr<UScrollpane> pane;
206  virtual void dragCB(UMouseEvent&);
207  };
208 
209 
210  // ==================================================== Ubit Toolkit =========
228  class USize : public UAttr, public USizeSpec {
229  public:
230  UCLASS(USize)
231 
232  static const ULength INITIAL;
233  static const ULength::Modes UNRESIZABLE;
234 
235  USize() : USizeSpec(UIGNORE,UIGNORE) {}
237 
238  USize(ULength width, ULength height = UIGNORE) : USizeSpec(width, height) {}
240 
241  USize(const UDimension& d) : USizeSpec(d.width, d.height) {}
243 
244  USize(const USize& s) : USizeSpec(s) {}
246 
247  //UPos(const UStr& widthSpec, const UStr& heightSpec);
248  //creates a new position attribute.
249 
250  const ULength& getWidth() const {return width;}
251  const ULength& getHeight() const {return height;}
252 
253  USize& setWidth(const ULength& _w) {return set(_w, height);}
254  USize& setHeight(const ULength& _h) {return set(width, _h);}
255 
256  virtual USize& set(const ULength& width, const ULength& height);
257  USize& operator=(const USize& s) {return set(s.width, s.height);}
258  USize& operator=(const UDimension& d) {return set(d.width, d.height);}
259 
260  virtual bool equals(const ULength& w, const ULength& h) const;
261  bool operator==(const USize& s) const {return equals(s.width, s.height);}
262  bool operator==(const UDimension& d) const {return equals(d.width, d.height);}
263 
264  virtual void update();
265 
266  private:
267  virtual void putProp(UUpdateContext*, UElem&);
268  friend class UViewLayoutImpl;
269  };
270 
271  inline USize& usize() {return *new USize();}
273 
274  inline USize& usize(const ULength& w, const ULength& h =UIGNORE) {return *new USize(w,h);}
276 
277  inline USize& usize(const UDimension& d) {return *new USize(d);}
279 
280 
281  // ==================================================== Ubit Toolkit =========
287  class USizeControl : public UAttr {
288  public:
289  UCLASS(USizeControl)
290 
291  USizeControl(USize* = null);
292  ~USizeControl();
293 
294  USizeControl& setModel(USize*);
295  USizeControl& freezeWidth(bool state);
296  USizeControl& freezeHeight(bool state);
297 
298  // - - - impl - - - - -- - - - - - - - - - - - - - - - - - - - - - - -
299 #ifndef NO_DOC
300  virtual void putProp(UUpdateContext*, UElem&) {}
301  virtual void addingTo(UChild&, UElem& parent);
302  virtual void removingFrom(UChild&, UElem& parent);
303  // NOTE that removingFrom() requires a destructor to be defined.
304  protected:
305  float w0, h0;
306  float xev0, yev0;
307  bool freeze_w, freeze_h;
308  uptr<UCall> callbacks;
309  uptr<USize> psize;
310  virtual void mouseCB(UMouseEvent&);
311  virtual void pressCB(UMouseEvent&);
312  virtual void releaseCB(UMouseEvent&);
313  virtual void dragCB(UMouseEvent&);
314 #endif
315  };
316 
317 
318  // ==================================================== Ubit Toolkit =========
321  class UPadding : public UAttr {
322  public:
323  UCLASS(UPadding)
324 
325  UPadding() : val(UIGNORE,UIGNORE) {}
326  UPadding(ULength width, ULength height) : val(width, height) {}
327 
328  UPadding& operator=(const UPadding&);
329 
330  UPadding& setWidth(ULength);
332 
333  UPadding& setHeight(ULength);
335 
336  UPadding& setTop(ULength);
337  UPadding& setRight(ULength);
338  UPadding& setBottom(ULength);
339  UPadding& setLeft(ULength);
340 
341  ULength getTop() const {return val.top;}
342  ULength getRight() const {return val.right;}
343  ULength getBottom()const {return val.bottom;}
344  ULength getLeft() const {return val.left;}
345 
346  virtual void update();
347  private:
348  UPaddingSpec val;
349  virtual void putProp(UUpdateContext*, UElem&);
350  };
351 
352 
353  inline UPadding& upadding() {return *new UPadding();}
355 
356  inline UPadding& upadding(ULength horiz, ULength vert) {return *new UPadding(horiz,vert);}
358 
359 
360  // ==================================================== Ubit Toolkit =========
365  class UOrient : public UAttr {
366  public:
367  UCLASS(UOrient)
368 
369  static UOrient horizontal, vertical;
370 
371  UOrient();
373 
374  UOrient(const UOrient&);
376 
377  UOrient& operator=(const UOrient& v);
378  bool operator==(const UOrient& v) const {return value == v.value;}
379 
380  virtual void update();
381  virtual void putProp(UUpdateContext*, UElem&);
382 
383  // - impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
384 #ifndef NO_DOC
385  enum {HORIZONTAL=0, VERTICAL=1, INHERIT=2}; //dont change values
386  void addingTo(UChild&, UElem& parent);
387  void removingFrom(UChild&, UElem& parent);
388  private:
389  char value;
390  UOrient(char value, UConst);
391 #endif
392  };
393 
394  inline UOrient& uorient(const UOrient& val) {return *new UOrient(val);}
396 
397 
398  // ==================================================== Ubit Toolkit =========
412  class UHalign : public UAttr {
413  public:
414  UCLASS(UHalign)
415 
416  static UHalign left, right, flex, center;
417 
418  UHalign();
420 
421  UHalign(const UHalign&);
423 
424  UHalign& operator=(const UHalign&);
425  bool operator==(const UHalign& v) const {return value == v.value;}
426 
427  virtual void update();
428  virtual void putProp(UUpdateContext*, UElem&);
429 
430  // - impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
431  enum {INHERIT, LEFT, RIGHT, FLEX, CENTER};
432  private:
433  char value;
434  UHalign(char value, UConst);
435  };
436 
437 
438  inline UHalign& uhalign(const UHalign& val) {return *new UHalign(val);}
440 
441  inline UHalign& uleft() {return UHalign::left;}
448  inline UHalign& uright() {return UHalign::right;}
455  inline UHalign& uhcenter() {return UHalign::center;}
462  inline UHalign& uhflex() {return UHalign::flex;}
471  // ==================================================== Ubit Toolkit =========
480  class UValign : public UAttr {
481  public:
482  UCLASS(UValign)
483 
484  static UValign top, bottom, flex, center;
485 
486  UValign();
488 
489  UValign(const UValign&);
491 
492  UValign& operator=(const UValign& v);
493  bool operator==(const UValign& v) const {return value == v.value;}
494 
495  virtual void update();
496  virtual void putProp(UUpdateContext*, UElem&);
497 
498  // - impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
499  enum {INHERIT, TOP, BOTTOM, FLEX, CENTER};
500  private:
501  char value;
502  UValign(char value, UConst);
503  };
504 
505  inline UValign& uvalign(const UValign& val) {return *new UValign(val);}
507 
508  inline UValign& utop() {return UValign::top;}
515  inline UValign& ubottom() {return UValign::bottom;}
522  inline UValign& uvcenter() {return UValign::center;}
529  inline UValign& uvflex() {return UValign::flex;}
538  // ==================================================== Ubit Toolkit =========
541  class UVspacing : public UAttr {
542  public:
543  UCLASS(UVspacing)
544 
545  static UVspacing none;
546 
547  UVspacing(float = 0);
548 
549  operator float() const {return value;}
551 
552  UVspacing& operator=(float);
553  UVspacing& operator=(const UVspacing&);
554 
555  bool operator==(float v) const {return value == v;}
556  bool operator==(const UVspacing& v) const {return value == v.value;}
557 
558  virtual void update();
559 
560  // - impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
561  enum {INHERIT = -1};
562  virtual void putProp(UUpdateContext*, UElem&);
563  private:
564  float value;
565  };
566 
567  inline UVspacing& uvspacing(float val = 0) {return *new UVspacing(val);}
569 
570  // ==================================================== Ubit Toolkit =========
573  class UHspacing : public UAttr {
574  public:
575  UCLASS(UHspacing)
576 
577  static UHspacing none;
578 
579  UHspacing(float = 0);
580 
581  operator float() const {return value;}
583 
584  UHspacing& operator=(float);
585  UHspacing& operator=(const UHspacing&);
586 
587  bool operator==(float v) const {return value == v;}
588  bool operator==(const UHspacing& v) const {return value == v.value;}
589 
590  virtual void update();
591 
592  // - impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
593  enum {INHERIT = -1};
594  virtual void putProp(UUpdateContext*, UElem&);
595  private:
596  float value;
597  };
598 
599  inline UHspacing& uhspacing(float val) {return *new UHspacing(val);}
601 
602 }
603 #endif
Base class for attributes.
Definition: uattr.hpp:97
2D Dimension.
Definition: ugeom.hpp:55
Widget position.
Definition: uboxgeom.hpp:91
Makes it possible to change the UPos of a Magic Lens interactively.
Definition: uboxgeom.hpp:199
virtual void removingFrom(UChild &, UElem &parent)
called when this object is removed from a parent (SEE DETAILS IF YOU REDEFINE THIS METHOD)...
Definition: unode.hpp:222
Definition: uobject.hpp:282
Box container.
Definition: ubox.hpp:64
2D Point.
Definition: ugeom.hpp:25
Size Control: interactive control of the size of a widget.
Definition: uboxgeom.hpp:287
Box vertical layout.
Definition: uboxgeom.hpp:480
USize()
creates a new size attribute with width=UAUTO and height=UAUTO.
Definition: uboxgeom.hpp:235
Length of positions (UPos), sizes (USize) and padding (UPadding)
Definition: ulength.hpp:59
virtual bool is3Dpos() const
returns true if this is a U3Dpos.
Definition: uboxgeom.hpp:134
USize(ULength width, ULength height=UIGNORE)
creates a new size attribute,
Definition: uboxgeom.hpp:238
Definition: ulength.hpp:135
virtual void update()
updates parents graphics.
Definition: uboxgeom.cpp:62
virtual void putProp(UUpdateContext *, UElem &)
[impl] changes corresponding value in the UUpdateContext
Definition: uboxgeom.hpp:184
UScale(float value=1.)
creates a new scale attribute; see also shortcut uscale().
Box horizontal spacing.
Definition: uboxgeom.hpp:573
virtual void addingTo(UChild &, UElem &parent)
called when this object is added to a parent.
Definition: unode.hpp:219
lightweight general purpose container.
Definition: uelem.hpp:44
USize(const USize &s)
creates a new size attribute.
Definition: uboxgeom.hpp:244
Smart Pointer for UObject instances (.
Definition: uobject.hpp:365
Box vertical spacing.
Definition: uboxgeom.hpp:541
Box padding.
Definition: ulength.hpp:150
UPos()
creates a new position attribute with x=0 and y=0.
Definition: uboxgeom.hpp:97
Widget Orientation.
Definition: uboxgeom.hpp:365
Position Control: interactive control of the position of a widget.
Definition: uboxgeom.hpp:162
A box with (optionnal) scrollbars that manages a viewport.
Definition: uscrollpane.hpp:37
virtual void destructs()
unlinks the object from its parents and destroys its children.
Definition: unode.cpp:56
Box horizontal layout.
Definition: uboxgeom.hpp:412
Box View.
Definition: uview.hpp:65
Definition: uupdatecontext.hpp:32
Definition: uhardfont.hpp:31
USize(const UDimension &d)
creates a new size attribute.
Definition: uboxgeom.hpp:241
Widget scale.
Definition: uboxgeom.hpp:31
Active Float.
Definition: unumber.hpp:140
Definition: ulength.hpp:142
Widget padding.
Definition: uboxgeom.hpp:321
Base class for windows and menus.
Definition: uwin.hpp:47
Definition: ulength.hpp:61
Definition: uviewImpl.hpp:123
virtual void putProp(UUpdateContext *, UElem &)
[impl] changes corresponding value in the UUpdateContext
Definition: uboxgeom.hpp:300
UPos(const UPos &p)
creates a new position attribute.
Definition: uboxgeom.hpp:106
Widget Size.
Definition: uboxgeom.hpp:228
UPos(const UPoint &p)
creates a new position attribute; see also shortcut upos().
Definition: uboxgeom.hpp:103
mouse events
Definition: uevent.hpp:172
[impl] Internal implementation of a child node.
Definition: uchild.hpp:23
UPos(ULength x, ULength y)
creates a new position attribute; see also shortcut upos(ULength x, ULength y).
Definition: uboxgeom.hpp:100