summaryrefslogtreecommitdiff
path: root/src/graphics.h
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-02-27 10:51:33 +0000
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-02-27 10:51:33 +0000
commit254c3db4a39aa35274fd7cd4ec2cccde5b92d71b (patch)
tree01c1b5ad71794c02b03d9c45f2c4b5043bc03163 /src/graphics.h
parent81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08 (diff)
downloadmana-254c3db4a39aa35274fd7cd4ec2cccde5b92d71b.tar.gz
mana-254c3db4a39aa35274fd7cd4ec2cccde5b92d71b.tar.bz2
mana-254c3db4a39aa35274fd7cd4ec2cccde5b92d71b.tar.xz
mana-254c3db4a39aa35274fd7cd4ec2cccde5b92d71b.zip
Added VSync and windowed fullscreen options
The configuration and setup UI were adjusted to the new options. This also fixes issues in applying new video settings. Default resolution was changed from 800x600 to 1280x720. VSync is enabled by default while FPS limit was disabled. Display aspect ratio for the resolution options. I had to work around some macOS issues: * Don't change window size when it appears to be "maximized", since it just changes the rendering area while leaving the window maximized. * Unset fullscreen display mode temporarily to allow changing resolutions, otherwise the rendering area no longer matches the screen and mouse input is also off. * Removed SDL_WINDOW_ALLOW_HIGHDPI for now because it causes issues on macOS, since we're not actually handling the scaling factor. A Video class and an SDLGraphics subclass were split off from Graphics. This setup has Less duplication and leaves the OpenGLGraphics and SDLGraphics better separated. Fixes #57 Fixes #58
Diffstat (limited to 'src/graphics.h')
-rw-r--r--src/graphics.h114
1 files changed, 27 insertions, 87 deletions
diff --git a/src/graphics.h b/src/graphics.h
index 24483078..956e729d 100644
--- a/src/graphics.h
+++ b/src/graphics.h
@@ -28,10 +28,6 @@
#include <guichan/graphics.hpp>
class Image;
-class ImageRect;
-
-static const int defaultScreenWidth = 800;
-static const int defaultScreenHeight = 600;
/**
* 9 images defining a rectangle. 4 corners, 4 sides and a middle area. The
@@ -79,32 +75,15 @@ class Graphics : public gcn::Graphics
public:
Graphics() = default;
- ~Graphics() override;
-
- /**
- * Sets the target SDL_Window to draw to. This funtion also pushes a
- * clip areas corresponding to the dimension of the target.
- *
- * @param target the target to draw to.
- */
- virtual void setTarget(SDL_Window *target);
-
- SDL_Window *getTarget() const { return mTarget; }
- SDL_Renderer *getRenderer() const { return mRenderer; }
-
/**
- * Try to create a window with the given settings.
+ * Sets whether vertical refresh syncing is enabled.
*/
- virtual bool setVideoMode(int w, int h, bool fs);
-
- /**
- * Change the video mode. Can be used for switching to full screen,
- * changing resolution or adapting after window resize.
- */
- bool changeVideoMode(int w, int h, bool fs);
+ virtual void setVSync(bool sync) = 0;
virtual void videoResized(int w, int h);
+ using gcn::Graphics::drawImage;
+
/**
* Blits an image onto the screen.
*
@@ -114,26 +93,13 @@ class Graphics : public gcn::Graphics
bool drawImage(Image *image, int x, int y);
/**
- * Draws a resclaled version of the image
- */
- bool drawRescaledImage(Image *image, int srcX, int srcY,
- int dstX, int dstY,
- int width, int height,
- int desiredWidth, int desiredHeight)
- { return drawRescaledImage(image, srcX, srcY,
- dstX, dstY,
- width, height,
- desiredWidth, desiredHeight,
- false); }
-
- /**
- * Draws a resclaled version of the image
+ * Draws a rescaled version of the image.
*/
virtual bool drawRescaledImage(Image *image, int srcX, int srcY,
- int dstX, int dstY,
- int width, int height,
- int desiredWidth, int desiredHeight,
- bool useColor = false);
+ int dstX, int dstY,
+ int width, int height,
+ int desiredWidth, int desiredHeight,
+ bool useColor = false) = 0;
/**
* Blits an image onto the screen.
@@ -155,28 +121,28 @@ class Graphics : public gcn::Graphics
* Draw a pattern based on a rescaled version of the given image...
*/
virtual void drawRescaledImagePattern(Image *image,
- int x, int y, int w, int h,
- int scaledWidth, int scaledHeight);
+ int x, int y,
+ int w, int h,
+ int scaledWidth,
+ int scaledHeight) = 0;
/**
* Draws a rectangle using images. 4 corner images, 4 side images and 1
* image for the inside.
*/
- void drawImageRect(
- int x, int y, int w, int h,
- Image *topLeft, Image *topRight,
- Image *bottomLeft, Image *bottomRight,
- Image *top, Image *right,
- Image *bottom, Image *left,
- Image *center);
+ void drawImageRect(int x, int y, int w, int h,
+ Image *topLeft, Image *topRight,
+ Image *bottomLeft, Image *bottomRight,
+ Image *top, Image *right,
+ Image *bottom, Image *left,
+ Image *center);
/**
* Draws a rectangle using images. 4 corner images, 4 side images and 1
* image for the inside.
*/
- void drawImageRect(
- int x, int y, int w, int h,
- const ImageRect &imgRect);
+ void drawImageRect(int x, int y, int w, int h,
+ const ImageRect &imgRect);
/**
* Draws a rectangle using images. 4 corner images, 4 side images and 1
@@ -192,7 +158,7 @@ class Graphics : public gcn::Graphics
* Updates the screen. This is done by either copying the buffer to the
* screen or swapping pages.
*/
- virtual void updateScreen();
+ virtual void updateScreen() = 0;
/**
* Returns the width of the screen.
@@ -205,57 +171,31 @@ class Graphics : public gcn::Graphics
int getHeight() const;
/**
- * Returns whether we're in a full screen mode.
- */
- bool getFullscreen() const { return mFullscreen; }
-
- /**
* Takes a screenshot and returns it as SDL surface.
*/
- virtual SDL_Surface *getScreenshot();
+ virtual SDL_Surface *getScreenshot() = 0;
gcn::Font *getFont() const { return mFont; }
- bool pushClipArea(gcn::Rectangle area) override;
-
- void popClipArea() override;
-
void drawImage(const gcn::Image *image,
- int srcX,
- int srcY,
- int dstX,
- int dstY,
- int width,
- int height) override {} // not used
-
- void drawPoint(int x, int y) override;
-
- void drawLine(int x1, int y1, int x2, int y2) override;
-
- void drawRectangle(const gcn::Rectangle &rectangle) override;
-
- void fillRectangle(const gcn::Rectangle &rectangle) override;
+ int srcX, int srcY,
+ int dstX, int dstY,
+ int width, int height) override {} // not used
void setColor(const gcn::Color &color) override
{
mColor = color;
}
- const gcn::Color &getColor() const override
+ const gcn::Color &getColor() const final
{
return mColor;
}
protected:
- void updateSDLClipRect();
-
int mWidth = 0;
int mHeight = 0;
- bool mFullscreen = false;
gcn::Color mColor;
-
- SDL_Window *mTarget = nullptr;
- SDL_Renderer *mRenderer = nullptr;
};
extern Graphics *graphics;