Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Commit

Permalink
Clean up ImageRoll::Draw()
Browse files Browse the repository at this point in the history
Signed-off-by: Avery King <[email protected]>
  • Loading branch information
generic-pers0n committed Sep 13, 2022
1 parent c602385 commit fd23bcb
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 82 deletions.
174 changes: 95 additions & 79 deletions src/widgets/ImageRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,109 +316,125 @@ void ImageRoll::DrawBitmap(wxDC &dc, wxBitmap &bitmap,

void ImageRoll::Draw(wxDC &dc, wxRect rect)
{
Draw( dc, rect, wxCOPY );
}

void ImageRoll::Draw(wxDC &dc, wxRect rect, int WXUNUSED(logicalFunc))
{
auto func = wxCOPY;
int width = rect.width;
int height = rect.height;
int num = (int)mPieces.size();
int i, j;

switch(mType) {
case HorizontalRoll: {
// The pieces alternate fixed, rolling, fixed, rolling...

int fixedWidth = 0;
for(i=0; i<num; i+=2)
fixedWidth += (mPieces[i].Ok() ? mPieces[i].GetWidth() : 0);

int rollingSpace = width - fixedWidth;
int numRolling = num / 2;
int x = 0;
switch(mType)
{
case HorizontalRoll: {
// The pieces alternate fixed, rolling, fixed, rolling...

for(i=0; i<num; i++) {
int w = (mPieces[i].Ok() ? mPieces[i].GetWidth() : 0);
int fixedWidth = 0;
for (i = 0; i < num; i += 2)
{
fixedWidth += (mPieces[i].Ok() ? mPieces[i].GetWidth() : 0);
}

if (i%2==0) {
// fixed
int rollingSpace = width - fixedWidth;
int numRolling = num / 2;
int x = 0;

if (mPieces[i].Ok())
DrawBitmap(dc, mPieces[i], rect.x + x, rect.y, func);
x += w;
}
else {
// rolling
for(i=0; i<num; i++)
{
int w = (mPieces[i].Ok() ? mPieces[i].GetWidth() : 0);

int space =
((1+(i/2))*rollingSpace / numRolling) -
((i/2)*rollingSpace / numRolling);
if (i % 2 == 0)
{
// fixed

j = 0;
while(j < space) {
if (mPieces[i].Ok())
DrawBitmap(dc, mPieces[i], rect.x + x + j, rect.y, func);
j += w;
{
DrawBitmap(dc, mPieces[i], rect.x + x, rect.y, wxCOPY);
}

x += w;
} else
{
// rolling

int space =
((1+(i/2))*rollingSpace / numRolling) -
((i/2)*rollingSpace / numRolling);

j = 0;
while(j < space)
{
if (mPieces[i].Ok())
{
DrawBitmap(dc, mPieces[i], rect.x + x + j, rect.y, wxCOPY);
}

j += w;
}

x += space;
}

x += space;
}
}
} break; // case HorizontalRoll

case VerticalRoll: {
// The pieces alternate fixed, rolling, fixed, rolling...

int fixedHeight = 0;
for(i=0; i<num; i+=2)
fixedHeight += (mPieces[i].Ok() ? mPieces[i].GetHeight() : 0);
} break; // case HorizontalRoll

int rollingSpace = height - fixedHeight;
int numRolling = num / 2;
int y = 0;
case VerticalRoll: {
// The pieces alternate fixed, rolling, fixed, rolling...

for(i=0; i<num; i++) {
int h = (mPieces[i].Ok() ? mPieces[i].GetHeight() : 0);
int fixedHeight = 0;
for (i = 0; i < num; i += 2)
{
fixedHeight += (mPieces[i].Ok() ? mPieces[i].GetHeight() : 0);
}

if (i%2==0) {
// fixed
int rollingSpace = height - fixedHeight;
int numRolling = num / 2;
int y = 0;

if (mPieces[i].Ok())
DrawBitmap(dc, mPieces[i], rect.x, rect.y + y, func);
y += h;
}
else {
// rolling
for (i = 0; i < num; i++)
{
int h = (mPieces[i].Ok() ? mPieces[i].GetHeight() : 0);

int space =
((1+(i/2))*rollingSpace / numRolling) -
((i/2)*rollingSpace / numRolling);
if (i % 2 == 0)
{
// fixed

j = 0;
while(j < space) {
if (mPieces[i].Ok())
DrawBitmap(dc, mPieces[i], rect.x, rect.y + y + j, func);
j += h;
{
DrawBitmap(dc, mPieces[i], rect.x, rect.y + y, wxCOPY);
}

y += h;
} else
{
// rolling

int space =
((1+(i/2))*rollingSpace / numRolling) -
((i/2)*rollingSpace / numRolling);

j = 0;
while(j < space)
{
if (mPieces[i].Ok())
{
DrawBitmap(dc, mPieces[i], rect.x, rect.y + y + j, wxCOPY);
}

j += h;
}

y += space;
}

y += space;
}
}
} break; // case VerticalRoll

case FixedImage:
DrawBitmap(dc, mPieces[0], rect.x, rect.y, func);
} break; // case VerticalRoll

case FixedImage:
DrawBitmap(dc, mPieces[0], rect.x, rect.y, wxCOPY);
break;
/* the other possible cases don't really make sense, but not having them
* listed gives a GCC warning */
case Uninitialized:
break;
/* the other possible cases don't really make sense, but not having them
* listed gives a GCC warning */
case Uninitialized:
break;

case Frame:
break;

case Frame:
break;
} // switch
}

Expand Down
4 changes: 1 addition & 3 deletions src/widgets/ImageRoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ class SAUCEDACITY_DLL_API ImageRoll
wxSize GetMinSize() const { return mMinSize; }
wxSize GetMaxSize() const { return mMaxSize; }

void Draw(wxDC &dc, wxRect rect,
int /* wxRasterOperationMode */ logicalFunc);
void Draw(wxDC &dc, wxRect rect); // default logicalFunc to wxCOPY
void Draw(wxDC &dc, wxRect rect);

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

0 comments on commit fd23bcb

Please sign in to comment.