Skip to content

Commit

Permalink
Measure Text Once in Header
Browse files Browse the repository at this point in the history
  • Loading branch information
btmura committed Jun 13, 2011
1 parent 8346a37 commit 91ddcdd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/B1/Program/Chart/Header.hs
Expand Up @@ -62,6 +62,7 @@ data HeaderState = HeaderState
, getStatus :: Symbol -> StockData -> IO HeaderStatus
, isStatusShowing :: Bool
, statusAlphaAnimation :: Animation (GLfloat, Dirty)
, maybeTextBounds :: Maybe Box
}

data HeaderStatus = HeaderStatus String (GLfloat -> Color4 GLfloat)
Expand All @@ -76,6 +77,7 @@ newHeaderState options = HeaderState
, getStatus = statusFunction
, isStatusShowing = False
, statusAlphaAnimation = animateOnce $ linearRange 0 1 30
, maybeTextBounds = Nothing
}
where
statusFunction = case statusStyle options of
Expand Down Expand Up @@ -103,19 +105,20 @@ drawHeader resources@Resources
, getStatus = getStatus
, isStatusShowing = isStatusShowing
, statusAlphaAnimation = statusAlphaAnimation
, maybeTextBounds = maybeTextBounds
}
} =
preservingMatrix $ do
translate $ vector3 (-(boxWidth bounds / 2)) (boxHeight bounds / 2) 0

HeaderStatus statusText statusColor <- getStatus symbol stockData
let statusTextSpec = headerTextSpec statusText
statusBox <- measureText statusTextSpec
textBounds <- maybe (measureText statusTextSpec) return maybeTextBounds

let statusHeight = boxHeight statusBox
let textHeight = boxHeight textBounds
statusAlpha = fst $ current statusAlphaAnimation
headerHeight = padding + statusHeight + padding
statusY = (-headerHeight - statusHeight) / 2
headerHeight = padding + textHeight + padding
statusY = (-headerHeight - textHeight) / 2

preservingMatrix $ do
translate $ vector3 headerHeight statusY 0
Expand All @@ -140,6 +143,7 @@ drawHeader resources@Resources
outputState = inputState
{ isStatusShowing = nextIsStatusShowing
, statusAlphaAnimation = nextStatusAlphaAnimation
, maybeTextBounds = Just textBounds
}
nextIsDirty = (snd . current) nextStatusAlphaAnimation
nextButtonClickedSymbol =
Expand Down

0 comments on commit 91ddcdd

Please sign in to comment.