Audacity  3.0.3
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  {
32  FixedImage,
35  Frame
36  };

Constructor & Destructor Documentation

◆ ImageRoll() [1/4]

ImageRoll::ImageRoll ( )

Definition at line 283 of file ImageRoll.cpp.

284 {
286 }

References mType, and Uninitialized.

◆ ImageRoll() [2/4]

ImageRoll::ImageRoll ( const wxImage &  src)

Definition at line 293 of file ImageRoll.cpp.

294 {
295  Init(FixedImage, src, *wxWHITE);
296 }

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 288 of file ImageRoll.cpp.

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

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 317 of file ImageRoll.cpp.

318 {
319  Draw( dc, rect, wxCOPY );
320 }

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 303 of file ImageRoll.cpp.

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

References wxRasterOperationMode.

◆ GetMaxSize()

wxSize ImageRoll::GetMaxSize ( ) const
inline

Definition at line 48 of file ImageRoll.h.

48 { return mMaxSize; }

◆ GetMinSize()

wxSize ImageRoll::GetMinSize ( ) const
inline

Definition at line 47 of file ImageRoll.h.

47 { return mMinSize; }

◆ Init()

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

Definition at line 220 of file ImageRoll.cpp.

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

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 298 of file ImageRoll.cpp.

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

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 110 of file ImageRoll.cpp.

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

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

Here is the caller graph for this function:

◆ SplitV()

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

Definition at line 166 of file ImageRoll.cpp.

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

Referenced by Init().

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:
ImageRoll::HorizontalRoll
@ HorizontalRoll
Definition: ImageRoll.h:33
ImageRoll::mMaxSize
wxSize mMaxSize
Definition: ImageRoll.h:69
ImageRoll::mPieces
std::vector< wxBitmap > mPieces
Definition: ImageRoll.h:67
ImageArray
std::vector< wxImage > ImageArray
Definition: ImageRoll.h:25
ImageRoll::Frame
@ Frame
Definition: ImageRoll.h:35
ImageRoll::VerticalRoll
@ VerticalRoll
Definition: ImageRoll.h:34
wxRasterOperationMode
#define wxRasterOperationMode
Definition: ImageRoll.h:21
ImageRoll::Uninitialized
@ Uninitialized
Definition: ImageRoll.h:31
ImageRoll::Draw
void Draw(wxDC &dc, wxRect rect, int logicalFunc)
ImageRoll::SplitH
static ImageArray SplitH(const wxImage &src, wxColour magicColor)
Definition: ImageRoll.cpp:110
ImageRoll::mType
RollType mType
Definition: ImageRoll.h:65
ImageRoll::SplitV
static ImageArray SplitV(const wxImage &src, wxColour magicColor)
Definition: ImageRoll.cpp:166
ImageRoll::FixedImage
@ FixedImage
Definition: ImageRoll.h:32
ImageRoll::Ok
bool Ok() const
Definition: ImageRoll.cpp:298
ImageRoll::mMinSize
wxSize mMinSize
Definition: ImageRoll.h:68
ImageRoll::Init
void Init(RollType type, const wxImage &src, wxColour magicColor)
Definition: ImageRoll.cpp:220