Fixing small bugs and add console window

This commit is contained in:
Krzosa Karol
2024-08-02 12:03:51 +02:00
parent cff301499f
commit 55223b763a
6 changed files with 74 additions and 25 deletions

View File

@@ -63,7 +63,7 @@ void EndFrameRender(Color color) {
glViewport(0, 0, (GLsizei)WindowSize.x, (GLsizei)WindowSize.y);
glScissor(0, 0, (GLsizei)WindowSize.x, (GLsizei)WindowSize.y);
glClearColor(color.r, color.g, color.b, color.a);
glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// Default draw using the font texture
glBindProgramPipeline(Shader2D.pipeline);
@@ -299,6 +299,18 @@ void DrawRect(Rect2I rect, Color color) {
PushQuad2D(RenderArena, &Vertices, ToRect2(rect), MainFont.white_texture_bounding_box, color);
}
void DrawRectOutline(Rect2I rect, Color color, Int thickness = 2) {
Rect2I a = CutLeft(&rect, thickness);
Rect2I b = CutRight(&rect, thickness);
Rect2I c = CutTop(&rect, thickness);
Rect2I d = CutBottom(&rect, thickness);
PushQuad2D(RenderArena, &Vertices, ToRect2(a), MainFont.white_texture_bounding_box, color);
PushQuad2D(RenderArena, &Vertices, ToRect2(b), MainFont.white_texture_bounding_box, color);
PushQuad2D(RenderArena, &Vertices, ToRect2(c), MainFont.white_texture_bounding_box, color);
PushQuad2D(RenderArena, &Vertices, ToRect2(d), MainFont.white_texture_bounding_box, color);
}
Int GetCharSpacing(Font *font, int codepoint = '_') {
Glyph *g = GetGlyph(font, codepoint);
if (g->xadvance) return (Int)g->xadvance;

View File

@@ -323,6 +323,11 @@ bool GlobalCommand(Event event) {
}
}
if (Ctrl(SDLK_GRAVE)) {
Window *window = GetWindow(ConsoleWindowID);
ToggleVisibility(window);
}
if (CtrlShift(SDLK_BACKSLASH)) {
AddRowWindow();
} else if (Ctrl(SDLK_BACKSLASH)) {
@@ -330,8 +335,8 @@ bool GlobalCommand(Event event) {
}
if (Ctrl(SDLK_0)) {
Window *window = GetWindow(DebugWindowID);
window->visible = !window->visible;
Window *window = GetWindow(DebugWindowID);
ToggleVisibility(window);
}
if (Press(SDLK_F5)) {

View File

@@ -14,6 +14,7 @@ WindowID InfoBarWindowID;
WindowID SearchWindowID;
WindowID PopupWindowID;
WindowID DebugWindowID;
WindowID ConsoleWindowID;
Array<WindowID> WindowSwitchHistory; // @todo: probably better as a circular buffer
WindowID ActiveWindow;

View File

@@ -172,8 +172,8 @@ void Update(const Event &event) {
Window *window = &Windows[it];
{
if (window->invisible_when_inactive) {
if (IsActive(window)) window->visible = true;
else window->visible = false;
if (IsActive(window)) SetVisibility(window, true);
else SetVisibility(window, false);
}
if (!window->visible) continue;
}
@@ -260,11 +260,6 @@ int main()
SDL_GL_MakeCurrent(SDLWindow, gl_context);
SDL_GL_SetSwapInterval(0); // Enable vsync
SDL_DisplayID display = SDL_GetDisplayForWindow(SDLWindow);
const SDL_DisplayMode *dm = SDL_GetCurrentDisplayMode(display);
SDL_SetWindowSize(SDLWindow, (int)((double)dm->w * 0.8), (int)((double)dm->h * 0.8));
SDL_SetWindowPosition(SDLWindow, (int)((double)dm->w * 0.1), (int)((double)dm->h * 0.1));
SDL_ShowWindow(SDLWindow);
// Set icon

View File

@@ -49,6 +49,9 @@ Window *CreateInfobar(Window *parent_window) {
parent_window->title_bar_window = window->id;
window->title_bar_window = parent_window->id;
void ReplaceTitleBarData(Window * window);
ReplaceTitleBarData(window);
return window;
}
@@ -84,6 +87,19 @@ void AddRowWindow() {
Insert(&Windows, window_copy, active_window_index + 1);
}
void SetVisibility(Window *window, bool v) {
window->visible = v;
if (window->title_bar_window.id != 0) {
Window *title_bar = GetWindow(window->title_bar_window);
title_bar->visible = v;
}
}
void ToggleVisibility(Window *window) {
SetVisibility(window, !window->visible);
}
void InitWindows(View *null_view) {
Allocator sys_allocator = GetSystemAllocator();
@@ -102,17 +118,20 @@ void InitWindows(View *null_view) {
}
{
Window *window = CreateWindow();
window->is_column = true;
Buffer *buffer = CreateBuffer(sys_allocator, "*console*");
View *view = CreateView(buffer->id);
Window *window = CreateWindow();
window->absolute_position = true;
window->dont_save_in_active_window_history = true;
window->deactivate_on_escape = true;
Buffer *buffer = CreateBuffer(sys_allocator, "*console*");
buffer->no_history = true;
View *view = CreateView(buffer->id);
SetActiveView(window, view->id);
CreateInfobar(window);
}
SetVisibility(window, false);
// AddRowWindow();
// AddRowWindow();
// AddRowWindow();
ConsoleWindowID = window->id;
}
{
Window *window = CreateWindow();
@@ -186,11 +205,28 @@ void InitWindows(View *null_view) {
}
void LayoutWindows() {
float ScrollBarSize = (10.f * DPIScale);
Rect2I screen_rect = GetScreenRectI();
float line_numbers_size = (float)FontCharSpacing * 10;
float sizex = (float)GetSize(screen_rect).x;
Window *search_window = GetWindow(SearchWindowID);
float ScrollBarSize = (10.f * DPIScale);
Rect2I screen_rect = GetScreenRectI();
float line_numbers_size = (float)FontCharSpacing * 10;
float sizex = (float)GetSize(screen_rect).x;
{
Window *window = GetWindow(ConsoleWindowID);
if (window->visible) {
Vec2I size = GetSize(screen_rect);
Rect2I c = CutBottom(&screen_rect, (Int)((float)size.y * 0.5f));
Window *title_bar_window = GetWindow(window->title_bar_window);
title_bar_window->total_rect = CutBottom(&window->total_rect, GetTitleBarSize(title_bar_window));
title_bar_window->document_rect = title_bar_window->total_rect;
window->document_rect = window->total_rect;
if (window->draw_scrollbar) window->scrollbar_rect = CutRight(&window->document_rect, (Int)ScrollBarSize);
if (window->draw_line_numbers) window->line_numbers_rect = CutLeft(&window->document_rect, (Int)line_numbers_size);
}
}
Window *search_window = GetWindow(SearchWindowID);
if (search_window->visible) {
Rect2I rect = CutBottom(&screen_rect, FontLineSpacing);
search_window->total_rect = rect;

View File

@@ -160,8 +160,8 @@ void DrawWindow(Window *window) {
w -= view->scroll;
w += window->document_rect.min;
Rect2 rect = {
{ 0.f, (float)w.y},
{WindowSize.x, (float)w.y + (float)FontLineSpacing}
{(float)window->total_rect.min.x, (float)w.y},
{(float)window->total_rect.max.x, (float)w.y + (float)FontLineSpacing}
};
DrawRect(rect, color_line_highlight);
}