From dec70c10e7f87c394f93915459408f2bdbfd5bf4 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Sat, 3 May 2025 21:16:16 +0200 Subject: [PATCH] Color of title bar when active and window size --- build_file.cpp | 1 + src/text_editor/generated.cpp | 2 ++ src/text_editor/generated_variables.cpp | 1 + src/text_editor/management.cpp | 3 ++- src/text_editor/text_editor.cpp | 5 ++++- src/text_editor/window_draw.cpp | 14 +++++++++++--- 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/build_file.cpp b/build_file.cpp index b60603c..cacd1ca 100644 --- a/build_file.cpp +++ b/build_file.cpp @@ -250,6 +250,7 @@ void GenerateConfig() { colors.add({"TitleBarText", "GruvboxDark2"}); colors.add({"TitleBarBackground", "GruvboxLight1"}); + colors.add({"TitleBarActiveBackground", "0xfefefefe"}); colors.add({"TitleBarSelection", "GruvboxLight3"}); Array style = {}; diff --git a/src/text_editor/generated.cpp b/src/text_editor/generated.cpp index 2805e41..1c1fb13 100644 --- a/src/text_editor/generated.cpp +++ b/src/text_editor/generated.cpp @@ -55,6 +55,7 @@ Color.ScrollbarScroller = GruvboxLight1 Color.ScrollbarScrollerSelected = GruvboxLight0Hard Color.TitleBarText = GruvboxDark2 Color.TitleBarBackground = GruvboxLight1 +Color.TitleBarActiveBackground = 0xfefefefe Color.TitleBarSelection = GruvboxLight3 Style = {} Style.ConsoleSizeSmall = 10 @@ -347,6 +348,7 @@ void ReloadStyle() { ColorScrollbarScrollerSelected = GetColor("ScrollbarScrollerSelected", ColorScrollbarScrollerSelected); ColorTitleBarText = GetColor("TitleBarText", ColorTitleBarText); ColorTitleBarBackground = GetColor("TitleBarBackground", ColorTitleBarBackground); + ColorTitleBarActiveBackground = GetColor("TitleBarActiveBackground", ColorTitleBarActiveBackground); ColorTitleBarSelection = GetColor("TitleBarSelection", ColorTitleBarSelection); StyleConsoleSizeSmall = GetStyleInt("ConsoleSizeSmall", StyleConsoleSizeSmall); StyleConsoleSizeBig = GetStyleInt("ConsoleSizeBig", StyleConsoleSizeBig); diff --git a/src/text_editor/generated_variables.cpp b/src/text_editor/generated_variables.cpp index cb5ef6b..474338f 100644 --- a/src/text_editor/generated_variables.cpp +++ b/src/text_editor/generated_variables.cpp @@ -53,6 +53,7 @@ Color ColorScrollbarScroller = GruvboxLight1; Color ColorScrollbarScrollerSelected = GruvboxLight0Hard; Color ColorTitleBarText = GruvboxDark2; Color ColorTitleBarBackground = GruvboxLight1; +Color ColorTitleBarActiveBackground = {0xfe, 0xfe, 0xfe, 0xfe}; Color ColorTitleBarSelection = GruvboxLight3; Int StyleConsoleSizeSmall = 10; Int StyleConsoleSizeBig = 30; diff --git a/src/text_editor/management.cpp b/src/text_editor/management.cpp index 10b9b45..9a7fbdb 100644 --- a/src/text_editor/management.cpp +++ b/src/text_editor/management.cpp @@ -352,7 +352,8 @@ Buffer *BufferOpenFile(String path) { if (!FileExists(path)) { buffer = CreateBuffer(sys_allocator, path); } else if (IsDir(path)) { - Assert(!"Invalid codepath"); + ReportWarningf("failed to open, it's a directory: %.*s", FmtString(path)); + return GetBuffer(NullBufferID); } else { String string = ReadFile(scratch, path); buffer = CreateBuffer(sys_allocator, path, string.len * 4 + 4096); diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index 943bb58..1d85b6e 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -295,8 +295,11 @@ int main(int argc, char **argv) SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); + SDL_DisplayID primary_display_id = SDL_GetPrimaryDisplay(); + const SDL_DisplayMode *display_mode = SDL_GetCurrentDisplayMode(primary_display_id); + Uint32 window_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN | SDL_WINDOW_HIGH_PIXEL_DENSITY; - SDLWindow = SDL_CreateWindow("Text editor", 1280, 720, window_flags); + SDLWindow = SDL_CreateWindow("Text editor", (int)(display_mode->w * 0.8), (int)(display_mode->h * 0.8), window_flags); if (SDLWindow == NULL) { ReportErrorf("Couldn't create window! %s", SDL_GetError()); return 1; diff --git a/src/text_editor/window_draw.cpp b/src/text_editor/window_draw.cpp index bd7a727..32fcee9 100644 --- a/src/text_editor/window_draw.cpp +++ b/src/text_editor/window_draw.cpp @@ -123,7 +123,11 @@ void DrawWindow(Window *window, Event &event) { Color color_text_line_numbers = ColorTextLineNumbers; Color color_text = ColorText; if (window->is_title_bar) { - color_background = ColorTitleBarBackground; + if (is_active) { + color_background = ColorTitleBarActiveBackground; + } else { + color_background = ColorTitleBarBackground; + } color_selection = ColorTitleBarSelection; color_text = ColorTitleBarText; color_line_highlight = ColorTitleBarBackground; @@ -170,7 +174,7 @@ void DrawWindow(Window *window, Event &event) { } } } - } else { + } else if (!window->is_title_bar) { // // Draw highlight Int front = GetFront(it); @@ -267,6 +271,10 @@ void DrawWindow(Window *window, Event &event) { if (!is_active) { SetScissor(screen_rect); - DrawRect(window->total_rect, ColorInactiveWindow); + if (window->is_title_bar) { + + } else { + DrawRect(window->total_rect, ColorInactiveWindow); + } } }