File: grarray.cpp

package info (click to toggle)
paintlib 2.6.2-14
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 7,920 kB
  • ctags: 3,874
  • sloc: cpp: 25,209; sh: 10,605; ansic: 1,891; makefile: 120
file content (131 lines) | stat: -rw-r--r-- 2,142 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
/--------------------------------------------------------------------
|
|      $Id: grarray.cpp,v 1.4 2002/03/31 13:36:42 uzadow Exp $
|      Array of CGrItems
|
|      Contains an array of graphic items sorted by z-order. Deletes
|      elements when done.
|
|      Copyright (c) 1996-2002 Ulrich von Zadow
|
\--------------------------------------------------------------------
*/

#include "stdafx.h"
#include "grarray.h"
#include "gritem.h"

IMPLEMENT_DYNAMIC (CGrItemArray, CObArray);


CGrItemArray::CGrItemArray
    ()
{
}


CGrItemArray::~CGrItemArray ()
{
  Empty();
}


CGrItem * CGrItemArray::GetItem
    ( int i
    )
{
  return (CGrItem *) GetAt (i);
}


void CGrItemArray::Empty
    ()
{
  int i;

  for (i=0; i<GetSize(); i++)
  {
    delete GetAt(i);
  }
  RemoveAll();
}


int CGrItemArray::AddItem
    ( CGrItem * pItem,
      int Pos
    )
    // Typsichere Version von Add. Fgt Element an korrekter Position
    // ein. Falls Pos nicht angegeben wird, wird das Element nach
    // z-Order sortiert eingefgt.
{
  if (Pos == -1)
    return sortedInsert (pItem);
  else
  {
    InsertAt (Pos, pItem);
    return Pos;
  }
}



void CGrItemArray::Draw
    ( PLBmp * pCanvas,
      CRect * pRect
    )
{
  int i;

  for (i=0; i<GetSize(); i++)
    GetItem(i)->Draw (pCanvas, pRect);
}


void CGrItemArray::GetRect
    ( CRect * pRect
    )
{
  int i;
  CRect ItemRect;

  *pRect = CRect (0,0,0,0);

  for (i=0; i<GetSize(); i++)
  {
    GetItem(i)->GetRect (&ItemRect);
    pRect->UnionRect (pRect, &ItemRect);
  }
}


int CGrItemArray::sortedInsert
    ( CGrItem * pItem
    )
{
  int i;
  int z = pItem->m_z;
  for (i=0; i<GetSize(); i++)
  {
    if (GetItem(i)->m_z > z)
    {
      InsertAt (i, pItem);
      return i;
    }
  }
  return Add (pItem);
}
/*
/--------------------------------------------------------------------
|
|      $Log: grarray.cpp,v $
|      Revision 1.4  2002/03/31 13:36:42  uzadow
|      Updated copyright.
|
|      Revision 1.3  2001/09/16 19:03:23  uzadow
|      Added global name prefix PL, changed most filenames.
|
|
--------------------------------------------------------------------
*/