Audacity  2.2.2
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>

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)
 
bool Ok () const
 
wxSize GetMinSize () const
 
wxSize GetMaxSize () const
 
void Draw (wxDC &dc, wxRect rect, wxRasterOperationMode logicalFunc=wxCOPY)
 

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, wxRasterOperationMode logicalFunc=wxCOPY)
 
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 29 of file ImageRoll.h.

Member Enumeration Documentation

Enumerator
Uninitialized 
FixedImage 
HorizontalRoll 
VerticalRoll 
Frame 

Definition at line 32 of file ImageRoll.h.

Constructor & Destructor Documentation

ImageRoll::ImageRoll ( )

Definition at line 279 of file ImageRoll.cpp.

References mType, and Uninitialized.

280 {
282 }
RollType mType
Definition: ImageRoll.h:62
ImageRoll::ImageRoll ( const wxImage &  src)

Definition at line 289 of file ImageRoll.cpp.

References FixedImage, and Init().

290 {
291  Init(FixedImage, src, *wxWHITE);
292 }
void Init(RollType type, const wxImage &src, wxColour magicColor)
Definition: ImageRoll.cpp:216
ImageRoll::ImageRoll ( RollType  type,
const wxImage &  src,
wxColour  magicColor 
)

Definition at line 284 of file ImageRoll.cpp.

References Init().

285 {
286  Init(type, src, magicColor);
287 }
void Init(RollType type, const wxImage &src, wxColour magicColor)
Definition: ImageRoll.cpp:216

Member Function Documentation

void ImageRoll::Draw ( wxDC &  dc,
wxRect  rect,
wxRasterOperationMode  logicalFunc = wxCOPY 
)

Definition at line 312 of file ImageRoll.cpp.

References DrawBitmap(), FixedImage, Frame, HorizontalRoll, mPieces, mType, Ok(), Uninitialized, and VerticalRoll.

313 {
314  int width = rect.width;
315  int height = rect.height;
316  int num = (int)mPieces.size();
317  int i, j;
318 
319  switch(mType) {
320  case HorizontalRoll: {
321  // The pieces alternate fixed, rolling, fixed, rolling...
322 
323  int fixedWidth = 0;
324  for(i=0; i<num; i+=2)
325  fixedWidth += (mPieces[i].Ok() ? mPieces[i].GetWidth() : 0);
326 
327  int rollingSpace = width - fixedWidth;
328  int numRolling = num / 2;
329  int x = 0;
330 
331  for(i=0; i<num; i++) {
332  int w = (mPieces[i].Ok() ? mPieces[i].GetWidth() : 0);
333 
334  if (i%2==0) {
335  // fixed
336 
337  if (mPieces[i].Ok())
338  DrawBitmap(dc, mPieces[i], rect.x + x, rect.y);
339  x += w;
340  }
341  else {
342  // rolling
343 
344  int space =
345  ((1+(i/2))*rollingSpace / numRolling) -
346  ((i/2)*rollingSpace / numRolling);
347 
348  j = 0;
349  while(j < space) {
350  if (mPieces[i].Ok())
351  DrawBitmap(dc, mPieces[i], rect.x + x + j, rect.y);
352  j += w;
353  }
354 
355  x += space;
356  }
357  }
358  } break; // case HorizontalRoll
359 
360  case VerticalRoll: {
361  // The pieces alternate fixed, rolling, fixed, rolling...
362 
363  int fixedHeight = 0;
364  for(i=0; i<num; i+=2)
365  fixedHeight += (mPieces[i].Ok() ? mPieces[i].GetHeight() : 0);
366 
367  int rollingSpace = height - fixedHeight;
368  int numRolling = num / 2;
369  int y = 0;
370 
371  for(i=0; i<num; i++) {
372  int h = (mPieces[i].Ok() ? mPieces[i].GetHeight() : 0);
373 
374  if (i%2==0) {
375  // fixed
376 
377  if (mPieces[i].Ok())
378  DrawBitmap(dc, mPieces[i], rect.x, rect.y + y);
379  y += h;
380  }
381  else {
382  // rolling
383 
384  int space =
385  ((1+(i/2))*rollingSpace / numRolling) -
386  ((i/2)*rollingSpace / numRolling);
387 
388  j = 0;
389  while(j < space) {
390  if (mPieces[i].Ok())
391  DrawBitmap(dc, mPieces[i], rect.x, rect.y + y + j);
392  j += h;
393  }
394 
395  y += space;
396  }
397  }
398  } break; // case VerticalRoll
399 
400  case FixedImage:
401  DrawBitmap(dc, mPieces[0], rect.x, rect.y);
402  break;
403  /* the other possible cases don't really make sense, but not having them
404  * listed gives a GCC warning */
405  case Uninitialized:
406  break;
407 
408  case Frame:
409  break;
410 
411  } // switch
412 }
bool Ok() const
Definition: ImageRoll.cpp:294
std::vector< wxBitmap > mPieces
Definition: ImageRoll.h:64
RollType mType
Definition: ImageRoll.h:62
void DrawBitmap(wxDC &dc, wxBitmap &bitmap, int x, int y, wxRasterOperationMode logicalFunc=wxCOPY)
Definition: ImageRoll.cpp:299
void ImageRoll::DrawBitmap ( wxDC &  dc,
wxBitmap &  bitmap,
int  x,
int  y,
wxRasterOperationMode  logicalFunc = wxCOPY 
)
protected

Definition at line 299 of file ImageRoll.cpp.

Referenced by Draw().

301 {
302  if (logicalFunc == wxCOPY)
303  dc.DrawBitmap(bitmap, x, y);
304  else {
305  wxMemoryDC memDC;
306  memDC.SelectObject(bitmap);
307  dc.Blit(x, y, bitmap.GetWidth(), bitmap.GetHeight(),
308  &memDC, 0, 0, logicalFunc);
309  }
310 }
wxSize ImageRoll::GetMaxSize ( ) const
inline

Definition at line 47 of file ImageRoll.h.

References mMaxSize.

47 { return mMaxSize; }
wxSize mMaxSize
Definition: ImageRoll.h:66
wxSize ImageRoll::GetMinSize ( ) const
inline

Definition at line 46 of file ImageRoll.h.

References mMinSize.

46 { return mMinSize; }
wxSize mMinSize
Definition: ImageRoll.h:65
void ImageRoll::Init ( RollType  type,
const wxImage &  src,
wxColour  magicColor 
)
protected

Definition at line 216 of file ImageRoll.cpp.

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

Referenced by ImageRoll().

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

Definition at line 294 of file ImageRoll.cpp.

References mType, and Uninitialized.

Referenced by Draw(), and Init().

295 {
296  return (mType != Uninitialized);
297 }
RollType mType
Definition: ImageRoll.h:62
ImageArray ImageRoll::SplitH ( const wxImage &  src,
wxColour  magicColor 
)
static

Definition at line 106 of file ImageRoll.cpp.

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

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

Definition at line 162 of file ImageRoll.cpp.

Referenced by Init().

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

Member Data Documentation

wxSize ImageRoll::mMaxSize
protected

Definition at line 66 of file ImageRoll.h.

Referenced by GetMaxSize(), and Init().

wxSize ImageRoll::mMinSize
protected

Definition at line 65 of file ImageRoll.h.

Referenced by GetMinSize(), and Init().

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

Definition at line 64 of file ImageRoll.h.

Referenced by Draw(), and Init().

RollType ImageRoll::mType
protected

Definition at line 62 of file ImageRoll.h.

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


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