Fixing small bugs and add console window
This commit is contained in:
@@ -63,7 +63,7 @@ void EndFrameRender(Color color) {
|
|||||||
glViewport(0, 0, (GLsizei)WindowSize.x, (GLsizei)WindowSize.y);
|
glViewport(0, 0, (GLsizei)WindowSize.x, (GLsizei)WindowSize.y);
|
||||||
glScissor(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);
|
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
|
// Default draw using the font texture
|
||||||
glBindProgramPipeline(Shader2D.pipeline);
|
glBindProgramPipeline(Shader2D.pipeline);
|
||||||
@@ -299,6 +299,18 @@ void DrawRect(Rect2I rect, Color color) {
|
|||||||
PushQuad2D(RenderArena, &Vertices, ToRect2(rect), MainFont.white_texture_bounding_box, 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 = '_') {
|
Int GetCharSpacing(Font *font, int codepoint = '_') {
|
||||||
Glyph *g = GetGlyph(font, codepoint);
|
Glyph *g = GetGlyph(font, codepoint);
|
||||||
if (g->xadvance) return (Int)g->xadvance;
|
if (g->xadvance) return (Int)g->xadvance;
|
||||||
|
|||||||
@@ -323,6 +323,11 @@ bool GlobalCommand(Event event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Ctrl(SDLK_GRAVE)) {
|
||||||
|
Window *window = GetWindow(ConsoleWindowID);
|
||||||
|
ToggleVisibility(window);
|
||||||
|
}
|
||||||
|
|
||||||
if (CtrlShift(SDLK_BACKSLASH)) {
|
if (CtrlShift(SDLK_BACKSLASH)) {
|
||||||
AddRowWindow();
|
AddRowWindow();
|
||||||
} else if (Ctrl(SDLK_BACKSLASH)) {
|
} else if (Ctrl(SDLK_BACKSLASH)) {
|
||||||
@@ -331,7 +336,7 @@ bool GlobalCommand(Event event) {
|
|||||||
|
|
||||||
if (Ctrl(SDLK_0)) {
|
if (Ctrl(SDLK_0)) {
|
||||||
Window *window = GetWindow(DebugWindowID);
|
Window *window = GetWindow(DebugWindowID);
|
||||||
window->visible = !window->visible;
|
ToggleVisibility(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Press(SDLK_F5)) {
|
if (Press(SDLK_F5)) {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ WindowID InfoBarWindowID;
|
|||||||
WindowID SearchWindowID;
|
WindowID SearchWindowID;
|
||||||
WindowID PopupWindowID;
|
WindowID PopupWindowID;
|
||||||
WindowID DebugWindowID;
|
WindowID DebugWindowID;
|
||||||
|
WindowID ConsoleWindowID;
|
||||||
|
|
||||||
Array<WindowID> WindowSwitchHistory; // @todo: probably better as a circular buffer
|
Array<WindowID> WindowSwitchHistory; // @todo: probably better as a circular buffer
|
||||||
WindowID ActiveWindow;
|
WindowID ActiveWindow;
|
||||||
|
|||||||
@@ -172,8 +172,8 @@ void Update(const Event &event) {
|
|||||||
Window *window = &Windows[it];
|
Window *window = &Windows[it];
|
||||||
{
|
{
|
||||||
if (window->invisible_when_inactive) {
|
if (window->invisible_when_inactive) {
|
||||||
if (IsActive(window)) window->visible = true;
|
if (IsActive(window)) SetVisibility(window, true);
|
||||||
else window->visible = false;
|
else SetVisibility(window, false);
|
||||||
}
|
}
|
||||||
if (!window->visible) continue;
|
if (!window->visible) continue;
|
||||||
}
|
}
|
||||||
@@ -260,11 +260,6 @@ int main()
|
|||||||
SDL_GL_MakeCurrent(SDLWindow, gl_context);
|
SDL_GL_MakeCurrent(SDLWindow, gl_context);
|
||||||
SDL_GL_SetSwapInterval(0); // Enable vsync
|
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);
|
SDL_ShowWindow(SDLWindow);
|
||||||
|
|
||||||
// Set icon
|
// Set icon
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ Window *CreateInfobar(Window *parent_window) {
|
|||||||
parent_window->title_bar_window = window->id;
|
parent_window->title_bar_window = window->id;
|
||||||
window->title_bar_window = parent_window->id;
|
window->title_bar_window = parent_window->id;
|
||||||
|
|
||||||
|
void ReplaceTitleBarData(Window * window);
|
||||||
|
ReplaceTitleBarData(window);
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,6 +87,19 @@ void AddRowWindow() {
|
|||||||
Insert(&Windows, window_copy, active_window_index + 1);
|
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) {
|
void InitWindows(View *null_view) {
|
||||||
Allocator sys_allocator = GetSystemAllocator();
|
Allocator sys_allocator = GetSystemAllocator();
|
||||||
|
|
||||||
@@ -103,16 +119,19 @@ void InitWindows(View *null_view) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
Window *window = CreateWindow();
|
Window *window = CreateWindow();
|
||||||
window->is_column = true;
|
window->absolute_position = true;
|
||||||
|
window->dont_save_in_active_window_history = true;
|
||||||
|
window->deactivate_on_escape = true;
|
||||||
|
|
||||||
Buffer *buffer = CreateBuffer(sys_allocator, "*console*");
|
Buffer *buffer = CreateBuffer(sys_allocator, "*console*");
|
||||||
|
buffer->no_history = true;
|
||||||
View *view = CreateView(buffer->id);
|
View *view = CreateView(buffer->id);
|
||||||
SetActiveView(window, view->id);
|
SetActiveView(window, view->id);
|
||||||
CreateInfobar(window);
|
CreateInfobar(window);
|
||||||
}
|
SetVisibility(window, false);
|
||||||
|
|
||||||
// AddRowWindow();
|
ConsoleWindowID = window->id;
|
||||||
// AddRowWindow();
|
}
|
||||||
// AddRowWindow();
|
|
||||||
|
|
||||||
{
|
{
|
||||||
Window *window = CreateWindow();
|
Window *window = CreateWindow();
|
||||||
@@ -190,6 +209,23 @@ void LayoutWindows() {
|
|||||||
Rect2I screen_rect = GetScreenRectI();
|
Rect2I screen_rect = GetScreenRectI();
|
||||||
float line_numbers_size = (float)FontCharSpacing * 10;
|
float line_numbers_size = (float)FontCharSpacing * 10;
|
||||||
float sizex = (float)GetSize(screen_rect).x;
|
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);
|
Window *search_window = GetWindow(SearchWindowID);
|
||||||
if (search_window->visible) {
|
if (search_window->visible) {
|
||||||
Rect2I rect = CutBottom(&screen_rect, FontLineSpacing);
|
Rect2I rect = CutBottom(&screen_rect, FontLineSpacing);
|
||||||
|
|||||||
@@ -160,8 +160,8 @@ void DrawWindow(Window *window) {
|
|||||||
w -= view->scroll;
|
w -= view->scroll;
|
||||||
w += window->document_rect.min;
|
w += window->document_rect.min;
|
||||||
Rect2 rect = {
|
Rect2 rect = {
|
||||||
{ 0.f, (float)w.y},
|
{(float)window->total_rect.min.x, (float)w.y},
|
||||||
{WindowSize.x, (float)w.y + (float)FontLineSpacing}
|
{(float)window->total_rect.max.x, (float)w.y + (float)FontLineSpacing}
|
||||||
};
|
};
|
||||||
DrawRect(rect, color_line_highlight);
|
DrawRect(rect, color_line_highlight);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user