Created
August 7, 2015 01:11
-
-
Save nsf/0aec3c45c013c6ae0090 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type DefaultWindowStyle () as this = | |
member val Color = ShadowedTextColor(RGBA8.White, RGBA8(0, 0, 0, 127)) with get, set | |
member val Alignment = TextAlignment.Left with get, set | |
member val Ellipsis = Char.ConvertToUtf32("…", 0) with get, set | |
member val Font = getFont guiResourceGroup "fonts/dejavu.font" with get, set | |
member val DecorNine : LazyNineAtlasTextures = getNineAtlasTextures guiResourceGroup "atlases/gui.atlas#decor" with get, set | |
member val HandleSizes = lazy (this.DecorNine.Sizes |> Array.map (Vec2i.Max (Vec2i 5))) | |
interface IWindowStyle with | |
override s.AdditionalSize w = nineAdditionalSize s.DecorNine.Sizes | |
override s.InnerRect w = nineInnerRect w.IdleRect s.DecorNine.Sizes | |
override s.ClassifyPart (p, w) = | |
let hs = s.HandleSizes.Value | |
let r = w.Rect | |
// corners | |
if (Rect.SizedAt hs.[0] r.TopLeft).Contains p then | |
WindowPart.TopLeft | |
elif (Rect.SizedAt hs.[2] (r.TopRight - Vec2i(X=hs.[2].X - 1))).Contains p then | |
WindowPart.TopRight | |
elif (Rect.SizedAt hs.[6] (r.BottomLeft - Vec2i(Y=hs.[6].Y - 1))).Contains p then | |
WindowPart.BottomLeft | |
elif (Rect.SizedAt hs.[8] (r.BottomRight - hs.[8] + Vec2i(1))).Contains p then | |
WindowPart.BottomRight | |
// sides | |
elif Rect(r.Left + hs.[0].X, r.Top, r.Right - hs.[2].X, r.Top + hs.[1].Y - 1).Contains p then | |
WindowPart.Top | |
elif Rect(r.Left, r.Top + hs.[0].Y, r.Left + hs.[3].X - 1, r.Bottom - hs.[6].Y).Contains p then | |
WindowPart.Left | |
elif Rect(r.Right - hs.[5].X + 1, r.Top + hs.[2].Y, r.Right, r.Bottom - hs.[8].Y).Contains p then | |
WindowPart.Right | |
elif Rect(r.Left + hs.[6].X, r.Bottom - hs.[7].Y + 1, r.Right - hs.[8].X, r.Bottom).Contains p then | |
WindowPart.Bottom | |
else | |
WindowPart.Center | |
override s.Draw (dc, w) = | |
if not (String.IsNullOrEmpty w.Caption) then | |
let r = nineHeaderRect w.IdleRect s.DecorNine.Sizes | |
let r = Rect.CenteredIn (r.Size - Vec2i(X=10)) r | |
dc.Text(2, s.Font.Value, w.Caption, s.Alignment, s.Ellipsis, r, s.Color.Normal) | |
let r = r.Moved(Vec2i(Y=1)) | |
dc.Text(1, s.Font.Value, w.Caption, s.Alignment, s.Ellipsis, r, s.Color.Shadow) | |
dc.BlendFunc(0, BlendFactor.One, BlendFactor.Zero, BlendFactor.One, BlendFactor.Zero) | |
dc.NineAtlasQuads(0, s.DecorNine.Value, w.IdleRect, "sssssssss", RGBA8.White) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment