Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(570621)

Unified Diff: examples/analyzer.cc

Issue 1050: Add image panning to the analyzer.
Patch Set: Rebase and fix default size. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/analyzer.cc
diff --git a/examples/analyzer.cc b/examples/analyzer.cc
index 7c5f67877f6f44e8151f760d3188a6d6b48d8bf2..e396f34f7eb9b2a1d8410c39d5c5480ec1e3a9ce 100644
--- a/examples/analyzer.cc
+++ b/examples/analyzer.cc
@@ -297,7 +297,7 @@ bool DaalaDecoder::setDeringFlagsBuffer(unsigned char *buf, size_t buf_sz) {
}
#define MIN_ZOOM (1)
-#define MAX_ZOOM (4)
+#define MAX_ZOOM (8)
enum {
OD_LUMA_MASK = 1 << 0,
@@ -306,7 +306,7 @@ enum {
OD_ALL_MASK = OD_LUMA_MASK | OD_CB_MASK | OD_CR_MASK
};
-class TestPanel : public wxPanel {
+class TestPanel : public wxScrolledWindow {
DECLARE_EVENT_TABLE()
private:
DaalaDecoder dd;
@@ -363,6 +363,7 @@ public:
int getZoom() const;
bool setZoom(int zoom);
+ int scrollUnit() const;
void setShowBlocks(bool show_blocks);
void setShowSkip(bool show_skip);
@@ -452,7 +453,7 @@ BEGIN_EVENT_TABLE(TestFrame, wxFrame)
EVT_MENU(wxID_ABOUT, TestFrame::onAbout)
END_EVENT_TABLE()
-TestPanel::TestPanel(wxWindow *parent, const wxString &path) : wxPanel(parent),
+TestPanel::TestPanel(wxWindow *parent, const wxString &path) : wxScrolledWindow(parent),
pixels(NULL), zoom(0), bsize(NULL), bsize_len(0), show_blocks(false),
flags(NULL), flags_len(0), show_skip(false), show_noref(false),
show_padding(false), show_dering(false), acct(NULL), show_bits(false),
@@ -468,6 +469,7 @@ bool TestPanel::open(const wxString &path) {
if (!dd.open(path)) {
return false;
}
+ SetSize(dd.getWidth(), dd.getHeight());
if (!setZoom(MIN_ZOOM)) {
return false;
}
@@ -748,6 +750,10 @@ int TestPanel::getZoom() const {
return zoom;
}
+int TestPanel::scrollUnit() const {
+ return zoom*8;
+}
+
bool TestPanel::updateDisplaySize() {
unsigned char *p =
(unsigned char *)malloc(sizeof(*p)*3*getDisplayWidth()*getDisplayHeight());
@@ -756,7 +762,10 @@ bool TestPanel::updateDisplaySize() {
}
free(pixels);
pixels = p;
- SetSize(getDisplayWidth(), getDisplayHeight());
+ int sx, sy;
+ GetViewStart(&sx, &sy);
+ SetScrollbars(scrollUnit(), scrollUnit(),
+ getDisplayWidth()/scrollUnit(), getDisplayHeight()/scrollUnit(), sx, sy);
return true;
}
@@ -973,8 +982,11 @@ void TestPanel::onMouseMotion(wxMouseEvent& event) {
int mouse_x = pt.x - this->GetScreenPosition().x;
int mouse_y = pt.y - this->GetScreenPosition().y;
TestFrame *parent = static_cast<TestFrame*>(GetParent());
- int row = mouse_y/zoom;
- int col = mouse_x/zoom;
+ int sx, sy;
+ GetViewStart(&sx, &sy);
+ /* Offset row / col by scroll position. */
+ int col = (mouse_x + sx*scrollUnit())/zoom;
+ int row = (mouse_y + sy*scrollUnit())/zoom;
if (row >= 0 && col >= 0 && row < getDecodeHeight()
&& col < getDecodeWidth()) {
const od_img_plane *planes = dd.img.planes;
@@ -1001,8 +1013,14 @@ void TestPanel::onMouseLeaveWindow(wxMouseEvent& event) {
}
void TestPanel::onPaint(wxPaintEvent &) {
+ int sx, sy;
+ GetViewStart(&sx, &sy);
wxBitmap bmp(wxImage(getDisplayWidth(), getDisplayHeight(), pixels, true));
- wxBufferedPaintDC dc(this, bmp);
+ wxBufferedPaintDC dc(this);
+ dc.SetBackgroundMode(wxSOLID);
+ dc.SetBackground(wxColor(0,0,0));
+ dc.Clear();
+ dc.DrawBitmap(bmp, -sx*scrollUnit(), -sy*scrollUnit());
}
void TestPanel::onIdle(wxIdleEvent &) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld