Audacity 3.2.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ImageRoll Class Reference

An ImageRoll is an image that can be expanded to an arbitrary size; it is made up of both fixed pieces and repeating pieces. More...

#include <ImageRoll.h>

Collaboration diagram for ImageRoll:
[legend]

Public Types

enum  RollType {
  Uninitialized , FixedImage , HorizontalRoll , VerticalRoll ,
  Frame
}
 

Public Member Functions

 ImageRoll ()
 
 ImageRoll (const wxImage &src)
 
 ImageRoll (RollType type, const wxImage &src, wxColour magicColor)
 
 ImageRoll (const ImageRoll &)
 
ImageRolloperator= (const ImageRoll &)
 
 ~ImageRoll ()
 
bool Ok () const
 
wxSize GetMinSize () const
 
wxSize GetMaxSize () const
 
void Draw (wxDC &dc, wxRect rect, int logicalFunc)
 
void Draw (wxDC &dc, wxRect rect)
 

Static Public Member Functions

static ImageArray SplitH (const wxImage &src, wxColour magicColor)
 
static ImageArray SplitV (const wxImage &src, wxColour magicColor)
 

Protected Member Functions

void DrawBitmap (wxDC &dc, wxBitmap &bitmap, int x, int y, int logicalFunc)
 
void Init (RollType type, const wxImage &src, wxColour magicColor)
 

Protected Attributes

RollType mType
 
std::vector< wxBitmap > mPieces
 
wxSize mMinSize
 
wxSize mMaxSize
 

Detailed Description

An ImageRoll is an image that can be expanded to an arbitrary size; it is made up of both fixed pieces and repeating pieces.

A typical ImageRoll might be made up of two fixed ends and a repeating middle part:

  /-----\                       /-----\
  |LEFT |--REPEATING--REPEATING-|RIGHT|
  \-----/                       \-----/

As you resize the image, it could look like this:

  /-----\ /-----\
  |LEFT |-|RIGHT|
  \-----/ \-----/

Or like this:

  /-----\                                  /-----\
  |LEFT |--REPEATING--REPEATING--REPEATING-|RIGHT|
  \-----/                                  \-----/

Note that an ImageRoll can have a center piece; in fact, its pieces always alternate fixed, repeating, fixed, repeating, etc. - although one of these pieces is allowed to be of size zero, making it skipped. Here's an example with a center piece:

  /-----\                /------\                /-----\
  |LEFT |-REPEAT--REPEAT-|CENTER|-repeat--repeat-|RIGHT|
  \-----/                \------/                \-----/

Note that the left and right repeating sections can be different. Of course, an ImageRoll can be oriented vertically as well. In the future, support for an ImageRoll that expands both horizontally and vertically at the same time will be supported.

An ImageRoll is initialized with a single wxImage that defines all of its pieces. This is done by way of a "magic color" which separates each piece in the image. If the magic colored pixel is denoted by "X", the above ImageRoll could be encoded like this:

  /-----\X        X/------\X        X/-----\
  |LEFT |X-REPEAT-X|CENTER|X-repeat-X|RIGHT|
  \-----/X        X\------/X        X\-----/

Putting two lines of magic color in a row will create a blank piece. For example, for an ImageRoll with a center piece but no left and right pieces:

  X        X/------\X        X
  X-REPEAT-X|CENTER|X-repeat-X
  X        X\------/X        X

Once again, the pieces are always assumed to alternate: fixed, repeating, fixed, repeating, etc. The magic color is specified when you construct the ImageRoll from a wxImage.

In the constructor, you also choose whether it is a horizontal or vertical ImageRoll (and later a "Frame" as well). You can also choose a "fixed" ImageRoll, which behaves just like a wxImage - this is handy so that you can use ImageRolls everywhere you were previously using wxImages.

Definition at line 27 of file ImageRoll.h.

Member Enumeration Documentation

◆ RollType

Enumerator
Uninitialized 
FixedImage 
HorizontalRoll 
VerticalRoll 
Frame 

Definition at line 30 of file ImageRoll.h.

30 {
35 Frame
36 };
@ FixedImage
Definition: ImageRoll.h:32
@ VerticalRoll
Definition: ImageRoll.h:34
@ HorizontalRoll
Definition: ImageRoll.h:33
@ Uninitialized
Definition: ImageRoll.h:31

Constructor & Destructor Documentation

◆ ImageRoll() [1/4]

ImageRoll::ImageRoll ( )

Definition at line 282 of file ImageRoll.cpp.

283{
285}
RollType mType
Definition: ImageRoll.h:65

References mType, and Uninitialized.

◆ ImageRoll() [2/4]

ImageRoll::ImageRoll ( const wxImage src)

Definition at line 292 of file ImageRoll.cpp.

