aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--TODO.norg2
-rw-r--r--specs/Specs/ViewSpec.hs30
-rw-r--r--src/Chelleport/Config.hs6
-rw-r--r--src/Chelleport/Draw.hs8
-rw-r--r--src/Chelleport/Types.hs6
-rw-r--r--src/Chelleport/View.hs7
6 files changed, 35 insertions, 24 deletions
diff --git a/TODO.norg b/TODO.norg
index 2228e2d..591118c 100644
--- a/TODO.norg
+++ b/TODO.norg
@@ -1,6 +1,4 @@
* Current
- - ( ) Investigate memory leak with c++ ffi when re-evaluating ocr
- - ( ) TextStyle for drawText
- ( ) Middle click
- (-) Optimize speed of ocr
- ( ) Backspace deletes a single character in search mode
diff --git a/specs/Specs/ViewSpec.hs b/specs/Specs/ViewSpec.hs
index a5a67c9..9d7dfda 100644
--- a/specs/Specs/ViewSpec.hs
+++ b/specs/Specs/ViewSpec.hs
@@ -19,10 +19,10 @@ test = do
(_, mock) <- runWithMocks $ do
Mock_windowSize `mockReturns` mockWindowSize
render currentState
- mock `shouldHaveCalled` Mock_drawText (460, 10) colorWhite FontLG "ABC"
- mock `shouldHaveCalled` Mock_drawText (1420, 10) colorWhite FontLG "DEF"
- mock `shouldHaveCalled` Mock_drawText (460, 550) colorWhite FontLG "DJK"
- mock `shouldHaveCalled` Mock_drawText (1420, 550) colorWhite FontLG "JKL"
+ mock `shouldHaveCalled` Mock_drawText (460, 10) (hintLabelTextStyle {textColor = colorWhite}) "ABC"
+ mock `shouldHaveCalled` Mock_drawText (1420, 10) (hintLabelTextStyle {textColor = colorWhite}) "DEF"
+ mock `shouldHaveCalled` Mock_drawText (460, 550) (hintLabelTextStyle {textColor = colorWhite}) "DJK"
+ mock `shouldHaveCalled` Mock_drawText (1420, 550) (hintLabelTextStyle {textColor = colorWhite}) "JKL"
context "when there is a partial match" $ do
let currentState = defaultState {stateMode = ModeHints (modeHintsData $ stateMode defaultState) {stateKeySequence = "D"}}
@@ -30,13 +30,13 @@ test = do
it "draws matching text labels" $ do
(_, mock) <- runWithMocks $ do
Mock_windowSize `mockReturns` mockWindowSize
- Mock_drawText (1420, 10) colorLightGray FontLG "D" `mockReturns` (10, 0)
- Mock_drawText (460, 550) colorLightGray FontLG "D" `mockReturns` (10, 0)
+ Mock_drawText (1420, 10) (hintLabelTextStyle {textColor = colorLightGray}) "D" `mockReturns` (10, 0)
+ Mock_drawText (460, 550) (hintLabelTextStyle {textColor = colorLightGray}) "D" `mockReturns` (10, 0)
render currentState
- mock `shouldHaveCalled` Mock_drawText (1420, 10) colorLightGray FontLG "D"
- mock `shouldHaveCalled` Mock_drawText (1430, 10) colorAccent FontLG "EF"
- mock `shouldHaveCalled` Mock_drawText (460, 550) colorLightGray FontLG "D"
- mock `shouldHaveCalled` Mock_drawText (470, 550) colorAccent FontLG "JK"
+ mock `shouldHaveCalled` Mock_drawText (1420, 10) (hintLabelTextStyle {textColor = colorLightGray}) "D"
+ mock `shouldHaveCalled` Mock_drawText (1430, 10) (hintLabelTextStyle {textColor = colorAccent}) "EF"
+ mock `shouldHaveCalled` Mock_drawText (460, 550) (hintLabelTextStyle {textColor = colorLightGray}) "D"
+ mock `shouldHaveCalled` Mock_drawText (470, 550) (hintLabelTextStyle {textColor = colorAccent}) "JK"
context "when key sequence is complete match" $ do
let currentState = defaultState {stateMode = ModeHints (modeHintsData $ stateMode defaultState) {stateKeySequence = "DEF"}}
@@ -45,17 +45,17 @@ test = do
(_, mock) <- runWithMocks $ do
Mock_windowSize `mockReturns` mockWindowSize
render currentState
- mock `shouldHaveCalled` Mock_drawText (1420, 10) colorLightGray FontLG "DEF"
+ mock `shouldHaveCalled` Mock_drawText (1420, 10) (hintLabelTextStyle {textColor = colorLightGray}) "DEF"
describe "#renderKeySequence" $ do
context "when there is a partial match" $ do
it "draws the matched section and highlights the remaining characters" $ do
(_, mock) <- runWithMocks $ do
Mock_windowSize `mockReturns` mockWindowSize
- Mock_drawText (0, 0) colorLightGray FontLG "ABC" `mockReturns` (30, 0)
+ Mock_drawText (0, 0) (hintLabelTextStyle {textColor = colorLightGray}) "ABC" `mockReturns` (30, 0)
renderKeySequence "ABC" "ABCDE" (0, 0)
- mock `shouldHaveCalled` Mock_drawText (0, 0) colorLightGray FontLG "ABC"
- mock `shouldHaveCalled` Mock_drawText (30, 0) colorAccent FontLG "DE"
+ mock `shouldHaveCalled` Mock_drawText (0, 0) (hintLabelTextStyle {textColor = colorLightGray}) "ABC"
+ mock `shouldHaveCalled` Mock_drawText (30, 0) (hintLabelTextStyle {textColor = colorAccent}) "DE"
it "return true as the text is visible" $ do
(isVisible, _) <- runWithMocks $ renderKeySequence "ABC" "ABCDE" (0, 0)
@@ -64,7 +64,7 @@ test = do
context "when there is no input key sequence" $ do
it "draws text as a single chunk" $ do
(_, mock) <- runWithMocks $ renderKeySequence "" "ABCD" (0, 0)
- mock `shouldHaveCalled` Mock_drawText (0, 0) colorWhite FontLG "ABCD"
+ mock `shouldHaveCalled` Mock_drawText (0, 0) (hintLabelTextStyle {textColor = colorWhite}) "ABCD"
it "return true as the text is visible" $ do
(isVisible, _) <- runWithMocks $ renderKeySequence "" "ABCD" (0, 0)
diff --git a/src/Chelleport/Config.hs b/src/Chelleport/Config.hs
index b75abc0..398e3d6 100644
--- a/src/Chelleport/Config.hs
+++ b/src/Chelleport/Config.hs
@@ -4,6 +4,12 @@ import Chelleport.Types
import Foreign.C (CFloat)
import qualified SDL
+searchingTextStyle :: TextStyle
+searchingTextStyle = TextStyle {textColor = colorWhite, textSize = FontSM}
+
+hintLabelTextStyle :: TextStyle
+hintLabelTextStyle = TextStyle {textColor = colorWhite, textSize = FontLG}
+
colorWhite :: Color
colorWhite = SDL.V4 255 255 255 255
diff --git a/src/Chelleport/Draw.hs b/src/Chelleport/Draw.hs
index afb72ca..2d3a77c 100644
--- a/src/Chelleport/Draw.hs
+++ b/src/Chelleport/Draw.hs
@@ -12,7 +12,7 @@ import qualified SDL.Font as TTF
class (Monad m) => MonadDraw m where
drawLine :: (CInt, CInt) -> (CInt, CInt) -> m ()
- drawText :: (CInt, CInt) -> Color -> FontSize -> Text -> m (CInt, CInt)
+ drawText :: (CInt, CInt) -> TextStyle -> Text -> m (CInt, CInt)
drawCircle :: Int -> (CInt, CInt) -> m ()
fillRect :: (CInt, CInt) -> (CInt, CInt) -> m ()
setDrawColor :: Color -> m ()
@@ -33,12 +33,12 @@ instance (MonadIO m) => MonadDraw (AppM m) where
let rect = SDL.Rectangle (SDL.P $ SDL.V2 x y) (SDL.V2 w h)
SDL.fillRect renderer (Just rect)
- drawText (x, y) color size text = do
+ drawText (x, y) (TextStyle {textColor, textSize}) text = do
DrawContext {ctxRenderer = renderer, ctxFontSmall, ctxFontLarge} <- ask
- let font = case size of
+ let font = case textSize of
FontSM -> ctxFontSmall
FontLG -> ctxFontLarge
- surface <- TTF.blended font color text
+ surface <- TTF.blended font textColor text
texture <- SDL.createTextureFromSurface renderer surface
SDL.freeSurface surface
diff --git a/src/Chelleport/Types.hs b/src/Chelleport/Types.hs
index ca4742e..56e6d8c 100644
--- a/src/Chelleport/Types.hs
+++ b/src/Chelleport/Types.hs
@@ -152,3 +152,9 @@ data Configuration = Configuration
instance Default Configuration where
def = Configuration {configMode = ModeHints def, configShowHelp = False}
+
+data TextStyle = TextStyle
+ { textColor :: Color,
+ textSize :: FontSize
+ }
+ deriving (Show, Eq)
diff --git a/src/Chelleport/View.hs b/src/Chelleport/View.hs
index 8cb6094..42c23a9 100644
--- a/src/Chelleport/View.hs
+++ b/src/Chelleport/View.hs
@@ -33,7 +33,8 @@ renderSearchView state searchData@(ModeSearchData {searchFilteredWords, searchHi
fillRectVertices (matchStartX, matchStartY) (matchEndX, matchEndY)
(w, h) <- windowSize
- void $ drawText (w `div` 2, h `div` 2) colorWhite FontSM (Text.pack $ getSearchText state searchData)
+ let textStyle = TextStyle {textColor = colorWhite, textSize = FontSM}
+ void $ drawText (w `div` 2, h `div` 2) textStyle (Text.pack $ getSearchText state searchData)
renderHintsView :: (MonadDraw m) => State -> ModeHintsData -> m ()
renderHintsView state (ModeHintsData {stateGrid, stateKeySequence, stateIsMatched}) = do
@@ -63,12 +64,12 @@ renderKeySequence keySequence cell (px, py) = do
previousTextWidth <-
if isNotEmpty matched
- then fst <$> drawText (px, py) colorLightGray FontLG (Text.pack matched)
+ then fst <$> drawText (px, py) (hintLabelTextStyle {textColor = colorLightGray}) (Text.pack matched)
else pure 0
when (isNotEmpty remaining) $ case textColor of
Just color -> do
- void $ drawText (px + previousTextWidth, py) color FontLG $ Text.pack remaining
+ void $ drawText (px + previousTextWidth, py) (hintLabelTextStyle {textColor = color}) $ Text.pack remaining
Nothing -> pure ()
pure isVisible