source: liacs/MIR2010/SourceCode/cximage/ximalyr.cpp@ 196

Last change on this file since 196 was 95, checked in by Rick van der Zwet, 15 years ago

Bad boy, improper move of directory

File size: 3.0 KB
Line 
1// xImaLyr.cpp : Layers functions
2/* 21/04/2003 v1.00 - Davide Pizzolato - www.xdp.it
3 * CxImage version 6.0.0 02/Feb/2008
4 */
5
6#include "ximage.h"
7
8#if CXIMAGE_SUPPORT_LAYERS
9
10////////////////////////////////////////////////////////////////////////////////
11/**
12 * If the object is an internal layer, GetParent return its parent in the hierarchy.
13 */
14CxImage* CxImage::GetParent() const
15{
16 return info.pParent;
17}
18////////////////////////////////////////////////////////////////////////////////
19/**
20 * Number of layers allocated directly by the object.
21 */
22long CxImage::GetNumLayers() const
23{
24 return info.nNumLayers;
25}
26////////////////////////////////////////////////////////////////////////////////
27/**
28 * Creates an empty layer. If position is less than 0, the new layer will be placed in the last position
29 */
30bool CxImage::LayerCreate(long position)
31{
32 if ( position < 0 || position > info.nNumLayers ) position = info.nNumLayers;
33
34 CxImage** ptmp = new CxImage*[info.nNumLayers + 1];
35 if (ptmp==0) return false;
36
37 int i=0;
38 for (int n=0; n<info.nNumLayers; n++){
39 if (position == n){
40 ptmp[n] = new CxImage();
41 i=1;
42 }
43 ptmp[n+i]=ppLayers[n];
44 }
45 if (i==0) ptmp[info.nNumLayers] = new CxImage();
46
47 if (ptmp[position]){
48 ptmp[position]->info.pParent = this;
49 } else {
50 free(ptmp);
51 return false;
52 }
53
54 info.nNumLayers++;
55 delete [] ppLayers;
56 ppLayers = ptmp;
57 return true;
58}
59////////////////////////////////////////////////////////////////////////////////
60/**
61 * Deletes a layer. If position is less than 0, the last layer will be deleted
62 */
63bool CxImage::LayerDelete(long position)
64{
65 if ( position >= info.nNumLayers ) return false;
66 if ( position < 0) position = info.nNumLayers - 1;
67 if ( position < 0) return false;
68
69 if (info.nNumLayers>1){
70
71 CxImage** ptmp = new CxImage*[info.nNumLayers - 1];
72 if (ptmp==0) return false;
73
74 int i=0;
75 for (int n=0; n<info.nNumLayers; n++){
76 if (position == n){
77 delete ppLayers[n];
78 i=1;
79 }
80 ptmp[n]=ppLayers[n+i];
81 }
82
83 info.nNumLayers--;
84 delete [] ppLayers;
85 ppLayers = ptmp;
86
87 } else {
88 delete ppLayers[0];
89 delete [] ppLayers;
90 ppLayers = 0;
91 info.nNumLayers = 0;
92 }
93 return true;
94}
95////////////////////////////////////////////////////////////////////////////////
96void CxImage::LayerDeleteAll()
97{
98 if (ppLayers) {
99 for(long n=0; n<info.nNumLayers;n++){ delete ppLayers[n]; }
100 delete [] ppLayers; ppLayers=0; info.nNumLayers = 0;
101 }
102}
103////////////////////////////////////////////////////////////////////////////////
104/**
105 * Returns a pointer to a layer. If position is less than 0, the last layer will be returned
106 */
107CxImage* CxImage::GetLayer(long position)
108{
109 if ( ppLayers == NULL) return NULL;
110 if ( info.nNumLayers == 0) return NULL;
111 if ( position >= info.nNumLayers ) return NULL;
112 if ( position < 0) position = info.nNumLayers - 1;
113 return ppLayers[position];
114}
115////////////////////////////////////////////////////////////////////////////////
116#endif //CXIMAGE_SUPPORT_LAYERS
Note: See TracBrowser for help on using the repository browser.