diff options
-rw-r--r-- | src/client.cpp | 5 | ||||
-rw-r--r-- | src/graphics.cpp | 11 | ||||
-rw-r--r-- | src/graphics.h | 10 | ||||
-rw-r--r-- | src/gui/equipmentwindow.cpp | 3 | ||||
-rw-r--r-- | src/gui/gui.cpp | 3 | ||||
-rw-r--r-- | src/gui/sdlinput.cpp | 15 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 7 | ||||
-rw-r--r-- | src/openglgraphics.cpp | 49 | ||||
-rw-r--r-- | src/resources/image.cpp | 1 |
9 files changed, 72 insertions, 32 deletions
diff --git a/src/client.cpp b/src/client.cpp index 28affce6..ce29f1b1 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1397,7 +1397,7 @@ void Client::handleVideoResize(int width, int height) // Keep a minimum size. This isn't adhered to by the actual window, but // it keeps some window positions from getting messed up. width = std::max(640, width); - height = std::max(480, height); + height = std::max(360, height); if (graphics->getWidth() == width && graphics->getHeight() == height) return; @@ -1408,7 +1408,8 @@ void Client::handleVideoResize(int width, int height) false, graphics->getHWAccel())) { - videoResized(width, height); + videoResized(graphics->getWidth(), + graphics->getHeight()); // Since everything appears to have worked out, remember to store the // new size in the configuration. diff --git a/src/graphics.cpp b/src/graphics.cpp index 7b56d974..d4b6778c 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -34,6 +34,7 @@ Graphics::Graphics(): mWidth(0), mHeight(0), + mScale(1), mBpp(0), mFullscreen(false), mHWAccel(false), @@ -136,16 +137,6 @@ bool Graphics::changeVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) return success; } -int Graphics::getWidth() const -{ - return mWidth; -} - -int Graphics::getHeight() const -{ - return mHeight; -} - bool Graphics::drawImage(Image *image, int x, int y) { if (image) diff --git a/src/graphics.h b/src/graphics.h index 6a17aab4..2e23b382 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -197,12 +197,17 @@ class Graphics : public gcn::SDLGraphics /** * Returns the width of the screen. */ - int getWidth() const; + int getWidth() const { return mWidth; } /** * Returns the height of the screen. */ - int getHeight() const; + int getHeight() const { return mHeight; } + + /** + * Returns the current scale ratio of the screen. + */ + int getScale() const { return mScale; } /** * Returns the amount of bits per pixel that was requested (not the @@ -231,6 +236,7 @@ class Graphics : public gcn::SDLGraphics protected: int mWidth; int mHeight; + int mScale; int mBpp; bool mFullscreen; bool mHWAccel; diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 85a4c766..9df8c98c 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -254,6 +254,9 @@ void EquipmentWindow::mouseMoved(gcn::MouseEvent &event) int mouseX, mouseY; SDL_GetMouseState(&mouseX, &mouseY); + mouseX /= graphics->getScale(); + mouseY /= graphics->getScale(); + // Show ItemTooltip std::string slotName = getSlotName(x, y); if (!slotName.empty()) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 78fc42fb..e6e61f64 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -205,6 +205,9 @@ void Gui::draw() int mouseX, mouseY; Uint8 button = SDL_GetMouseState(&mouseX, &mouseY); + mouseX /= graphics->getScale(); + mouseY /= graphics->getScale(); + if ((Client::hasMouseFocus() || button & SDL_BUTTON(1)) && mCustomCursor && mMouseCursorAlpha > 0.0f) diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp index 4ccb7580..46636d52 100644 --- a/src/gui/sdlinput.cpp +++ b/src/gui/sdlinput.cpp @@ -60,6 +60,8 @@ #include <guichan/exception.hpp> +#include "graphics.h" + SDLInput::SDLInput() { mMouseInWindow = true; @@ -73,14 +75,12 @@ bool SDLInput::isKeyQueueEmpty() gcn::KeyInput SDLInput::dequeueKeyInput() { - gcn::KeyInput keyInput; - if (mKeyInputQueue.empty()) { throw GCN_EXCEPTION("The queue is empty."); } - keyInput = mKeyInputQueue.front(); + gcn::KeyInput keyInput = mKeyInputQueue.front(); mKeyInputQueue.pop(); return keyInput; @@ -93,16 +93,19 @@ bool SDLInput::isMouseQueueEmpty() gcn::MouseInput SDLInput::dequeueMouseInput() { - gcn::MouseInput mouseInput; - if (mMouseInputQueue.empty()) { throw GCN_EXCEPTION("The queue is empty."); } - mouseInput = mMouseInputQueue.front(); + gcn::MouseInput mouseInput = mMouseInputQueue.front(); mMouseInputQueue.pop(); + // Scale the mouse input by the graphics scale ratio + int scale = graphics->getScale(); + mouseInput.setX(mouseInput.getX() / scale); + mouseInput.setY(mouseInput.getY() / scale); + return mouseInput; } diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 1b5b00c3..0aab399c 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -286,6 +286,10 @@ void Viewport::logic() void Viewport::_followMouse() { Uint8 button = SDL_GetMouseState(&mMouseX, &mMouseY); + + mMouseX /= graphics->getScale(); + mMouseY /= graphics->getScale(); + // If the left button is dragged if (mPlayerFollowMouse && button & SDL_BUTTON(1)) { @@ -313,6 +317,9 @@ void Viewport::_drawDebugPath(Graphics *graphics) // Get the current mouse position SDL_GetMouseState(&mMouseX, &mMouseY); + mMouseX /= graphics->getScale(); + mMouseY /= graphics->getScale(); + // Prepare the walkmask corresponding to the protocol unsigned char walkMask; switch (Net::getNetworkType()) diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 74a309e1..3e3085a9 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -33,6 +33,8 @@ #include <SDL.h> +#include <cmath> + #ifndef GL_TEXTURE_RECTANGLE_ARB #define GL_TEXTURE_RECTANGLE_ARB 0x84F5 #define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8 @@ -70,8 +72,22 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) int displayFlags = SDL_ANYFORMAT | SDL_OPENGL; - mWidth = w; - mHeight = h; + const double targetRatio = (double) 640 / 360; // 1.77778 + const double requestedRatio = (double) w / h; + mScale = 1; + + if (requestedRatio < targetRatio) { + // Screen is higher / narrower than target aspect ratio: calculate + // scale based on height. + std::cout << ((double) h / 360) << std::endl; + mScale = (int) std::floor((double) h / 360); + } else { + std::cout << ((double) w / 640) << std::endl; + mScale = (int) std::floor((double) w / 640); + } + + mWidth = w / mScale; + mHeight = h / mScale; mBpp = bpp; mFullscreen = fs; mHWAccel = hwaccel; @@ -646,7 +662,7 @@ void OpenGLGraphics::_beginDraw() glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glOrtho(0.0, (double)mTarget->w, (double)mTarget->h, 0.0, -1.0, 1.0); + glOrtho(0.0, (double) mWidth, (double) mHeight, 0.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -659,7 +675,7 @@ void OpenGLGraphics::_beginDraw() glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); - pushClipArea(gcn::Rectangle(0, 0, mTarget->w, mTarget->h)); + pushClipArea(gcn::Rectangle(0, 0, mWidth, mHeight)); } void OpenGLGraphics::_endDraw() @@ -712,6 +728,8 @@ SDL_Surface* OpenGLGraphics::getScreenshot() bool OpenGLGraphics::pushClipArea(gcn::Rectangle area) { + const double ratio = (double) mTarget->w / mWidth; + int transX = 0; int transY = 0; @@ -726,12 +744,15 @@ bool OpenGLGraphics::pushClipArea(gcn::Rectangle area) transX += mClipStack.top().xOffset; transY += mClipStack.top().yOffset; + int x = (int) (mClipStack.top().x * ratio); + int y = mTarget->h - (int) ((mClipStack.top().y + + mClipStack.top().height) * ratio); + int width = (int) (mClipStack.top().width * ratio); + int height = (int) (mClipStack.top().height * ratio); + glPushMatrix(); glTranslatef(transX, transY, 0); - glScissor(mClipStack.top().x, - mTarget->h - mClipStack.top().y - mClipStack.top().height, - mClipStack.top().width, - mClipStack.top().height); + glScissor(x, y, width, height); return result; } @@ -743,11 +764,15 @@ void OpenGLGraphics::popClipArea() if (mClipStack.empty()) return; + const double ratio = (double) mTarget->w / mWidth; + int x = (int) (mClipStack.top().x * ratio); + int y = mTarget->h - (int) ((mClipStack.top().y + + mClipStack.top().height) * ratio); + int width = (int) (mClipStack.top().width * ratio); + int height = (int) (mClipStack.top().height * ratio); + glPopMatrix(); - glScissor(mClipStack.top().x, - mTarget->h - mClipStack.top().y - mClipStack.top().height, - mClipStack.top().width, - mClipStack.top().height); + glScissor(x, y, width, height); } void OpenGLGraphics::setColor(const gcn::Color& color) diff --git a/src/resources/image.cpp b/src/resources/image.cpp index a29d475d..dbed38a2 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -496,6 +496,7 @@ Image *Image::_GLload(SDL_Surface *tmpImage) tmpImage->pixels); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST); if (SDL_MUSTLOCK(tmpImage)) SDL_UnlockSurface(tmpImage); |