From ff0ac74154d73e75981f6f66e84fad5eb44bd95c Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 5 Oct 2013 18:30:31 -0700 Subject: [PATCH] Make it possible to pan the texture while zoomed. --- Windows/GEDebugger/SimpleGLWindow.cpp | 49 +++++++++++++++++++++++++-- Windows/GEDebugger/SimpleGLWindow.h | 10 ++++++ 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/Windows/GEDebugger/SimpleGLWindow.cpp b/Windows/GEDebugger/SimpleGLWindow.cpp index edea4b97b0..e404779972 100644 --- a/Windows/GEDebugger/SimpleGLWindow.cpp +++ b/Windows/GEDebugger/SimpleGLWindow.cpp @@ -15,6 +15,7 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. +#include #include "math/lin/matrix4x4.h" #include "gfx_es2/glsl_program.h" #include "Common/Common.h" @@ -66,7 +67,8 @@ static const char basic_vs[] = "}\n"; SimpleGLWindow::SimpleGLWindow(HWND wnd) - : hWnd_(wnd), valid_(false), drawProgram_(NULL), tex_(0), flags_(0), zoom_(false) { + : hWnd_(wnd), valid_(false), drawProgram_(NULL), tex_(0), flags_(0), zoom_(false), + dragging_(false), offsetX_(0), offsetY_(0) { SetWindowLongPtr(wnd, GWLP_USERDATA, (LONG) this); } @@ -237,9 +239,15 @@ void SimpleGLWindow::Draw(u8 *data, int w, int h, bool flipped, Format fmt) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - tw_ = w; - th_ = h; + // Reset offset when the texture size changes. + if (tw_ != w || th_ != h) { + tw_ = w; + th_ = h; + offsetX_ = 0; + offsetY_ = 0; + } tflipped_ = flipped; + Redraw(); } @@ -278,6 +286,9 @@ void SimpleGLWindow::Redraw() { y = ((float)h_ - fh) / 2; } + x += offsetX_; + y += offsetY_; + const float pos[12] = {x,y,0, x+fw,y,0, x+fw,y+fh,0, x,y+fh,0}; static const float texCoords[8] = {0,0, 1,0, 1,1, 0,1}; static const float texCoordsFlipped[8] = {0,1, 1,1, 1,0, 0,0}; @@ -317,7 +328,39 @@ LRESULT CALLBACK SimpleGLWindow::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPA case WM_LBUTTONDBLCLK: win->zoom_ = !win->zoom_; + // Reset the offset when zooming out (or in, doesn't matter.) + win->offsetX_ = 0; + win->offsetY_ = 0; + // Redrawn in WM_LBUTTONUP. + return 0; + + case WM_LBUTTONDOWN: + // Only while zoomed in, otherwise it's shrink to fit mode or fixed. + if (win->zoom_) { + win->dragging_ = true; + win->dragStartX_ = GET_X_LPARAM(lParam) - win->offsetX_; + win->dragStartY_ = GET_Y_LPARAM(lParam) - win->offsetY_; + win->dragLastUpdate_ = GetTickCount(); + } + return 0; + + case WM_LBUTTONUP: + win->dragging_ = false; win->Redraw(); + return 0; + + case WM_MOUSEMOVE: + if (win->dragging_) { + int x = GET_X_LPARAM(lParam); + int y = GET_Y_LPARAM(lParam); + win->offsetX_ = x - win->dragStartX_; + win->offsetY_ = y - win->dragStartY_; + const u32 MS_BETWEEN_DRAG_REDRAWS = 5; + if (GetTickCount() - win->dragLastUpdate_ > MS_BETWEEN_DRAG_REDRAWS) { + win->Redraw(); + } + return 0; + } break; } diff --git a/Windows/GEDebugger/SimpleGLWindow.h b/Windows/GEDebugger/SimpleGLWindow.h index d4f904052c..d9739a6b54 100644 --- a/Windows/GEDebugger/SimpleGLWindow.h +++ b/Windows/GEDebugger/SimpleGLWindow.h @@ -73,8 +73,10 @@ protected: HDC hDC_; HGLRC hGLRC_; bool valid_; + // Width and height of the window. int w_; int h_; + // Last texture size/flipped for Redraw(). int tw_; int th_; bool tflipped_; @@ -83,5 +85,13 @@ protected: GLuint checker_; GLuint tex_; u32 flags_; + // Disable shrink (toggled by double click.) bool zoom_; + bool dragging_; + int dragStartX_; + int dragStartY_; + u32 dragLastUpdate_; + // Offset to position the texture is drawn at. + int offsetX_; + int offsetY_; }; \ No newline at end of file