Skip to content
This repository was archived by the owner on Jan 17, 2020. It is now read-only.

Add a viewportDimensions option for high DPI #136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Helm/Engine/SDL/Engine.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Helm.Engine.SDL.Engine
import Control.Monad (when)

import Data.Foldable (forM_)
import Data.Maybe (fromMaybe)
import qualified Data.Text as T
import Data.Word (Word32)
import Foreign.Ptr (castPtr)
Expand Down Expand Up @@ -51,6 +52,7 @@ import Helm.Graphics2D.Text (Text(..), FontWeight(..), FontStyle(..),
-- Use 'defaultConfig' and then only change the necessary fields.
data SDLEngineConfig = SDLEngineConfig
{ windowDimensions :: V2 Int -- ^ The initial SDL window size.
, viewportDimensions :: Maybe (V2 Int) -- ^ The initial SDL viewport size.
, windowIsFullscreen :: !Bool -- ^ Whether the SDL window should start fullscreen.
, windowIsResizable :: !Bool -- ^ Whether the SDL window should be resizable.
, windowTitle :: !String -- ^ The initial SDL window title.
Expand Down Expand Up @@ -176,6 +178,7 @@ instance Engine SDLEngine where
defaultConfig :: SDLEngineConfig
defaultConfig = SDLEngineConfig
{ windowDimensions = V2 800 600
, viewportDimensions = Nothing
, windowIsFullscreen = False
, windowIsResizable = True
, windowTitle = "Helm"
Expand Down Expand Up @@ -207,7 +210,7 @@ startupWith config@SDLEngineConfig { .. } = do
-- Initialize the SDL window from our provided engine config.
window <- Video.createWindow (T.pack windowTitle) windowConfig
renderer <- Video.createRenderer window (-1) rendererConfig
texture <- prepTexture windowDimensions renderer
texture <- prepTexture viewportDimensions' renderer

-- Initialize all of the sinks and signals that SDL events will be sunk into.
mouseMoveEvent <- externalMulti
Expand Down Expand Up @@ -257,7 +260,9 @@ startupWith config@SDLEngineConfig { .. } = do
then Video.Fullscreen
else Video.Windowed
, windowResizable = windowIsResizable
, windowHighDPI = True
}
viewportDimensions' = fromMaybe windowDimensions viewportDimensions

-- | Renders a 2D element to the engine screen.
render2d
Expand Down