UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ZPixelCoord.H
1 // ZPixelCoord.H $Revision: 1.11 $ $Date: 2003/12/28 14:38:34 $
2 
3 #if !defined __ZPixelCoord_H
4 
5 #define __ZPixelCoord_H
6 
7 
8 #include <mix/SortedAr.H>
9 #include <zm/ZTypes.h>
10 
11 
12 /*************************************************************
13  * Pixel hint of group
14  *************************************************************/
15 
16 enum ZSizeLimit
17 {
18  NoLimits, /* object may have any size */
19  MinSize, /* object must have minimum size or greater */
20  FixedSize /* object must have fixed size */
21 };
22 
23 struct ZPOwnHint
24 {
25  ZGroupId id; /* group id */
26 
27  ZSizeLimit kind; /* type of size limit */
28  int size; /* value of limit */
29 };
30 
31 struct ZPGroupHint : public ZPOwnHint
32 {
33  int c[2]; /* coords: c[0] <= c[1] */
34 
35  Logic linked; /* TRUE if group has linked */
36  ZGroupId linked_id; /* id of linked group */
37  int delta[2]; /* delta for computing this coords from
38  coords of linked group by addition */
39 
40  /* TRUE if group has been resized since last expose; FALSE --
41  coords may be changed without touching size */
42  Logic resized;
43 
44  /* TRUE if group has been moved since last expose; FALSE --
45  coords have the same value that have had after last expose */
46  Logic moved;
47 };
48 
49 
50 /*************************************************************
51  * Array of group hints
52  *************************************************************/
53 class ZPHintAr : public SortedAr
54 {
55 private:
56 
57  /* Returns index of group or -1 if is not found */
58  int group_index (ZGroupId gid) const;
59 
60 public:
61 
62  ZPHintAr (const ZPHintAr& hintar)
63  : SortedAr(hintar) {};
64  ZPHintAr (unsigned quant = DEFAULT_QUANT,
65  unsigned volume = START_VOLUME)
66  : SortedAr(sizeof(ZPGroupHint), quant, volume) {};
67 
68  /* Usual compare between two elements */
69  virtual Compar compare (const char* item1, const char* item2) const;
70 
71  /* Add one more group */
72  void add (const ZPGroupHint& item);
73 
74  /* Remove the group from hint array */
75  void remove_group (ZGroupId gid);
76 
77  /* Get reference at needed group */
78  ZPGroupHint& operator[] (ZGroupId gid) const
79  {return fetch(gid);}
80  ZPGroupHint& fetch (ZGroupId gid) const;
81 
82  /* Returns TRUE if group with gid is already exist */
83  Logic check (ZGroupId gid) const;
84 
85  /* Returns contents of group with index */
86  ZPGroupHint& group_body (unsigned index) const
87  {return *(ZPGroupHint*)item_ptr(index);}
88 
89  /* Print item for debug purpose */
90  virtual void print_item (unsigned i) const;
91 
92 };
93 
94 
95 /* Forward definition */
96 class ZPCoordMaster;
97 
98 
99 /*************************************************************
100  * Slave object with pixel coord grid
101  *************************************************************/
103 {
104 private:
105 
106  ZPOwnHint hint; /* own hints */
107 
108  ZPCoordMaster *master; /* pointer at own master */
109 
110 public:
111 
112  ZPCoordSlave (ZPCoordMaster *pMaster, ZGroupId gid);
113 
115  virtual~ZPCoordSlave ();
116 
117  /* Get group id */
118  ZGroupId group () const;
119 
120  /* Change group at new one */
121  void group (ZGroupId new_gid);
122 
123  /* Erase from group list -- before destructor */
124  void erase ();
125 
126  /* Get pixel coords of group */
127  void get_pc (int pc[2]) const;
128  int get_pc1 () const;
129  int get_pc2 () const;
130  int get_psize () const;
131 
132  /* Set natural coords of group */
133  void set_pc (int pc[2]);
134 
135  /* Answers TRUE if group of object has been resized */
136  Logic is_resized () const;
137 
138  /* Answers TRUE if group of object has been moved */
139  Logic is_moved () const;
140 
141  /* Size limitation */
142  ZSizeLimit get_limit (int* pValue = NULL) const;
143  void set_limit (ZSizeLimit limit_type, int limit_value);
144 
145  /* Link and unlink operations */
146  void link (ZGroupId id);
147  void unlink ();
148 
149  /* Get information about link */
150  Logic is_linked () const;
151  ZGroupId linked_group () const;
152 
153  /* Get delta of pointed group if it's linked */
154  void get_delta (int d[2]) const;
155 
156  /* Set delta for pointed group and negative delta for linked one */
157  void set_delta (int d[2]);
158 
159 };
160 
161 
162 #define PtrType ZPCoordSlave*
163 #define PtrAr ZPCSAr
164 #include <mix/PtrAr.H> /* ==> class ZPCSAr */
165 
166 /* Reserved id for unexist group */
167 #define BAD_GROUP_ID (-1)
168 
169 
175 {
176 public:
177 
180  ZPCoordMaster (const char* szName = NULL);
181  virtual ~ZPCoordMaster ();
182 
183  /* Get pixel coords of group */
184  void get_pc (ZGroupId gid, int pc[2]) const;
185  int get_pc1 (ZGroupId gid) const;
186  int get_pc2 (ZGroupId gid) const;
187  int get_psize (ZGroupId gid) const;
188 
189  /* Set pixel coords of group */
190  void set_pc (ZGroupId gid, int pc[2]);
191 
192  /* Add new slave into gid group */
193  void add_slave (ZPCoordSlave* pSlave);
194 
195  /* Add group if no such and do nothing if group exists */
196  void add_group (ZGroupId gid);
197 
198  /* Check for existent group id. Quicker than 0==slaves_count(). */
199  Logic is_group (ZGroupId gid) const;
200 
201  /* Get count of slaves in group */
202  unsigned slaves_count (ZGroupId gid);
203 
204  /* Erase some slave from groups list */
205  void erase_slave (ZPCoordSlave* pSlave);
206 
207  /* Answers TRUE if group of object has been resized */
208  Logic is_resized (ZGroupId gid) const;
209 
210  /* Answers TRUE if group of object has been moved */
211  Logic is_moved (ZGroupId gid) const;
212 
213  /* Get size limitation */
214  ZSizeLimit get_limit (ZGroupId gid, int* pValue = NULL) const;
215 
216  /* Two linked groups (group' and group'') have associated
217  coords by rule:
218  c' = c'' + delta';
219  c'' = c' + delta'',
220  where
221  c': c'[0], c'[1],
222  c'': c''[0], c''[1],
223  so delta' = - delta'' */
224  Logic is_linked (ZGroupId gid) const;
225  ZGroupId linked_group (ZGroupId gid) const;
226  void link (ZGroupId gid1, ZGroupId gid2);
227 
228  /* Get delta of pointed group if it's linked */
229  void get_delta (ZGroupId gid, int d[2]) const;
230 
231  /* Set delta for pointed group and negative delta for linked one */
232  void set_delta (ZGroupId gid, int d[2]);
233 
234  /*
235  * Refresh operations: makes group array up-to-date.
236  */
237 
238  /* Recomputes group size limitations */
239  void relimit ();
240 
241  /* As if expose has been done */
242  void redrawn ();
243 
244 private:
245 
246  char *name;
247  char *spy_env;
248  Logic spy;
250  ZPHintAr *group;
251  ZPCSAr *slave;
253  /* Add slave's limitation for pointed group */
254  void add_limit (ZPGroupHint* pGroup,
255  ZPCoordSlave* pSlave);
256 
257 };
258 
259 
260 #endif // ZPixelCoord.H
ZPCoordMaster(const char *szName=NULL)
Definition: SortedAr.H:14
Definition: ZPixelCoord.H:31
Definition: ZPixelCoord.H:53
Definition: ZPixelCoord.H:102
Definition: ZPixelCoord.H:23
virtual ~ZPCoordSlave()
Definition: ZPixelCoord.H:174