Skip to content

Commit

Permalink
Fix: Add vertical scrollbar to the sprite display.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberth289346 committed Nov 2, 2014
1 parent 800cd42 commit dc02545
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
29 changes: 21 additions & 8 deletions AnimView/frmSprites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ SOFTWARE.
#include <wx/msgdlg.h>
#include <wx/dirdlg.h>
#include <wx/filedlg.h>
#include <wx/vscroll.h>
#include <wx/dcclient.h>

BEGIN_EVENT_TABLE(frmSprites, wxFrame)
Expand Down Expand Up @@ -63,7 +64,7 @@ frmSprites::frmSprites()
pMainSizer->Add(pFiles, 0, wxEXPAND | wxALL, 2);

wxStaticBoxSizer *pSprites = new wxStaticBoxSizer(wxVERTICAL, this, L"Sprites");
pSprites->Add(m_panFrame = new wxPanel(this, wxID_ANY), 1, wxEXPAND);
pSprites->Add(m_panFrame = new MyVScrolled(this), 1, wxEXPAND);
pMainSizer->Add(pSprites, 1, wxEXPAND | wxALL, 2);
m_panFrame->Connect(wxEVT_PAINT, (wxObjectEventFunction)&frmSprites::_onPanelPaint, NULL, this);

Expand Down Expand Up @@ -153,29 +154,41 @@ void frmSprites::_onPanelPaint(wxPaintEvent& evt)

int iAvailableWidth, iAvailableHeight;
m_panFrame->GetClientSize(&iAvailableWidth, &iAvailableHeight);
int iX = 0, iY = 0, iTallest = 0;
int iX = 0;
int iTallest = 0;
int iTotal = 0;
int iY = -m_panFrame->GetVisibleRowsBegin();

for(std::vector<_sprite_t>::iterator itr = m_vSprites.begin(), itrEnd = m_vSprites.end();
itr != itrEnd; ++itr)
{
wxSize szLabel = dc.GetTextExtent(itr->caption);
int iWidth = wxMax(szLabel.GetWidth(), itr->bitmap.IsOk() ? itr->bitmap.GetWidth() : 0);
int iHeight = (itr->bitmap.IsOk() ? itr->bitmap.GetHeight() : 0) + szLabel.GetHeight() + 2;
if(iWidth + iX > iAvailableWidth)
{
iY += iTallest;
iTotal += iTallest;
iX = iTallest = 0;
if(iY > iAvailableHeight)
break;
}

dc.DrawText(itr->caption, iX, iY);
if(itr->bitmap.IsOk())
dc.DrawBitmap(itr->bitmap, iX, iY + szLabel.GetHeight() + 1);
if (iY + iHeight >= 0 && iY < iAvailableHeight) {
dc.DrawText(itr->caption, iX, iY);
if(itr->bitmap.IsOk())
dc.DrawBitmap(itr->bitmap, iX, iY + szLabel.GetHeight() + 1);
}

int iHeight = (itr->bitmap.IsOk() ? itr->bitmap.GetHeight() : 0) + szLabel.GetHeight() + 2;
iTallest = wxMax(iTallest, iHeight);
iX += iWidth + 2;
}

iTotal += iTallest; // Add last row too.

// Update the row count if it doesn't match.
if (iTotal != m_panFrame->iMyCount) {
m_panFrame->iMyCount = iTotal;
m_panFrame->SetRowCount(iTotal);
}
}

void frmSprites::_onBrowseTable(wxCommandEvent& WXUNUSED(evt))
Expand Down
17 changes: 16 additions & 1 deletion AnimView/frmSprites.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,24 @@ SOFTWARE.
#include <wx/panel.h>
#include <wx/timer.h>
#include <wx/listbox.h>
#include <wx/vscroll.h>
#include "th.h"
#include <vector>

static const int ROW_COUNT = 1000;

// Derived class to add scrollbars to the window.
class MyVScrolled : public wxVScrolledWindow {
public:
MyVScrolled(wxWindow *parent) : wxVScrolledWindow(parent, wxID_ANY) { iMyCount = ROW_COUNT; }

wxCoord OnGetRowHeight(size_t row) const { return 1; }

wxCoord EstimateTotalHeight() const { return iMyCount; }

int iMyCount;
};

class frmSprites : public wxFrame
{
public:
Expand Down Expand Up @@ -70,6 +85,6 @@ class frmSprites : public wxFrame
wxTextCtrl* m_txtTable;
wxTextCtrl* m_txtData;
wxTextCtrl* m_txtPalette;
wxPanel* m_panFrame;
MyVScrolled* m_panFrame;
DECLARE_EVENT_TABLE();
};

0 comments on commit dc02545

Please sign in to comment.