293{
294 Init(FixedImage, src, *wxWHITE);
295}
void Init(RollType type, const wxImage &src, wxColour magicColor)
Definition: ImageRoll.cpp:219

References FixedImage, and Init().

Here is the call graph for this function:

◆ ImageRoll() [3/4]

ImageRoll::ImageRoll ( RollType  type,
const wxImage src,
wxColour  magicColor 
)

Definition at line 287 of file ImageRoll.cpp.

288{
289 Init(type, src, magicColor);
290}

References Init().

Here is the call graph for this function:

◆ ImageRoll() [4/4]

ImageRoll::ImageRoll ( const ImageRoll )
default

◆ ~ImageRoll()

ImageRoll::~ImageRoll ( )
default

Member Function Documentation

◆ Draw() [1/2]

void ImageRoll::Draw ( wxDC &  dc,
wxRect  rect 
)

Definition at line 316 of file ImageRoll.cpp.

317{
318 Draw( dc, rect, wxCOPY );
319}
void Draw(wxDC &dc, wxRect rect, int logicalFunc)

References Draw().

Here is the call graph for this function:

◆ Draw() [2/2]

void ImageRoll::Draw ( wxDC &  dc,
wxRect  rect,
int  logicalFunc 
)

Referenced by Draw().

Here is the caller graph for this function:

◆ DrawBitmap()

void ImageRoll::DrawBitmap ( wxDC &  dc,
wxBitmap &  bitmap,
int  x,
int  y,
int  logicalFunc 
)
protected

Definition at line 302 of file ImageRoll.cpp.

304{
305 auto func = static_cast< wxRasterOperationMode >( logicalFunc );
306 if (func == wxCOPY)
307 dc.DrawBitmap(bitmap, x, y);
308 else {
309 wxMemoryDC memDC;
310 memDC.SelectObject(bitmap);
311 dc.Blit(x, y, bitmap.GetWidth(), bitmap.GetHeight(),
312 &memDC, 0, 0, func);
313 }
314}
#define wxRasterOperationMode
Definition: ImageRoll.h:21

References wxRasterOperationMode.

◆ GetMaxSize()

wxSize ImageRoll::GetMaxSize ( ) const
inline

Definition at line 48 of file ImageRoll.h.

48{ return mMaxSize; }
wxSize mMaxSize
Definition: ImageRoll.h:69

◆ GetMinSize()

wxSize ImageRoll::GetMinSize ( ) const
inline

Definition at line 47 of file ImageRoll.h.

47{ return mMinSize; }
wxSize mMinSize
Definition: ImageRoll.h:68

◆ Init()

void ImageRoll::Init ( RollType  type,
const wxImage src,
wxColour  magicColor 
)
protected

Definition at line 219 of file ImageRoll.cpp.

220{
221 ImageArray images;
222 int i;
223
224 mType = type;
225
226 switch(mType) {
227 case HorizontalRoll:
228 images = SplitH(src, magicColor);
229
230 mMinSize.x = 0;
231 mMinSize.y = src.GetHeight();
232 mMaxSize.x = 9999;
233 mMaxSize.y = src.GetHeight();
234
235 for(i = 0; i < (int)images.size(); i++) {
236 if (images[i].Ok()) {
237 mPieces.push_back(wxBitmap(images[i]));
238 mMinSize.x += mPieces[i].GetWidth();
239 }
240 else
241 mPieces.push_back(wxBitmap());
242 }
243 break;
244
245 case VerticalRoll:
246 images = SplitV(src, magicColor);
247
248 mMinSize.x = src.GetWidth();
249 mMinSize.y = 0;
250 mMaxSize.x = src.GetWidth();
251 mMaxSize.y = 9999;
252
253 for(i = 0; i < (int)images.size(); i++) {
254 if (images[i].Ok()) {
255 mPieces.push_back(wxBitmap(images[i]));
256 mMinSize.y += mPieces[i].GetHeight();
257 }
258 else
259 mPieces.push_back(wxBitmap());
260 }
261 break;
262
263 case FixedImage:
264 mPieces.push_back(wxBitmap(src));
265 mMinSize.x = src.GetWidth();
266 mMinSize.y = src.GetHeight();
267 mMaxSize.x = src.GetWidth();
268 mMaxSize.y = src.GetHeight();
269 break;
270
271 /* Adding these shuts up some GCC warnings. It is functionally what was
272 * implicit here before - Richard */
273 case Uninitialized:
274 break;
275
276 case Frame:
277 break;
278
279 } // switch
280}
std::vector< wxImage > ImageArray
Definition: ImageRoll.h:25
bool Ok() const
Definition: ImageRoll.cpp:297
static ImageArray SplitV(const wxImage &src, wxColour magicColor)
Definition: ImageRoll.cpp:165
std::vector< wxBitmap > mPieces
Definition: ImageRoll.h:67
static ImageArray SplitH(const wxImage &src, wxColour magicColor)
Definition: ImageRoll.cpp:109

