From d831d1663713a6001d40e381987d2a5e156daa11 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 28 Jun 2009 16:45:03 +0100 Subject: [PATCH] Get scrolling sorted --- include/IWindow.hpp | 4 ++++ src/Editor.cpp | 13 +++++++++---- src/FLTKWindow.cpp | 33 +++++++++++++++++++++++++++++---- src/SDLWindow.cpp | 1 + 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/include/IWindow.hpp b/include/IWindow.hpp index 70d6116..f91b735 100644 --- a/include/IWindow.hpp +++ b/include/IWindow.hpp @@ -32,6 +32,10 @@ public: virtual void takeScreenShot() = 0; virtual int width() const = 0; virtual int height() const = 0; + + // Ask the window to repaint the screen + // This is ignored by some implementations (e.g. SDL) + virtual void redrawHint() = 0; }; typedef shared_ptr IWindowPtr; diff --git a/src/Editor.cpp b/src/Editor.cpp index 83b25eb..9543e6f 100644 --- a/src/Editor.cpp +++ b/src/Editor.cpp @@ -443,7 +443,9 @@ void Editor::deleteObjects() void Editor::onMouseMove(IPickBufferPtr aPickBuffer, int x, int y, int xrel, int yrel) -{ +{ + debug() << "xrel=" << xrel << ", yrel=" << yrel; + if (amDragging) { // Extend the selection rectangle myMap->setPickMode(true); @@ -464,6 +466,8 @@ void Editor::onMouseMove(IPickBufferPtr aPickBuffer, int x, int y, myPosition.x += yrel * speed; myPosition.z -= yrel * speed; } + + getGameWindow()->redrawHint(); } // Change to the terrain raising mode @@ -520,8 +524,6 @@ void Editor::onBuildingSelect() void Editor::onMouseClick(IPickBufferPtr aPickBuffer, int x, int y, MouseButton aButton) { - log() << "Click!"; - // See if the GUI can handle it if (myToolbar->handleClick(x, y)) return; @@ -551,7 +553,8 @@ void Editor::onMouseClick(IPickBufferPtr aPickBuffer, int x, int y, else if (aButton == MOUSE_WHEEL_DOWN) { myPosition.y += 0.5; } - + + getGameWindow()->redrawHint(); } void Editor::onMouseRelease(IPickBufferPtr aPickBuffer, int x, int y, @@ -591,6 +594,8 @@ void Editor::onMouseRelease(IPickBufferPtr aPickBuffer, int x, int y, else if (amScrolling) { amScrolling = false; } + + getGameWindow()->redrawHint(); } void Editor::onKeyUp(SDLKey aKey) diff --git a/src/FLTKWindow.cpp b/src/FLTKWindow.cpp index 80a1cb9..45e84c1 100644 --- a/src/FLTKWindow.cpp +++ b/src/FLTKWindow.cpp @@ -41,6 +41,7 @@ public: void takeScreenShot(); int width() const; int height() const; + void redrawHint(); // IGraphics interface bool cuboidInViewFrustum(float x, float y, float z, @@ -97,6 +98,11 @@ FLTKWindow::~FLTKWindow() } +void FLTKWindow::redrawHint() +{ + redraw(); +} + void FLTKWindow::checkValid() { if (!valid()) { @@ -116,6 +122,26 @@ void FLTKWindow::draw() int FLTKWindow::handle(int anEvent) { + static int lastX = 0, lastY = 0; + + int dx = 0, dy = 0; + if (anEvent == FL_PUSH || FL_DRAG || FL_RELEASE || FL_MOVE) { + dx = Fl::event_x() - lastX; + dy = Fl::event_y() - lastY; + lastX = Fl::event_x(); + lastY = Fl::event_y(); + } + + MouseButton btn; + if (Fl::event_button1()) + btn = MOUSE_LEFT; + else if (Fl::event_button2()) + btn = MOUSE_MIDDLE; + else if (Fl::event_button3()) + btn = MOUSE_RIGHT; + else + btn = MOUSE_UNKNOWN; + // Do not call any OpenGL drawing functions in here as the context // won't be set up correctly switch (anEvent) { @@ -123,17 +149,16 @@ int FLTKWindow::handle(int anEvent) // Mouse down event // Position in Fl::event_x() and Fl::event_y() myScreen->onMouseClick(shared_from_this(), Fl::event_x(), - Fl::event_y(), MOUSE_LEFT); + Fl::event_y(), btn); return 1; case FL_DRAG: // Mouse moved while pressed down - myScreen->onMouseMove(shared_from_this(), Fl::event_x(), - Fl::event_y(), 1, 1); + myScreen->onMouseMove(shared_from_this(), lastX, lastY, dx, dy); return 1; case FL_RELEASE: // Mouse up event myScreen->onMouseRelease(shared_from_this(), Fl::event_x(), - Fl::event_y(), MOUSE_LEFT); + Fl::event_y(), btn); return 1; case FL_FOCUS: case FL_UNFOCUS: diff --git a/src/SDLWindow.cpp b/src/SDLWindow.cpp index b935e0e..ca4dddc 100644 --- a/src/SDLWindow.cpp +++ b/src/SDLWindow.cpp @@ -47,6 +47,7 @@ public: void takeScreenShot(); int width() const { return myWidth; } int height() const { return myHeight; } + void redrawHint() {} // IGraphics interface bool cuboidInViewFrustum(float x, float y, float z, -- 2.39.2