diff --git a/code/vn_font.h b/code/vn_font.h index 98efcb0..9f4a5d5 100644 --- a/code/vn_font.h +++ b/code/vn_font.h @@ -90,7 +90,7 @@ struct glyph r32 Advance; }; -#define DEFAULT_GLYPH_ATLAS_DIM 1024*4 +#define DEFAULT_GLYPH_ATLAS_DIM 1024*2 #define MAX_GLYPH_SIZE 128 #define STB_TRUETYPE_IMPLEMENTATION diff --git a/code/vn_platform.h b/code/vn_platform.h index 689a8e6..1493f5a 100644 --- a/code/vn_platform.h +++ b/code/vn_platform.h @@ -93,6 +93,7 @@ enum platform_key Key_PageUp, Key_PageDown, Key_Home, Key_End, Key_Plus, Key_Minus, + Key_Period, Key_Comma, Key_Backspace, Key_Delete, diff --git a/code/vn_workspace.cpp b/code/vn_workspace.cpp index 11399c6..d865fee 100644 --- a/code/vn_workspace.cpp +++ b/code/vn_workspace.cpp @@ -12,8 +12,13 @@ static workspace_keybind Workspace_Keybinds[] = {Key_P, PlatformModifier_Ctrl, W_Command_SplitPanelHorizontal}, {Key_L, PlatformModifier_Ctrl, W_Command_SplitPanelVertical}, + {Key_W, PlatformModifier_Ctrl, W_Command_CloseView, 0}, + {Key_P, PlatformModifier_Ctrl|PlatformModifier_Shift, W_Command_ClosePanel}, + + {Key_Comma, PlatformModifier_Ctrl, W_Command_CyclePanel}, + {Key_Comma, PlatformModifier_Ctrl|PlatformModifier_Shift, W_Command_CyclePanelReverse}, + {Key_O, PlatformModifier_Ctrl, W_Command_OpenView, W_ViewKind_FileLister}, - {Key_P, PlatformModifier_Ctrl|PlatformModifier_Shift, W_Command_OpenView, W_ViewKind_Settings}, #if VN_INTERNAL {Key_U, PlatformModifier_Ctrl|PlatformModifier_Shift, W_Command_ToggleRenderUIDebugRects}, diff --git a/code/vn_workspace_commands.cpp b/code/vn_workspace_commands.cpp index 9a76a58..1341f51 100644 --- a/code/vn_workspace_commands.cpp +++ b/code/vn_workspace_commands.cpp @@ -21,72 +21,73 @@ WORKSPACE_COMMAND(W_Command_ClosePanel) } workspace_panel *Parent = Panel->Parent; - - Assert(Parent); - Assert(Panel != Workspace->RootPanel); - - DLLRemove(Parent->First, Parent->Last, Panel); - - b32 OneChildRemains = (Parent->First == Parent->Last); - if(OneChildRemains) - { - workspace_panel *Child = Parent->First; - Assert(DLLIsEmpty(Parent->FirstView)); - - Parent->FirstView = Child->FirstView; - Parent->LastView = Child->LastView; - Parent->First = Child->First; - Parent->Last = Child->Last; - Parent->SplitAxis = Child->SplitAxis; - Parent->CurrentView = Child->CurrentView; - - // sixten: Update the parents of the children. - for(workspace_view *View = Parent->FirstView; - View != 0; - View = View->Next) - { - View->Parent = Parent; - } - for(workspace_panel *ParentChild = Parent->First; - ParentChild != 0; - ParentChild = ParentChild->Next) - { - ParentChild->Parent = Parent; - } - - DLLRemove(Parent->First, Parent->Last, Child); - W_DeletePanel(Child); - } - else - { - s32 ChildCount = 0; - for(workspace_panel *Child = Parent->First; - Child != 0; - Child = Child->Next) - { - ++ChildCount; - } - - r32 ToAppend = Panel->PercentOfParent / ChildCount; - for(workspace_panel *Child = Parent->First; - Child != 0; - Child = Child->Next) - { - Child->PercentOfParent += ToAppend; - } - } - - // sixten: Delete all child views. - workspace_view *NextChild = 0; - for(workspace_view *Child = Panel->FirstView; - Child != 0; - Child = NextChild) - { - NextChild = Child->Next; - W_DestroyView(Child); - } - - W_DeletePanel(Panel); + if(Parent) + { + Assert(Panel != Workspace->RootPanel); + + DLLRemove(Parent->First, Parent->Last, Panel); + + b32 OneChildRemains = (Parent->First == Parent->Last); + if(OneChildRemains) + { + workspace_panel *Child = Parent->First; + Assert(DLLIsEmpty(Parent->FirstView)); + + Parent->FirstView = Child->FirstView; + Parent->LastView = Child->LastView; + Parent->First = Child->First; + Parent->Last = Child->Last; + Parent->SplitAxis = Child->SplitAxis; + Parent->CurrentView = Child->CurrentView; + + // sixten: Update the parents of the children. + for(workspace_view *View = Parent->FirstView; + View != 0; + View = View->Next) + { + View->Parent = Parent; + } + for(workspace_panel *ParentChild = Parent->First; + ParentChild != 0; + ParentChild = ParentChild->Next) + { + ParentChild->Parent = Parent; + } + + DLLRemove(Parent->First, Parent->Last, Child); + W_DeletePanel(Child); + } + else + { + s32 ChildCount = 0; + for(workspace_panel *Child = Parent->First; + Child != 0; + Child = Child->Next) + { + ++ChildCount; + } + + r32 ToAppend = Panel->PercentOfParent / ChildCount; + for(workspace_panel *Child = Parent->First; + Child != 0; + Child = Child->Next) + { + Child->PercentOfParent += ToAppend; + } + } + + // sixten: Delete all child views. + workspace_view *NextChild = 0; + for(workspace_view *Child = Panel->FirstView; + Child != 0; + Child = NextChild) + { + NextChild = Child->Next; + W_DestroyView(Child); + } + + W_DeletePanel(Panel); + } } WORKSPACE_COMMAND(W_Command_OpenView) @@ -97,18 +98,30 @@ WORKSPACE_COMMAND(W_Command_OpenView) WORKSPACE_COMMAND(W_Command_CloseView) { - workspace_view *View = (workspace_view *)U64ToPointer(Argument); - workspace_panel *Panel = View->Parent; - - DLLRemove(Panel->FirstView, Panel->LastView, View); - if(Panel->CurrentView == View) - { - Panel->CurrentView = Panel->FirstView; - } - - W_DestroyView(View); + workspace_view *View = 0; + if(Argument) + { + View = (workspace_view *)U64ToPointer(Argument); + } + else + { + workspace *Workspace = W_GetState(); + View = Workspace->CurrentPanel->CurrentView; + } + + if(View) + { + workspace_panel *Panel = View->Parent; + + DLLRemove(Panel->FirstView, Panel->LastView, View); + if(Panel->CurrentView == View) + { + Panel->CurrentView = Panel->FirstView; + } + + W_DestroyView(View); + } } - WORKSPACE_COMMAND(W_Command_OpenFile) { temp Scratch = GetScratch(); @@ -190,6 +203,68 @@ WORKSPACE_COMMAND(W_Command_OpenFile) ReleaseScratch(Scratch); } +static workspace_panel *W_FindFirstLeaf(workspace_panel *Panel) +{ + for(;Panel->First;) Panel = Panel->First; + return(Panel); +} + +static workspace_panel *W_FindNextPanelParent(workspace_panel *Panel) +{ + workspace_panel *Result = 0; + if(Panel->Next) + { + Result = Panel->Next; + } + else if(Panel->Parent) + { + Result = W_FindNextPanelParent(Panel->Parent); + } + else + { + Result = Panel; + } + return(Result); +} + +WORKSPACE_COMMAND(W_Command_CyclePanel) +{ + workspace *Workspace = W_GetState(); + workspace_panel *Panel = W_FindFirstLeaf(W_FindNextPanelParent(Workspace->CurrentPanel)); + Workspace->CurrentPanel = Panel; +} + +static workspace_panel *W_FindLastLeaf(workspace_panel *Panel) +{ + for(;Panel->Last;) Panel = Panel->Last; + return(Panel); +} + +static workspace_panel *W_FindPrevPanelParent(workspace_panel *Panel) +{ + workspace_panel *Result = 0; + if(Panel->Prev) + { + Result = Panel->Prev; + } + else if(Panel->Parent) + { + Result = W_FindPrevPanelParent(Panel->Parent); + } + else + { + Result = Panel; + } + return(Result); +} + +WORKSPACE_COMMAND(W_Command_CyclePanelReverse) +{ + workspace *Workspace = W_GetState(); + workspace_panel *Panel = W_FindLastLeaf(W_FindPrevPanelParent(Workspace->CurrentPanel)); + Workspace->CurrentPanel = Panel; +} + #if VN_INTERNAL WORKSPACE_COMMAND(W_Command_ToggleRenderUIDebugRects) { diff --git a/code/vn_workspace_text_editor.cpp b/code/vn_workspace_text_editor.cpp index 34d3dcd..16f4001 100644 --- a/code/vn_workspace_text_editor.cpp +++ b/code/vn_workspace_text_editor.cpp @@ -235,6 +235,7 @@ static void W_BuildTextEditorErrorList(workspace_view_text_editor *Editor) if(Signal.Hovering) { UI_TooltipLabel(StrLit("Goto in source"), UI_MouseP()); + // sixten(TODO): ACTUALLY GO TO THE SOURCE LOCATION } } UI_Spacer(UI_Em(0.5, 1)); @@ -316,6 +317,17 @@ UI_CUSTOM_DRAW_CALLBACK(W_TextEditorDrawCallback) } } +#if 0 + //- sixten: render gradient on current line + { + v4_r32 ColorBegin = SetAlpha(Theme_HighlightBorderColor, 0.5); + v4_r32 ColorEnd = SetAlpha(Theme_HighlightBorderColor, 0.0); + range2_r32 LineDest = Range2R32(Box->Rect.Min+V2R32(0, (CursorTextP.Line-1)*LineHeight), Box->Rect.Min+V2R32(400, CursorTextP.Line*LineHeight)); + PushQuad(Group, LineDest, ColorBegin, ColorEnd, ColorBegin, ColorEnd, 0, 0, 0); + PushQuad(Group, LineDest, Theme_BackgroundColor, Theme_BackgroundColor, Theme_BackgroundColor, Theme_BackgroundColor, 4.0f, 14, 0); + } +#endif + //- sixten: render tokens v2_r32 TokenP = StartTokenP; for(token *Token = VisibleTokensBegin; Token < VisibleTokensEnd; Token += 1) @@ -324,7 +336,7 @@ UI_CUSTOM_DRAW_CALLBACK(W_TextEditorDrawCallback) //- sixten: get color & font from token font_id Font = Font_Monospace; - v4 Color = Color_Magenta; + v4 Color = Color_Cyan; if(Token->Kind == TokenKind_Comment) { Color = Color_Grey; Font = Font_MonospaceOblique; } else if(Token->Kind > TokenKind_SymbolsBegin && Token->Kind < TokenKind_SymbolsEnd) { Color = Color_Grey; } else if(Token->Kind == TokenKind_StringLiteral) { Color = ColorFromHex(0xffa900ff); } @@ -552,7 +564,6 @@ static void W_BuildTextEditor(workspace_view *View) s64 ColumnIndex = UTF8IndexFromOffset(Line, ColumnOffset); CursorHasBeenModified = true; - Editor->DropdownActive = false; text_point Point = {LineIndex + 1, ColumnIndex + 1}; Editor->EditState.Cursor = OffsetFromTextPoint(Editor->Text.String, Editor->Lines, Point); @@ -776,6 +787,15 @@ static void W_BuildTextEditor(workspace_view *View) Editor->Offset.y = CursorP.y - VisibleRegionDim.y + LineHeight; } + if(CursorP.x < Editor->Offset.x) + { + Editor->Offset.x = CursorP.x; + } + if(CursorP.x > Editor->Offset.x + VisibleRegionDim.x - LineHeight) + { + Editor->Offset.x = CursorP.x - VisibleRegionDim.x + LineHeight; + } + if(Editor->LastTextPoint.Line == Point.Line) { Editor->LastTextPoint = Point; diff --git a/code/vn_workspace_text_editor.h b/code/vn_workspace_text_editor.h index e9cfe3f..b1638fc 100644 --- a/code/vn_workspace_text_editor.h +++ b/code/vn_workspace_text_editor.h @@ -72,12 +72,7 @@ struct workspace_view_text_editor history_node *SavePoint; // sixten: ui building & rendering - ui_box *ContainerBox; - v2 TextDim; v2 Offset; - b32 DropdownActive; - v2 DropdownP; - r32 DropdownTransition; }; //////////////////////////////// diff --git a/code/vn_workspace_view.cpp b/code/vn_workspace_view.cpp index 351daab..067de00 100644 --- a/code/vn_workspace_view.cpp +++ b/code/vn_workspace_view.cpp @@ -40,7 +40,7 @@ inline workspace_view *W_CreateNewView(workspace_view_kind Kind, workspace_panel Editor->Tokens = TextData.Tokens; Editor->Lines = TextData.Lines; - Editor->FontSize = 13.0f; + Editor->FontSize = 15.0f; } break; case W_ViewKind_NavEditor: diff --git a/code/win32_main.cpp b/code/win32_main.cpp index 8a544b8..3ed5099 100644 --- a/code/win32_main.cpp +++ b/code/win32_main.cpp @@ -575,6 +575,8 @@ static LRESULT Win32_WindowCallback(HWND Window, UINT Message, WPARAM WParam, LP else if(VKCode == VK_END) { Key = Key_End; } else if(VKCode == VK_OEM_PLUS) { Key = Key_Plus; } else if(VKCode == VK_OEM_MINUS) { Key = Key_Minus; } + else if(VKCode == VK_OEM_PERIOD) { Key = Key_Period; } + else if(VKCode == VK_OEM_COMMA) { Key = Key_Comma; } else if(VKCode == VK_BACK) { Key = Key_Backspace; } else if(VKCode == VK_DELETE) { Key = Key_Delete; } else if(VKCode == VK_ESCAPE) { Key = Key_Escape; } @@ -794,7 +796,7 @@ int WinMain(HINSTANCE Instance, HINSTANCE PreviousInstance, LPSTR CommandLine, i // sixten: Setup OpenGL HDC DeviceContext = GetDC(Window); Win32_CreateOpenGLContext(DeviceContext); - opengl_context OpenGLContext = OpenGL_SetupContext(&RenderCommands, 16*1024); + opengl_context OpenGLContext = OpenGL_SetupContext(&RenderCommands, 64*1024); vn_memory Memory = {}; Memory.PlatformAPI = Platform; diff --git a/data/scene.vns b/data/scene.vns index 2873883..5d23fc2 100644 --- a/data/scene.vns +++ b/data/scene.vns @@ -9,7 +9,7 @@ proc main @arthur(normal) "Welcome to the Scene Test!"; @arthur(happy) "Feel free to move around."; - branch + branch { "No! Sooth me with your voice one more time." {