References FixedImage, Frame, HorizontalRoll, mMaxSize, mMinSize, mPieces, mType, Ok(), SplitH(), SplitV(), Uninitialized, and VerticalRoll.

Referenced by ImageRoll().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Ok()

bool ImageRoll::Ok ( ) const

Definition at line 297 of file ImageRoll.cpp.

298{
299 return (mType != Uninitialized);
300}

References mType, and Uninitialized.

Referenced by Init().

Here is the caller graph for this function:

◆ operator=()

ImageRoll & ImageRoll::operator= ( const ImageRoll )
default

◆ SplitH()

ImageArray ImageRoll::SplitH ( const wxImage src,
wxColour  magicColor 
)
static

Definition at line 109 of file ImageRoll.cpp.

110{
111 ImageArray result;
112
113 int width = src.GetWidth();
114 int height = src.GetHeight();
115 unsigned char *data = src.GetData();
116 unsigned char *ptr = data;
117 unsigned char magicRed = magicColor.Red();
118 unsigned char magicGreen = magicColor.Green();
119 unsigned char magicBlue = magicColor.Blue();
120 bool cur, prev;
121 int i, j, start;
122
123 // Sanity check...
124 if (width<=0 || height<=0 || data==NULL)
125 return result;
126
127 prev = false;
128 start = 0;
129 for(i=0; i<width+1; i++) {
130 if (i < width) {
131 unsigned char *ptr2 = ptr;
132 cur = true;
133 for(j=0; j<height && cur; j++) {
134 if (!(ptr2[0] == magicRed &&
135 ptr2[1] == magicGreen &&
136 ptr2[2] == magicBlue))
137 cur = false;
138 ptr2 += 3 * width;
139 }
140 }
141 else
142 cur = !prev;
143
144 if ((cur && !prev)) {
145 wxRect subRect(start, 0, i-start, height);
146 wxImage subImage;
147 if (subRect.width > 0)
148 subImage = src.GetSubImage(subRect);
149 else
150 subImage = wxImage(subRect.width, subRect.height);
151 result.push_back(subImage);
152 }
153 else if (!cur && prev) {
154 start = i;
155 }
156
157 prev = cur;
158 ptr += 3;
159 }
160
161 return result;
162}
wxImage(22, 22)

References wxImage().

Referenced by Init(), and ToolBarGrabber::ToolBarGrabber().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SplitV()

ImageArray ImageRoll::SplitV ( const wxImage src,
wxColour  magicColor 
)
static

Definition at line 165 of file ImageRoll.cpp.

166{
167 ImageArray result;
168 int width = src.GetWidth();
169 int height = src.GetHeight();
170 unsigned char *data = src.GetData();
171 unsigned char *ptr = data;
172 unsigned char magicRed = magicColor.Red();
173 unsigned char magicGreen = magicColor.Green();
174 unsigned char magicBlue = magicColor.Blue();
175 bool cur, prev;
176 int i, j, start;
177
178 // Sanity check...
179 if (width<=0 || height<=0 || data==NULL)
180 return result;
181
182 prev = false;
183 start = 0;
184 for(i=0; i<height+1; i++) {
185 if (i < height) {
186 unsigned char *ptr2 = ptr;
187 cur = true;
188 for(j=0; j<width && cur; j++) {
189 if (!(ptr2[0] == magicRed &&
190 ptr2[1] == magicGreen &&
191 ptr2[2] == magicBlue))
192 cur = false;
193 ptr2 += 3;
194 }
195 }
196 else
197 cur = !prev;
198
199 if ((cur && !prev)) {
200 wxRect subRect(0, start, width, i-start);
201 wxImage subImage;
202 if (subRect.width > 0)
203 subImage = src.GetSubImage(subRect);
204 else
205 subImage = wxImage(subRect.width, subRect.height);
206 result.push_back(subImage);
207 }
208 else if (!cur && prev) {
209 start = i;
210 }
211
212 prev = cur;
213 ptr += 3*width;
214 }
215
216 return result;
217}

References wxImage().

Referenced by Init().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mMaxSize

wxSize ImageRoll::mMaxSize
protected

Definition at line 69 of file ImageRoll.h.

Referenced by Init().

◆ mMinSize

wxSize ImageRoll::mMinSize
protected

Definition at line 68 of file ImageRoll.h.

Referenced by Init().

◆ mPieces

std::vector<wxBitmap> ImageRoll::mPieces
protected

Definition at line 67 of file ImageRoll.h.

Referenced by Init().

◆ mType

RollType ImageRoll::mType
protected

Definition at line 65 of file ImageRoll.h.

Referenced by ImageRoll(), Init(), and Ok().


The documentation for this class was generated from the following files: