compressed some ui drawing code.
This commit is contained in:
parent
a0072cd57b
commit
dc25b268f7
|
@ -139,7 +139,7 @@ INITIALIZE_APPLICATION(InitializeApplication)
|
||||||
AddCodepointToFont(Font, Codepoint, 0, 0, CodepointW, CodepointH, CodepointX, CodepointY);
|
AddCodepointToFont(Font, Codepoint, 0, 0, CodepointW, CodepointH, CodepointX, CodepointY);
|
||||||
}
|
}
|
||||||
|
|
||||||
State->Interface.Font = Font;
|
State->Interface_.Style.Font = Font;
|
||||||
|
|
||||||
Font->BitmapTextureHandle = Context.PlatformGetGPUTextureHandle(Font->BitmapMemory,
|
Font->BitmapTextureHandle = Context.PlatformGetGPUTextureHandle(Font->BitmapMemory,
|
||||||
Font->BitmapWidth, Font->BitmapHeight);
|
Font->BitmapWidth, Font->BitmapHeight);
|
||||||
|
@ -150,23 +150,21 @@ INITIALIZE_APPLICATION(InitializeApplication)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
State->Interface.FontSize = FontSize;
|
State->Interface_.Style.FontSize = FontSize;
|
||||||
State->Interface.PanelBGColors[0] = v4{.3f, .3f, .3f, 1};
|
State->Interface_.Style.PanelBGColors[0] = v4{.3f, .3f, .3f, 1};
|
||||||
State->Interface.PanelBGColors[1] = v4{.4f, .4f, .4f, 1};
|
State->Interface_.Style.PanelBGColors[1] = v4{.4f, .4f, .4f, 1};
|
||||||
State->Interface.PanelBGColors[2] = v4{.5f, .5f, .5f, 1};
|
State->Interface_.Style.PanelBGColors[2] = v4{.5f, .5f, .5f, 1};
|
||||||
State->Interface.PanelBGColors[3] = v4{.6f, .6f, .6f, 1};
|
State->Interface_.Style.PanelBGColors[3] = v4{.6f, .6f, .6f, 1};
|
||||||
State->Interface.ButtonColor_Inactive = BlackV4;
|
State->Interface_.Style.ButtonColor_Inactive = BlackV4;
|
||||||
State->Interface.ButtonColor_Active = v4{.1f, .1f, .1f, 1};
|
State->Interface_.Style.ButtonColor_Active = v4{.1f, .1f, .1f, 1};
|
||||||
State->Interface.ButtonColor_Selected = v4{.1f, .1f, .3f, 1};
|
State->Interface_.Style.ButtonColor_Selected = v4{.1f, .1f, .3f, 1};
|
||||||
State->Interface.TextColor = WhiteV4;
|
State->Interface_.Style.TextColor = WhiteV4;
|
||||||
State->Interface.ListBGColors[0] = v4{ .16f, .16f, .16f, 1.f };
|
State->Interface_.Style.ListBGColors[0] = v4{ .16f, .16f, .16f, 1.f };
|
||||||
State->Interface.ListBGColors[1] = v4{ .18f, .18f, .18f, 1.f };
|
State->Interface_.Style.ListBGColors[1] = v4{ .18f, .18f, .18f, 1.f };
|
||||||
State->Interface.ListBGHover = v4{ .22f, .22f, .22f, 1.f };
|
State->Interface_.Style.ListBGHover = v4{ .22f, .22f, .22f, 1.f };
|
||||||
State->Interface.ListBGSelected = v4{.44f, .44f, .44f, 1.f };
|
State->Interface_.Style.ListBGSelected = v4{.44f, .44f, .44f, 1.f };
|
||||||
State->Interface.Margin = v2{5, 5};
|
State->Interface_.Style.Margin = v2{5, 5};
|
||||||
State->Interface.RowHeight = State->Interface.Font->PixelHeight + 2 * State->Interface.Margin.y;
|
State->Interface_.Style.RowHeight = ui_GetTextLineHeight(State->Interface_);
|
||||||
|
|
||||||
State->Interface_.Style = State->Interface;
|
|
||||||
|
|
||||||
State->SACN = InitializeSACN(Context);
|
State->SACN = InitializeSACN(Context);
|
||||||
State->NetworkProtocolHeaderSize = STREAM_HEADER_SIZE;
|
State->NetworkProtocolHeaderSize = STREAM_HEADER_SIZE;
|
||||||
|
|
|
@ -72,7 +72,6 @@ struct app_state
|
||||||
text_entry ActiveTextEntry;
|
text_entry ActiveTextEntry;
|
||||||
|
|
||||||
ui_interface Interface_;
|
ui_interface Interface_;
|
||||||
interface_config Interface;
|
|
||||||
|
|
||||||
animation_system AnimationSystem;
|
animation_system AnimationSystem;
|
||||||
gs_list_handle SelectedAnimationBlockHandle;
|
gs_list_handle SelectedAnimationBlockHandle;
|
||||||
|
|
|
@ -339,10 +339,18 @@ ui_LayoutRemaining(ui_layout Layout)
|
||||||
}
|
}
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Drawing Functions
|
// Drawing Functions
|
||||||
//
|
//
|
||||||
|
|
||||||
|
static r32
|
||||||
|
ui_GetTextLineHeight(ui_interface Interface)
|
||||||
|
{
|
||||||
|
r32 Result = Interface.Style.Font->PixelHeight + (2 * Interface.Style.Margin.y);
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ui_FillRect(ui_interface* Interface, rect Bounds, v4 Color)
|
ui_FillRect(ui_interface* Interface, rect Bounds, v4 Color)
|
||||||
{
|
{
|
||||||
|
@ -430,6 +438,37 @@ ui_Button(ui_interface* Interface, string Text, rect Bounds)
|
||||||
return ui_Button(Interface, Text, Bounds, BGColor, HoverColor, SelectedColor);
|
return ui_Button(Interface, Text, Bounds, BGColor, HoverColor, SelectedColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct list_item_colors
|
||||||
|
{
|
||||||
|
v4 Hover;
|
||||||
|
v4 Selected;
|
||||||
|
v4 BGColor;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline v4
|
||||||
|
ui_GetListItemBGColor(interface_config Style, u32 ElementIndex)
|
||||||
|
{
|
||||||
|
v4 Result = Style.ListBGColors[ElementIndex % LIST_BG_COLORS_COUNT];
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static list_item_colors
|
||||||
|
ui_GetListItemColors(ui_interface* Interface, u32 ListItemIndex)
|
||||||
|
{
|
||||||
|
list_item_colors Result = {};
|
||||||
|
Result.Hover = Interface->Style.ListBGHover;
|
||||||
|
Result.Selected = Interface->Style.ListBGSelected;
|
||||||
|
Result.BGColor = ui_GetListItemBGColor(Interface->Style, ListItemIndex);
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static b32
|
||||||
|
ui_ListButton(ui_interface* Interface, string Text, rect Bounds, u32 ListItemIndex)
|
||||||
|
{
|
||||||
|
list_item_colors Colors = ui_GetListItemColors(Interface, ListItemIndex);
|
||||||
|
return ui_Button(Interface, Text, Bounds, Colors.Hover, Colors.Selected, Colors.BGColor);
|
||||||
|
}
|
||||||
|
|
||||||
static b32
|
static b32
|
||||||
ui_LayoutButton(ui_interface* Interface, ui_layout* Layout, string Text, v4 BGColor, v4 HoverColor, v4 SelectColor)
|
ui_LayoutButton(ui_interface* Interface, ui_layout* Layout, string Text, v4 BGColor, v4 HoverColor, v4 SelectColor)
|
||||||
{
|
{
|
||||||
|
@ -450,11 +489,11 @@ ui_LayoutButton(ui_interface* Interface, ui_layout* Layout, string Text)
|
||||||
return ui_LayoutButton(Interface, Layout, Text, BGColor, HoverColor, SelectedColor);
|
return ui_LayoutButton(Interface, Layout, Text, BGColor, HoverColor, SelectedColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline v4
|
static b32
|
||||||
ui_GetListItemBGColor(interface_config Style, u32 ElementIndex)
|
ui_LayoutListButton(ui_interface* Interface, ui_layout* Layout, string Text, u32 ListItemIndex)
|
||||||
{
|
{
|
||||||
v4 Result = Style.ListBGColors[ElementIndex % LIST_BG_COLORS_COUNT];
|
list_item_colors Colors = ui_GetListItemColors(Interface, ListItemIndex);
|
||||||
return Result;
|
return ui_LayoutButton(Interface, Layout, Text, Colors.Hover, Colors.Selected, Colors.BGColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
static b32
|
static b32
|
||||||
|
|
|
@ -317,7 +317,7 @@ DrawFrameBar (animation_system* AnimationSystem, render_command_buffer* RenderBu
|
||||||
r32 FramePercent = FrameToPercentRange(Frame, VisibleFrames);
|
r32 FramePercent = FrameToPercentRange(Frame, VisibleFrames);
|
||||||
r32 FrameX = GSLerp(BarBounds.Min.x, BarBounds.Max.x, FramePercent);
|
r32 FrameX = GSLerp(BarBounds.Min.x, BarBounds.Max.x, FramePercent);
|
||||||
v2 FrameTextPos = v2{FrameX, BarBounds.Min.y + 2};
|
v2 FrameTextPos = v2{FrameX, BarBounds.Min.y + 2};
|
||||||
DrawString(RenderBuffer, TempString, State->Interface.Font, FrameTextPos, WhiteV4);
|
DrawString(RenderBuffer, TempString, State->Interface_.Style.Font, FrameTextPos, WhiteV4);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Time Slider
|
// Time Slider
|
||||||
|
@ -335,7 +335,7 @@ DrawFrameBar (animation_system* AnimationSystem, render_command_buffer* RenderBu
|
||||||
PushRenderQuad2D(RenderBuffer, HeadMin, HeadMax, TimeSliderColor);
|
PushRenderQuad2D(RenderBuffer, HeadMin, HeadMax, TimeSliderColor);
|
||||||
|
|
||||||
PrintF(&TempString, "%d", AnimationSystem->CurrentFrame);
|
PrintF(&TempString, "%d", AnimationSystem->CurrentFrame);
|
||||||
DrawString(RenderBuffer, TempString, State->Interface.Font, HeadMin + v2{6, 4}, WhiteV4);
|
DrawString(RenderBuffer, TempString, State->Interface_.Style.Font, HeadMin + v2{6, 4}, WhiteV4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,7 +418,7 @@ DrawLayerMenu(animation_system* AnimationSystem, rect PanelDim, render_command_b
|
||||||
{
|
{
|
||||||
PushRenderBoundingBox2D(RenderBuffer, gs_RectExpand(LayerBounds), 1, WhiteV4);
|
PushRenderBoundingBox2D(RenderBuffer, gs_RectExpand(LayerBounds), 1, WhiteV4);
|
||||||
}
|
}
|
||||||
DrawString(RenderBuffer, Layer->Name, State->Interface.Font, LayerTextPos, WhiteV4);
|
DrawString(RenderBuffer, Layer->Name, State->Interface_.Style.Font, LayerTextPos, WhiteV4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,42 +30,40 @@ internal void
|
||||||
HierarchyView_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context, mouse_state Mouse)
|
HierarchyView_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context, mouse_state Mouse)
|
||||||
{
|
{
|
||||||
ui_layout Layout = ui_CreateLayout(State->Interface_, PanelBounds);
|
ui_layout Layout = ui_CreateLayout(State->Interface_, PanelBounds);
|
||||||
v4 ListItemHover = State->Interface_.Style.ListBGHover;
|
|
||||||
v4 ListItemSelected = State->Interface_.Style.ListBGSelected;
|
|
||||||
|
|
||||||
string TempString = PushString(&State->Transient, 256);
|
string TempString = PushString(&State->Transient, 256);
|
||||||
|
|
||||||
u32 LineCount = (u32)(gs_Height(PanelBounds) / Layout.RowHeight) + 1;
|
u32 LineCount = (u32)(gs_Height(PanelBounds) / Layout.RowHeight) + 1;
|
||||||
u32 LinesDrawn = 0;
|
|
||||||
u32 AssembliesToDraw = GSMin(LineCount, State->Assemblies.Count);
|
u32 AssembliesToDraw = GSMin(LineCount, State->Assemblies.Count);
|
||||||
|
rect* LineBounds = PushArray(&State->Transient, rect, LineCount);
|
||||||
|
|
||||||
|
// Fill in alternating color rows for the backgrounds
|
||||||
|
for (u32 Line = 0; Line < LineCount; Line++)
|
||||||
|
{
|
||||||
|
LineBounds[Line] = ui_ReserveElementBounds(&Layout);
|
||||||
|
v4 ListItemBGColor = ui_GetListItemBGColor(State->Interface_.Style, Line);
|
||||||
|
ui_FillRect(&State->Interface_, LineBounds[Line], ListItemBGColor);
|
||||||
|
}
|
||||||
|
|
||||||
for (u32 AssemblyIndex = 0; AssemblyIndex < AssembliesToDraw; AssemblyIndex++)
|
for (u32 AssemblyIndex = 0; AssemblyIndex < AssembliesToDraw; AssemblyIndex++)
|
||||||
{
|
{
|
||||||
rect Bounds = ui_ReserveElementBounds(&Layout);
|
|
||||||
v4 ListItemBGColor = ui_GetListItemBGColor(State->Interface_.Style, AssemblyIndex);
|
|
||||||
ui_FillRect(&State->Interface_, Bounds, ListItemBGColor);
|
|
||||||
|
|
||||||
assembly Assembly = State->Assemblies.Values[AssemblyIndex];
|
assembly Assembly = State->Assemblies.Values[AssemblyIndex];
|
||||||
PrintF(&TempString, "%S", Assembly.Name);
|
PrintF(&TempString, "%S", Assembly.Name);
|
||||||
|
|
||||||
ui_layout ItemLayout = ui_CreateLayout(State->Interface_, Bounds);
|
ui_layout ItemLayout = ui_CreateLayout(State->Interface_, LineBounds[AssemblyIndex]);
|
||||||
ui_StartRow(&ItemLayout, 2);
|
ui_StartRow(&ItemLayout, 2);
|
||||||
{
|
{
|
||||||
ui_LayoutDrawString(&State->Interface_, &ItemLayout, TempString, State->Interface_.Style.TextColor);
|
ui_LayoutDrawString(&State->Interface_, &ItemLayout, TempString, State->Interface_.Style.TextColor);
|
||||||
if (ui_LayoutButton(&State->Interface_, &ItemLayout, MakeStringLiteral("X"), ListItemBGColor, ListItemHover, ListItemSelected))
|
if (ui_LayoutListButton(&State->Interface_, &ItemLayout, MakeStringLiteral("X"), AssemblyIndex))
|
||||||
{
|
{
|
||||||
UnloadAssembly(AssemblyIndex, State, Context);
|
UnloadAssembly(AssemblyIndex, State, Context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ui_EndRow(&ItemLayout);
|
ui_EndRow(&ItemLayout);
|
||||||
|
|
||||||
LinesDrawn += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LinesDrawn < LineCount)
|
if (AssembliesToDraw < LineCount)
|
||||||
{
|
{
|
||||||
v4 ListItemBGColor = ui_GetListItemBGColor(State->Interface_.Style, LinesDrawn++);
|
|
||||||
PrintF(&TempString, "+ Add Assembly");
|
PrintF(&TempString, "+ Add Assembly");
|
||||||
if (ui_LayoutButton(&State->Interface_, &Layout, TempString, ListItemBGColor, ListItemHover, ListItemSelected))
|
if (ui_ListButton(&State->Interface_, TempString, LineBounds[AssembliesToDraw], AssembliesToDraw))
|
||||||
{
|
{
|
||||||
string FilePath = PushString(&State->Transient, 256);
|
string FilePath = PushString(&State->Transient, 256);
|
||||||
b32 Success = GetFilePath(Context, &FilePath, "Foldhaus Files\0*.fold\0\0");
|
b32 Success = GetFilePath(Context, &FilePath, "Foldhaus Files\0*.fold\0\0");
|
||||||
|
@ -74,13 +72,6 @@ HierarchyView_Render(panel Panel, rect PanelBounds, render_command_buffer* Rende
|
||||||
LoadAssembly(&State->Assemblies, &State->LedSystem, &State->Transient, Context, FilePath, State->GlobalLog);
|
LoadAssembly(&State->Assemblies, &State->LedSystem, &State->Transient, Context, FilePath, State->GlobalLog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; LinesDrawn < LineCount; LinesDrawn++)
|
|
||||||
{
|
|
||||||
rect Bounds = ui_ReserveElementBounds(&Layout);
|
|
||||||
ListItemBGColor = ui_GetListItemBGColor(State->Interface_.Style, LinesDrawn);
|
|
||||||
ui_FillRect(&State->Interface_, Bounds, ListItemBGColor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -436,7 +436,7 @@ NodeGraph_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuf
|
||||||
|
|
||||||
r32 NodeWidth = 150;
|
r32 NodeWidth = 150;
|
||||||
r32 LayerDistance = 100;
|
r32 LayerDistance = 100;
|
||||||
r32 LineHeight = (State->Interface.Font->PixelHeight + (2 * State->Interface.Margin.y));
|
r32 LineHeight = ui_GetTextLineHeight(State->Interface_);
|
||||||
|
|
||||||
if (GraphState->LayoutIsDirty)
|
if (GraphState->LayoutIsDirty)
|
||||||
{
|
{
|
||||||
|
@ -477,7 +477,7 @@ NodeGraph_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuf
|
||||||
{
|
{
|
||||||
visual_node VisualNode = GraphState->Layout.VisualNodes[i];
|
visual_node VisualNode = GraphState->Layout.VisualNodes[i];
|
||||||
gs_list_handle NodeHandle = State->NodeWorkspace.SortedNodeHandles[i];
|
gs_list_handle NodeHandle = State->NodeWorkspace.SortedNodeHandles[i];
|
||||||
DrawNode(VisualNode.Position + GraphState->ViewOffset, VisualNode.Spec, NodeHandle, NodeWidth, LineHeight, State->Interface, RenderBuffer, Mouse, &State->Transient);
|
DrawNode(VisualNode.Position + GraphState->ViewOffset, VisualNode.Spec, NodeHandle, NodeWidth, LineHeight, State->Interface_.Style, RenderBuffer, Mouse, &State->Transient);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (u32 p = 0; p < GraphState->Layout.VisualPortsCount; p++)
|
for (u32 p = 0; p < GraphState->Layout.VisualPortsCount; p++)
|
||||||
|
@ -514,17 +514,17 @@ NodeGraph_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuf
|
||||||
List.ListBounds = NodeSelectionWindowBounds;
|
List.ListBounds = NodeSelectionWindowBounds;
|
||||||
List.ListElementDimensions = v2{
|
List.ListElementDimensions = v2{
|
||||||
gs_Width(NodeSelectionWindowBounds),
|
gs_Width(NodeSelectionWindowBounds),
|
||||||
(r32)(State->Interface.Font->PixelHeight + 8),
|
ui_GetTextLineHeight(State->Interface_)
|
||||||
};
|
};
|
||||||
List.ElementLabelIndent = v2{10, 4};
|
List.ElementLabelIndent = v2{10, 4};
|
||||||
|
|
||||||
string TitleString = MakeStringLiteral("Available Nodes");
|
string TitleString = MakeStringLiteral("Available Nodes");
|
||||||
DrawListElement(TitleString, &List, Mouse, RenderBuffer, State->Interface);
|
DrawListElement(TitleString, &List, Mouse, RenderBuffer, State->Interface_.Style);
|
||||||
|
|
||||||
for (u32 i = 0; i < NodeType_Count; i++)
|
for (u32 i = 0; i < NodeType_Count; i++)
|
||||||
{
|
{
|
||||||
node_specification_ Spec = NodeSpecifications[i];
|
node_specification_ Spec = NodeSpecifications[i];
|
||||||
rect ElementBounds = DrawListElement(Spec.Identifier, &List, Mouse, RenderBuffer, State->Interface);
|
rect ElementBounds = DrawListElement(Spec.Identifier, &List, Mouse, RenderBuffer, State->Interface_.Style);
|
||||||
|
|
||||||
if (MouseButtonTransitionedDown(Mouse.LeftButtonState)
|
if (MouseButtonTransitionedDown(Mouse.LeftButtonState)
|
||||||
&& gs_PointIsInRect(Mouse.DownPos, ElementBounds))
|
&& gs_PointIsInRect(Mouse.DownPos, ElementBounds))
|
||||||
|
|
|
@ -82,7 +82,7 @@ GetNextCodepointOffset (bitmap_font* Font, u32* X, u32* Y)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
AddCodepointToFont (bitmap_font* Font, char Codepoint,
|
AddCodepointToFont (bitmap_font* Font, char Codepoint,
|
||||||
s32 XOffset, s32 YOffset, s32 Width, s32 Height,
|
s32 XOffset, s32 YOffset, s32 Width, s32 Height,
|
||||||
s32 BitmapX, s32 BitmapY)
|
s32 BitmapX, s32 BitmapY)
|
||||||
{
|
{
|
||||||
|
@ -100,7 +100,7 @@ AddCodepointToFont (bitmap_font* Font, char Codepoint,
|
||||||
Value->BitmapX = BitmapX;
|
Value->BitmapX = BitmapX;
|
||||||
Value->BitmapY = BitmapY;
|
Value->BitmapY = BitmapY;
|
||||||
Value->UVMin = v2{(r32)BitmapX / (r32)Font->BitmapWidth, (r32)BitmapY / (r32)Font->BitmapHeight};
|
Value->UVMin = v2{(r32)BitmapX / (r32)Font->BitmapWidth, (r32)BitmapY / (r32)Font->BitmapHeight};
|
||||||
Value->UVMax =
|
Value->UVMax =
|
||||||
Value->UVMin + v2{(r32)Width / (r32)Font->BitmapWidth, (r32)Height / (r32)Font->BitmapHeight};
|
Value->UVMin + v2{(r32)Width / (r32)Font->BitmapWidth, (r32)Height / (r32)Font->BitmapHeight};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue