OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
celarray.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1992, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Definition of a bitmap Cel array class.
7//----------------------------------------------------------------------------
8
9#if !defined(OWL_CELARRAY_H)
10#define OWL_CELARRAY_H
11
12#include <owl/private/defs.h>
13#if defined(BI_HAS_PRAGMA_ONCE)
14# pragma once
15#endif
16
17#include <owl/gdiobjec.h>
18
19namespace owl {
20
21#include <owl/preclass.h>
22
23
24/// \addtogroup graphics
25/// @{
26/// \class TCelArray
27// ~~~~~ ~~~~~~~~~
28/// TCelArray is a horizontal array of cels (a unit of animation) created by slicing
29/// a portion of or an entire bitmap into evenly sized shapes. Gadgets such as
30/// buttons can use a TCelArray to save resource space. TCelArray's functions let
31/// you control the dimensions of each cel and determine if the cel can delete the
32/// bitmap.
33/// \image html bm92.BMP
34//
36 public:
37 // Constructors
38 //
40 TBitmap* bmp,
41 int numCels,
44 int numRows = 1,
46
47 TCelArray(const TDib& dib, int numCels, int numRows=1);
48 TCelArray(const TCelArray& src);
49 TCelArray(const TSize& size, uint flags, int init, int grow, int numRows = 1);
50
51 virtual ~TCelArray();
52
54 operator const TBitmap&() const;
55 operator TBitmap&();
56 // 'Get' accessors
57 //
58 TPoint Offset() const;
59 int NumCels() const;
60 int NumAllocCels() const;
61 int CurRow() const;
62 int NumRows() const;
63 TSize CelSize() const;
64 TPoint CelOffset(int cel) const;
65 TRect CelRect(int cel) const;
66 TRect operator [](int cel) const;
67
68 // 'Set' accessors
69 // !CQ not functional w/ ImageList.
70 //
71 void SetNumCels(int numCels);
72 void SetCelSize(TSize size);
73 void SetOffset(TPoint offs);
74 void SetNGrowBy(int growBy);
75 void SetCurRow(int raw);
76
77 // Manipulating cel images
78 //
79 int Add(const TBitmap& image);
80 int Add(const TCelArray& src, int index);
81
82 bool Remove(int index = -1);
83 bool RemoveAll();
84 bool Replace(int index, const TBitmap& image);
85 bool Replace(int index, const TCelArray& src, int srcidx);
86 TColor GetBkColor() const;
87 TColor SetBkColor(const TColor&);
88
89 bool BitBlt(int index, TDC& dc, int x, int y, uint32 rop = SRCCOPY);
90 bool StretchBlt(int index, TDC& dc, const TRect& dstRect, uint32 rop = SRCCOPY);
91
92 // not implemented functionality
93 bool BitBlt(int index, TDC&, int x, int y, int dx, int dy,
94 const TColor& bgClr, const TColor& fgClr);
95
97 TBitmap* Bitmap; ///< Main Cel bitmap
98 bool ShouldDelete; ///< Does this CelArray own the Bitmap?
99 TPoint Offs; ///< Offset within Bitmap of actual CelArray
100 int NCels; ///< Number of cels allocated in Bitmap
101 TSize CSize; ///< Size of one cel
102 int NGrowBy; ///< How much to grow the array by when full
103 TColor BkColor; ///< Background color used when image < cellsize
104 int NCelsUsed; ///< Numbers of cels currently in use
105 int NRows; ///< Number of rows existed in Bitmap
106 int NCurRow; ///< Current raw in Bitmap
107
108 private:
109 TPoint CelOffset(int cel, int row/*=-1*/) const;
110 TRect CelRect(int cel, int row/*=-1*/) const;
111 bool MaybeResize(int need);
112 bool Resize(int newCount);
113};
114/// @}
115
116#include <owl/posclass.h>
117
118
119//------------------------------------------------------------------------
120// Inline implementations
121//
122
123//
124/// Return the offset within the bitmap for the celarray.
125//
126inline TPoint TCelArray::Offset() const {
127 return Offs;
128}
129
130//
131/// Return the size of the celarray.
132//
133inline TSize TCelArray::CelSize() const {
134 return CSize;
135}
136
137//
138/// Returns the position of the upper left corner of a given cel from the current row,
139/// relative to the upper left corner of the bitmap.
140//
142 return CelOffset(cel,-1);
143}
144
145//
146/// Returns the upper left and lower right corner of a given cell from the current row,
147/// relative to the upper left corner of the bitmap.
148//
149inline TRect TCelArray::CelRect(int cel) const{
150 return CelRect(cel,-1);
151}
152
153//
154/// Return number of cels currently in this CelArray
155//
156inline int TCelArray::NumCels() const {
157 return NCelsUsed;
158}
159
160//
161/// Return number of cels allocated in this CelArray
162//
163inline int TCelArray::NumAllocCels() const{
164 return NCels;
165}
166
167//
168/// Return NCurRow, the current row in the bitmap.
169//
170inline int TCelArray::CurRow() const {
171 return NCurRow;
172}
173
174//
175/// Return NRows, the number of rows in this CelArray.
176//
177inline int TCelArray::NumRows() const {
178 return NRows;
179}
180
181//
182/// Retrieve the 'cel'th image from the celarray.
183//
185 return CelRect(cel);
186}
187
188//
189/// Set the number of cels within the celarary.
190//
192 NCels = numCels < 1 ? 1 : numCels;
193}
194
195//
196/// Sets NCurRow to row.
197//
198inline void TCelArray::SetCurRow(int row){
199 NCurRow = row;
200}
201
202//
203/// Sets the size of each cel in the array.
204/// They are all assumed to be the same.
205//
206inline void TCelArray::SetCelSize(TSize size) {
207 CSize = size;
208}
209
210//
211/// Set the increment by which the bitmap is resized
212//
214 NGrowBy = growBy;
215}
216
217//
218/// Set the offset within a bitmap for the start of the celarray.
219//
221 Offs = offs;
222}
223
224//
225/// Removes all the cels from the array by calling Remove(-1). Returns true if cels
226/// are removed; false otherwise.
227//
228inline bool TCelArray::RemoveAll() {
229 return Remove(-1);
230}
231
232//
233/// Return the image bitmap used by this CelArray
234//
235inline TCelArray::operator const TBitmap&() const {
236 return *Bitmap;
237}
238
239//
240/// Return the image bitmap used by this CelArray
241//
242inline TCelArray::operator TBitmap&() {
243 return *Bitmap;
244}
245
246//
247/// Get the current background color for this CelArray
248//
250 return BkColor;
251}
252
253//
254/// Set the current background color for this CelArray, returning the previous
255/// color.
256//
258 TColor obkColor = BkColor;
259 BkColor = color;
260 return obkColor;
261}
262
263
264} // OWL namespace
265
266#endif // OWL_CELARRAY_H
TBitmap is the GDI bitmap class derived from TGdiObject.
Definition gdiobjec.h:510
TCelArray is a horizontal array of cels (a unit of animation) created by slicing a portion of or an e...
Definition celarray.h:35
int NumRows() const
Return NRows, the number of rows in this CelArray.
Definition celarray.h:177
TSize CelSize() const
Return the size of the celarray.
Definition celarray.h:133
int CurRow() const
Return NCurRow, the current row in the bitmap.
Definition celarray.h:170
void SetNGrowBy(int growBy)
Set the increment by which the bitmap is resized.
Definition celarray.h:213
void SetCurRow(int raw)
Sets NCurRow to row.
Definition celarray.h:198
TPoint Offset() const
Return the offset within the bitmap for the celarray.
Definition celarray.h:126
void SetNumCels(int numCels)
Set the number of cels within the celarary.
Definition celarray.h:191
TColor SetBkColor(const TColor &)
Set the current background color for this CelArray, returning the previous color.
Definition celarray.h:257
void SetCelSize(TSize size)
Sets the size of each cel in the array.
Definition celarray.h:206
TRect operator[](int cel) const
Retrieve the 'cel'th image from the celarray.
Definition celarray.h:184
bool Remove(int index=-1)
Removes a cel from this CelArray.
Definition celarray.cpp:232
int NumCels() const
Return number of cels currently in this CelArray.
Definition celarray.h:156
int NumAllocCels() const
Return number of cels allocated in this CelArray.
Definition celarray.h:163
TColor GetBkColor() const
Get the current background color for this CelArray.
Definition celarray.h:249
void SetOffset(TPoint offs)
Set the offset within a bitmap for the start of the celarray.
Definition celarray.h:220
TPoint CelOffset(int cel) const
Returns the position of the upper left corner of a given cel from the current row,...
Definition celarray.h:141
bool RemoveAll()
Removes all the cels from the array by calling Remove(-1).
Definition celarray.h:228
TRect CelRect(int cel) const
Returns the upper left and lower right corner of a given cell from the current row,...
Definition celarray.h:149
Class wrapper for management of color values.
Definition color.h:245
TDC is the root class for GDI DC wrappers.
Definition dc.h:64
Pseudo-GDI object Device Independent Bitmap (DIB) class.
Definition gdiobjec.h:795
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
The tagSIZE struct is defined as.
Definition geometry.h:234
Definition of abstract GDI object class and derived classes.
TAutoDelete
Flag for Handle ctors to control Handle deletion in dtor.
Definition gdibase.h:70
@ AutoDelete
Definition gdibase.h:70
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
unsigned long uint32
Definition number.h:34
unsigned int uint
Definition number.h:25
#define protected_data
Definition defs.h:208
#define _OWLCLASS
Definition defs.h:338