C++SDK  1.0.0
annotationdefines.h
浏览该文件的文档.
1 #ifndef RT_AnnotationDefines_H_
2 #define RT_AnnotationDefines_H_
3 
4 #include "common.h"
6 
7 namespace rtcimp {
8 #ifndef LOG_FONT_FACE_NAME_SIZE
9 #define LOG_FONT_FACE_NAME_SIZE 32
10 #endif
11 
12 #ifndef DEFAULT_LINE_WIDTH
13 #define DEFAULT_LINE_WIDTH 1
14 #endif
15 #ifndef DEFAULT_LINE_COLOR
16 #define DEFAULT_LINE_COLOR 0xFF000000
17 #endif
18 #ifndef DEFAULT_BGROUNG_COLOR
19 #define DEFAULT_BGROUNG_COLOR 0xFF0000FF
20 #endif
21 #ifndef DEFAULT_FILL_COLOR
22 #define DEFAULT_FILL_COLOR 0xFF000000
23 #endif
24 
25  typedef struct tagLOGFONTA {
26  long lfHeight;
27  long lfWidth;
30  long lfWeight;
31  char lfItalic;
34  char lfCharSet;
37  char lfQuality;
40  }LogFont;
41 
42  static bool CalculateCheckMarkPoints(Point& pt1, Point& pt2, Point aPoints[]) {
43  aPoints[0].x = pt1.x;
44  aPoints[0].y = pt1.y + (pt2.y - pt1.y)*2.0 / 3.0;
45  aPoints[1].x = (pt1.x + pt2.x) / 2;
46  aPoints[1].y = pt2.y;
47  aPoints[2].x = pt2.x;
48  aPoints[2].y = pt1.y;
49  return true;
50  }
51  using tee3::avd::WindowId;
52  using tee3::avd::DesktopId;
55  class AVDContext {
56  public:
62 
63  virtual void setDrawWindowId(const WindowId& id) { draw_window_id_ = id; }
64  virtual void setDisplayWindowId(const WindowId& id) { display_window_id_ = id; }
65  virtual void setLineWidth(int width) { line_width_ = width; }
66  virtual void setLineColor(const Color& color) { line_color_ = color; }
67  virtual void setFillColor(const Color& color) { fill_color_ = color; }
68  virtual void setLineArrow(const LineArrowType& arrow) { line_arrow_ = arrow; }
69  virtual void setDisplayRect(const Rect& rc) { display_rect_ = rc; }
70  virtual void setAnnotationRect(const Rect& rc) { annotation_rect_ = rc; }
71  virtual void setZoomMode(bool isZoom) { zoom_ = isZoom; }
72  LineArrowType lineArrow() const { return line_arrow_; }
73  int lineWidth() const { return line_width_; }
74  int displayWidth() const {
75  int width = 0;
76  if (0 != annotation_rect_.width()) {
77  width = line_width_ * (double)display_rect_.width() / annotation_rect_.width() + 0.5;
78  }
79  else if (0 != annotation_rect_.height()) {
80  width = line_width_ * (double)display_rect_.height() / annotation_rect_.height() + 0.5;
81  }
82  if (0 == width) {
83  width = 1;
84  }
85  return width;
86  }
87  WindowId dispayWindowId() const { return display_window_id_; }
88  WindowId drawWindowId() const { return draw_window_id_; }
89  Color lineColor() const { return line_color_; }
90  Color fillColor() const { return fill_color_; }
91  Rect displayRect() const { return display_rect_; }
92  Rect annotationRect() const { return annotation_rect_; }
93  bool zoomMode()const { return zoom_; }
94  void clear() {
101  display_rect_ = Rect();
103  }
104 
105 
106  protected:
109  //not need initialize params
111  WindowId draw_window_id_;
116  bool zoom_;
117  };
118 
119  static uint32 AllSupportedTools() {
134  }
135 
136 
140  template<class ItemType, int GrowSize>
142  public:
144  m_head = NULL;
145  m_allocSize = 0;
146  m_usedSize = 0;
147  }
148 
149  EMArrayBaseT2(const EMArrayBaseT2& other) {
150  m_head = NULL;
151  m_allocSize = 0;
152  m_usedSize = 0;
153 
154  *this = other;
155  }
156 
157  virtual ~EMArrayBaseT2() {
158  RemoveAll();
159  }
160 
161  public:
162  int GetCount() {
163  return m_usedSize;
164  }
165 
166  bool Add(ItemType item, bool bCheckDuplicate = false) {
167  if (Expand()) {
168  if (bCheckDuplicate && GetIndex(item) >= 0)
169  return false;
170 
171  m_head[m_usedSize++] = item;
172  return true;
173  }
174  return false;
175  }
176 
177  bool InsertAt(int nIndex, ItemType item) {
178  if (nIndex >= 0 && nIndex <= m_usedSize) {
179  if (!Expand())
180  return false;
181 
182  if (nIndex < m_usedSize)
183  memmove(&m_head[nIndex + 1], &m_head[nIndex],
184  sizeof(ItemType)*(m_usedSize - nIndex));
185 
186  m_head[nIndex] = item;
187  m_usedSize++;
188 
189  return true;
190  }
191  return false;
192  }
193 
194  bool Remove(ItemType item) {
195  int i = 0;
196  for (; i < m_usedSize; i++) {
197  if (Compare(m_head + i, &item)) {
198  break;
199  }
200  }
201 
202  if (i < m_usedSize) {
203  // found
204  if (i < m_usedSize - 1)
205  memcpy(&m_head[i], &m_head[i + 1],
206  sizeof(ItemType)*(m_usedSize - i - 1));
207  m_usedSize--;
208  return true;
209  }
210 
211  return false;
212  }
213 
214  bool RemoveAt(int i) {
215  if (i < m_usedSize) {
216  if (i < m_usedSize - 1)
217  memcpy(&m_head[i], &m_head[i + 1],
218  sizeof(ItemType)*(m_usedSize - i - 1));
219  m_usedSize--;
220  return true;
221  }
222  return false;
223  }
224 
225  void RemoveAll() {
226  if (m_head)
227  delete[]m_head;
228  m_head = NULL;
229  m_allocSize = 0;
230  m_usedSize = 0;
231  }
232 
234  RemoveAll();
235 
236  if (other.m_usedSize > 0) {
237  m_head = new ItemType[other.m_usedSize];
238  if (m_head) {
239  memcpy(m_head, other.m_head, sizeof(ItemType)*other.m_usedSize);
241  }
242  }
243 
244  return *this;
245  }
246 
247  ItemType operator [](int i) {
248  RT_ASSERTE(m_head != NULL);
249  ItemType retVal;
250  if (i >= 0 && i < m_usedSize) {
251  retVal = m_head[i];
252  }
253  return retVal;
254  }
255 
256  bool SetAt(int nIndex, ItemType item) {
257  RT_ASSERTE(nIndex >= 0 && nIndex < m_usedSize);
258 
259  if (nIndex >= 0 && nIndex < m_usedSize) {
260  m_head[nIndex] = item;
261 
262  return true;
263  }
264 
265  return false;
266  }
267 
268  int GetIndex(ItemType item) {
269  for (int i = 0; i < m_usedSize; i++) {
270  if (Compare(m_head + i, &item))
271  return i;
272  }
273 
274  return -1;
275  }
276 
277  ItemType* GetHead() {
278  return m_head;
279  }
280 
281  protected:
282  bool Compare(ItemType* item1, ItemType* item2) {
283  if (memcmp(item1, item2, sizeof(ItemType)) == 0)
284  return true;
285 
286  return false;
287  }
288 
289  bool Expand() {
290  if (m_usedSize >= m_allocSize) {
291  ItemType* ppNew = new ItemType[m_allocSize + GrowSize];
292  if (ppNew) {
293  if (m_head) {
294  memcpy(ppNew, m_head, sizeof(ItemType)*m_allocSize);
295  delete[]m_head;
296  }
297  m_head = ppNew;
298  m_allocSize += GrowSize;
299  return true;
300  }
301  return false;
302  }
303  return true;
304  }
305 
306  protected:
307  ItemType* m_head;
310  };
311  template<class ItemType, int GrowSize>
312  class EMArrayBaseT {
313  public:
315  m_ppHead = NULL;
316  m_nAlloc = 0;
317  m_nUsed = 0;
318  }
319 
320  EMArrayBaseT(const EMArrayBaseT& other) {
321  m_ppHead = NULL;
322  m_nAlloc = 0;
323  m_nUsed = 0;
324 
325  *this = other;
326  }
327 
328  virtual ~EMArrayBaseT() {
329  RemoveAll();
330  }
331 
332  public:
333  int GetCount() {
334  return m_nUsed;
335  }
336 
337  bool Add(ItemType item, bool bCheckDuplicate = false) {
338  if (Expand()) {
339  if (bCheckDuplicate && GetIndex(item) >= 0)
340  return false;
341 
342  m_ppHead[m_nUsed++] = item;
343  return true;
344  }
345  return false;
346  }
347 
348  bool InsertAt(int nIndex, ItemType item, bool bCheckDuplicate = false) {
349  if (bCheckDuplicate && GetIndex(item) >= 0)
350  return false;
351 
352  if (nIndex >= 0 && nIndex <= m_nUsed) {
353  if (!Expand())
354  return false;
355 
356  if (nIndex < m_nUsed)
357  memmove(&m_ppHead[nIndex + 1], &m_ppHead[nIndex],
358  sizeof(ItemType)*(m_nUsed - nIndex));
359 
360  m_ppHead[nIndex] = item;
361  m_nUsed++;
362 
363  return true;
364  }
365  return false;
366  }
367 
368  bool Remove(ItemType item) {
369  int i = 0;
370  for (i = 0; i < m_nUsed; i++) {
371  if (Compare(m_ppHead + i, &item)) {
372  break;
373  }
374  }
375 
376  if (i < m_nUsed) {
377  // found
378  if (i < m_nUsed - 1)
379  memcpy(&m_ppHead[i], &m_ppHead[i + 1],
380  sizeof(ItemType)*(m_nUsed - i - 1));
381  m_nUsed--;
382  return true;
383  }
384 
385  return false;
386  }
387 
388  bool RemoveAt(int i) {
389  if (i < m_nUsed) {
390  if (i < m_nUsed - 1)
391  memcpy(&m_ppHead[i], &m_ppHead[i + 1],
392  sizeof(ItemType)*(m_nUsed - i - 1));
393  m_nUsed--;
394  return true;
395  }
396  return false;
397  }
398 
399  void RemoveAll() {
400  if (m_ppHead)
401  delete[]m_ppHead;
402  m_ppHead = NULL;
403  m_nAlloc = 0;
404  m_nUsed = 0;
405  }
406 
408  RemoveAll();
409 
410  if (other.m_nUsed > 0) {
411  m_ppHead = new ItemType[other.m_nUsed];
412  if (m_ppHead) {
413  memcpy(m_ppHead, other.m_ppHead, sizeof(ItemType)*other.m_nUsed);
414  m_nAlloc = m_nUsed = other.m_nUsed;
415  }
416  }
417 
418  return *this;
419  }
420 
421  ItemType operator [](int i) {
422  ItemType retVal = NULL;
423 
424  if (i >= 0 && i < m_nUsed) {
425  retVal = m_ppHead[i];
426  }
427 
428  return retVal;
429  }
430 
431  bool SetAt(int nIndex, ItemType item) {
432  if (nIndex >= 0 && nIndex < m_nUsed) {
433  m_ppHead[nIndex] = item;
434 
435  return true;
436  }
437 
438  return false;
439  }
440 
441  int GetIndex(ItemType item) {
442  switch (sizeof(ItemType)) {
443  case 4:
444  {
445  int dwItem = (int)item;
446  for (int i = 0; i < m_nUsed; i++) {
447  if (((int)m_ppHead[i]) == dwItem)
448  return i;
449  }
450  }
451  break;
452  case 2:
453  {
454  short wItem = (short)item;
455  for (int i = 0; i < m_nUsed; i++) {
456  if (((short)m_ppHead[i]) == wItem)
457  return i;
458  }
459  }
460  break;
461  case 1:
462  {
463  char cbItem = (char)item;
464  for (int i = 0; i < m_nUsed; i++) {
465  if (((char)m_ppHead[i]) == cbItem)
466  return i;
467  }
468  }
469  break;
470  default:
471  for (int i = 0; i < m_nUsed; i++) {
472  if (Compare(m_ppHead + i, &item))
473  return i;
474  }
475  break;
476  }
477 
478  return -1;
479  }
480 
481  ItemType* GetHead() {
482  return m_ppHead;
483  }
484 
485  protected:
486  bool Compare(ItemType* item1, ItemType* item2) {
487  if (memcmp(item1, item2, sizeof(ItemType)) == 0)
488  return true;
489 
490  return false;
491  }
492 
493  bool Expand() {
494  if (m_nUsed >= m_nAlloc) {
495  ItemType* ppNew = new ItemType[m_nAlloc + GrowSize];
496  if (ppNew) {
497  memset(ppNew, 0, (m_nAlloc + GrowSize)*sizeof(ItemType));
498 
499  if (m_ppHead) {
500  memcpy(ppNew, m_ppHead, sizeof(ItemType)*m_nAlloc);
501  delete[]m_ppHead;
502  }
503  m_ppHead = ppNew;
504  m_nAlloc += GrowSize;
505  return true;
506  }
507  return false;
508  }
509  return true;
510  }
511 
512  protected:
513  ItemType* m_ppHead;
514  int m_nAlloc;
515  int m_nUsed;
516  };
517  template <class ItemType>
519  public:
520  EMDynamicBuffer(uint32 nSize = 1024) {
521  m_pHead = NULL;
522  m_nSize = 0;
523  SetSize(nSize);
524  }
525 
527  Reset();
528  }
529 
530  void Reset() {
531  if (m_pHead)
532  delete[]m_pHead;
533  m_pHead = NULL;
534  m_nSize = 0;
535  }
536 
537  int GetSize() {
538  return m_nSize;
539  }
540 
541  bool SetSize(uint32 nSize) {
542  if (nSize > m_nSize) {
543  ItemType* pNewHead = new ItemType[nSize];
544  if (pNewHead) {
545  memset(pNewHead, 0, sizeof(ItemType)*nSize);
546  if (m_pHead) {
547  memcpy(pNewHead, m_pHead, sizeof(ItemType)*m_nSize);
548  delete[]m_pHead;
549  }
550 
551  m_pHead = pNewHead;
552  m_nSize = nSize;
553  return true;
554  }
555  return false;
556  }
557  return true;
558  }
559 
560  ItemType* GetHead() {
561  return m_pHead;
562  }
563  operator ItemType* () { return m_pHead; }
564 
565  protected:
566  ItemType* m_pHead;
568  };
569 }
570 #endif //RT_AnnotationDefines_H_
ItemType * m_head
Definition: annotationdefines.h:307
bool Compare(ItemType *item1, ItemType *item2)
Definition: annotationdefines.h:282
virtual void setFillColor(const Color &color)
Definition: annotationdefines.h:67
char lfOutPrecision
Definition: annotationdefines.h:35
int lineWidth() const
Definition: annotationdefines.h:73
char lfUnderline
Definition: annotationdefines.h:32
bool Expand()
Definition: annotationdefines.h:493
bool SetAt(int nIndex, ItemType item)
Definition: annotationdefines.h:431
EMArrayBaseT(const EMArrayBaseT &other)
Definition: annotationdefines.h:320
char lfCharSet
Definition: annotationdefines.h:34
Definition: annotationbasedefines.h:23
virtual void setDisplayWindowId(const WindowId &id)
Definition: annotationdefines.h:64
virtual ~EMArrayBaseT2()
Definition: annotationdefines.h:157
bool Add(ItemType item, bool bCheckDuplicate=false)
Definition: annotationdefines.h:337
int displayWidth() const
Definition: annotationdefines.h:74
Definition: common.h:490
EMDynamicBuffer(uint32 nSize=1024)
Definition: annotationdefines.h:520
int x
Definition: annotationbasedefines.h:12
static WindowId Cast(uint64 id)
Definition: common.h:412
WindowId drawWindowId() const
Definition: annotationdefines.h:88
~EMDynamicBuffer()
Definition: annotationdefines.h:526
EMArrayBaseT2(const EMArrayBaseT2 &other)
Definition: annotationdefines.h:149
bool Expand()
Definition: annotationdefines.h:289
Rect displayRect() const
Definition: annotationdefines.h:91
#define LOG_FONT_FACE_NAME_SIZE
Definition: annotationdefines.h:9
virtual void setDrawWindowId(const WindowId &id)
Definition: annotationdefines.h:63
Definition: annotationdefines.h:312
Definition: annotationdefines.h:55
Rect annotationRect() const
Definition: annotationdefines.h:92
int GetSize()
Definition: annotationdefines.h:537
Definition: common.h:493
LineArrowType line_arrow_
Definition: annotationdefines.h:107
ItemType * GetHead()
Definition: annotationdefines.h:560
int height() const
Definition: annotationbasedefines.h:32
virtual void setZoomMode(bool isZoom)
Definition: annotationdefines.h:71
ItemType * m_ppHead
Definition: annotationdefines.h:513
bool RemoveAt(int i)
Definition: annotationdefines.h:214
EMArrayBaseT & operator=(const EMArrayBaseT &other)
Definition: annotationdefines.h:407
int GetCount()
Definition: annotationdefines.h:333
int m_usedSize
Definition: annotationdefines.h:309
Color lineColor() const
Definition: annotationdefines.h:89
Color fillColor() const
Definition: annotationdefines.h:90
int m_allocSize
Definition: annotationdefines.h:308
Rect annotation_rect_
Definition: annotationdefines.h:115
void clear()
Definition: annotationdefines.h:94
uint32 m_nSize
Definition: annotationdefines.h:567
ItemType * m_pHead
Definition: annotationdefines.h:566
unsigned int uint32
Definition: defines.h:393
int width() const
Definition: annotationbasedefines.h:31
bool InsertAt(int nIndex, ItemType item, bool bCheckDuplicate=false)
Definition: annotationdefines.h:348
char lfFaceName[LOG_FONT_FACE_NAME_SIZE]
Definition: annotationdefines.h:39
int GetCount()
Definition: annotationdefines.h:162
char lfQuality
Definition: annotationdefines.h:37
#define DEFAULT_LINE_WIDTH
Definition: annotationdefines.h:13
AVDContext()
Definition: annotationdefines.h:57
void Reset()
Definition: annotationdefines.h:530
char lfPitchAndFamily
Definition: annotationdefines.h:38
#define DEFAULT_LINE_COLOR
Definition: annotationdefines.h:16
virtual void setLineWidth(int width)
Definition: annotationdefines.h:65
bool RemoveAt(int i)
Definition: annotationdefines.h:388
Definition: common.h:483
bool SetAt(int nIndex, ItemType item)
Definition: annotationdefines.h:256
ItemType * GetHead()
Definition: annotationdefines.h:481
Definition: common.h:488
bool Remove(ItemType item)
Definition: annotationdefines.h:194
char lfItalic
Definition: annotationdefines.h:31
virtual void setDisplayRect(const Rect &rc)
Definition: annotationdefines.h:69
EMArrayBaseT()
Definition: annotationdefines.h:314
void RemoveAll()
Definition: annotationdefines.h:399
ItemType * GetHead()
Definition: annotationdefines.h:277
int line_width_
Definition: annotationdefines.h:108
int m_nUsed
Definition: annotationdefines.h:515
WindowId display_window_id_
Definition: annotationdefines.h:110
Definition: common.h:500
char lfStrikeOut
Definition: annotationdefines.h:33
EMArrayBaseT2()
Definition: annotationdefines.h:143
#define RT_ASSERTE(expr)
Definition: defines.h:242
bool Add(ItemType item, bool bCheckDuplicate=false)
Definition: annotationdefines.h:166
Definition: annotationbasedefines.h:41
int GetIndex(ItemType item)
Definition: annotationdefines.h:268
bool InsertAt(int nIndex, ItemType item)
Definition: annotationdefines.h:177
Definition: annotationbasedefines.h:7
virtual void setAnnotationRect(const Rect &rc)
Definition: annotationdefines.h:70
virtual void setLineColor(const Color &color)
Definition: annotationdefines.h:66
struct rtcimp::tagRect Rect
long lfWidth
Definition: annotationdefines.h:27
long lfWeight
Definition: annotationdefines.h:30
Definition: annotationdefines.h:141
char lfClipPrecision
Definition: annotationdefines.h:36
virtual ~EMArrayBaseT()
Definition: annotationdefines.h:328
Definition: common.h:492
Definition: common.h:494
ItemType operator[](int i)
Definition: annotationdefines.h:421
LineArrowType lineArrow() const
Definition: annotationdefines.h:72
LineArrowType
Definition: common.h:499
bool Remove(ItemType item)
Definition: annotationdefines.h:368
Definition: annotationdefines.h:518
virtual void setLineArrow(const LineArrowType &arrow)
Definition: annotationdefines.h:68
long lfHeight
Definition: annotationdefines.h:26
Definition: common.h:491
int y
Definition: annotationbasedefines.h:13
bool Compare(ItemType *item1, ItemType *item2)
Definition: annotationdefines.h:486
bool zoom_
Definition: annotationdefines.h:116
WindowId dispayWindowId() const
Definition: annotationdefines.h:87
Rect display_rect_
Definition: annotationdefines.h:114
#define DEFAULT_FILL_COLOR
Definition: annotationdefines.h:22
int GetIndex(ItemType item)
Definition: annotationdefines.h:441
bool SetSize(uint32 nSize)
Definition: annotationdefines.h:541
long lfEscapement
Definition: annotationdefines.h:28
Definition: common.h:489
Color line_color_
Definition: annotationdefines.h:112
WindowId draw_window_id_
Definition: annotationdefines.h:111
Definition: annotationbasedefines.h:11
Color fill_color_
Definition: annotationdefines.h:113
Definition: common.h:485
Definition: common.h:496
Definition: common.h:487
struct rtcimp::tagLOGFONTA LogFont
ItemType operator[](int i)
Definition: annotationdefines.h:247
bool zoomMode() const
Definition: annotationdefines.h:93
long lfOrientation
Definition: annotationdefines.h:29
Definition: common.h:484
EMArrayBaseT2 & operator=(const EMArrayBaseT2 &other)
Definition: annotationdefines.h:233
int m_nAlloc
Definition: annotationdefines.h:514
void RemoveAll()
Definition: annotationdefines.h:225
Definition: common.h:486
Definition: annotationdefines.h:25
Definition: common.h:495