332 lines
12 KiB
C++
332 lines
12 KiB
C++
struct VisualColumn {
|
|
Window *window;
|
|
Array<Window *> rows;
|
|
};
|
|
|
|
Array<VisualColumn> GetVisualColumns(Allocator allocator) {
|
|
Array<VisualColumn> columns = {allocator};
|
|
ForItem(window, Windows) {
|
|
if (!window.visible || window.absolute_position || window.is_title_bar) continue;
|
|
|
|
if (window.is_column) {
|
|
Add(&columns, {&window, {allocator}});
|
|
VisualColumn *col = GetLast(columns);
|
|
Add(&col->rows, &window);
|
|
} else if (columns.len) {
|
|
VisualColumn *col = GetLast(columns);
|
|
Add(&col->rows, &window);
|
|
}
|
|
}
|
|
return columns;
|
|
}
|
|
|
|
Window *GetLayoutWindow(int n) {
|
|
int i = 0;
|
|
ForItem(window, Windows) {
|
|
if (!window.visible || window.absolute_position || window.is_title_bar) continue;
|
|
if (n == i) return &window;
|
|
i += 1;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
Array<Int> GetWindowZOrder(Allocator allocator) {
|
|
Array<Int> order = {allocator};
|
|
For(Windows) if (it.z == 2) Add(&order, GetIndex(Windows, it));
|
|
For(Windows) if (it.z == 1) Add(&order, GetIndex(Windows, it));
|
|
For(Windows) if (it.z == 0) Add(&order, GetIndex(Windows, it));
|
|
return order;
|
|
}
|
|
|
|
Window *CreateInfobar(Window *parent_window) {
|
|
Window *window = CreateWindow();
|
|
window->draw_scrollbar = false;
|
|
window->dont_save_in_active_window_history = true;
|
|
window->deactivate_on_escape = true;
|
|
window->is_title_bar = true;
|
|
|
|
static int InfobarCount;
|
|
Allocator sys_allocator = GetSystemAllocator();
|
|
String name = Format(sys_allocator, "*infobar%d", ++InfobarCount);
|
|
|
|
Buffer *b = CreateBuffer(sys_allocator, name);
|
|
View *v = CreateView(b->id);
|
|
window->active_view = v->id;
|
|
SetActiveView(window, v->id);
|
|
|
|
parent_window->title_bar_window = window->id;
|
|
window->title_bar_window = parent_window->id;
|
|
|
|
void ReplaceTitleBarData(Window * window);
|
|
ReplaceTitleBarData(window);
|
|
|
|
return window;
|
|
}
|
|
|
|
Int GetTitleBarSize(Window *window) {
|
|
View *view = GetView(window->active_view);
|
|
Buffer *buffer = GetBuffer(view->active_buffer);
|
|
float result = (float)buffer->line_starts.len * FontLineSpacing;
|
|
return (Int)result;
|
|
}
|
|
|
|
void AddColumnWindow() {
|
|
Window *window = CreateWindow();
|
|
window->is_column = true;
|
|
View *view = OpenBufferView("*scratch*");
|
|
SetActiveView(window, view->id);
|
|
CreateInfobar(window);
|
|
}
|
|
|
|
void AddRowWindow() {
|
|
Window *window = CreateWindow();
|
|
WindowID window_id = window->id;
|
|
|
|
View *view = OpenBufferView("*scratch*");
|
|
SetActiveView(window, view->id);
|
|
CreateInfobar(window);
|
|
|
|
Window *active_window = GetActiveWindow();
|
|
int64_t active_window_index = GetIndex(Windows, *active_window);
|
|
|
|
window = GetWindow(window_id);
|
|
Window window_copy = *window;
|
|
Remove(&Windows, *window);
|
|
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;
|
|
}
|
|
}
|
|
|
|
bool ToggleVisibility(Window *window) {
|
|
bool visible = !window->visible;
|
|
SetVisibility(window, visible);
|
|
return visible;
|
|
}
|
|
|
|
void InitWindows(View *null_view) {
|
|
Allocator sys_allocator = GetSystemAllocator();
|
|
|
|
{
|
|
Window *window = CreateWindow();
|
|
window->is_column = true;
|
|
// window->draw_line_numbers = false;
|
|
Buffer *buffer = CreateBuffer(sys_allocator, "*load_text_a*");
|
|
View *view = CreateView(buffer->id);
|
|
// LoadTextA(buffer);
|
|
LoadUnicode(buffer);
|
|
// LoadBigTextAndBigLine(buffer, 10000000);
|
|
window->active_view = view->id;
|
|
SetActiveView(window, view->id);
|
|
CreateInfobar(window);
|
|
}
|
|
|
|
{
|
|
Window *window = CreateWindow();
|
|
window->absolute_position = true;
|
|
window->dont_save_in_active_window_history = 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);
|
|
|
|
ConsoleWindowID = window->id;
|
|
}
|
|
|
|
{
|
|
Window *window = CreateWindow();
|
|
window->draw_line_numbers = false;
|
|
Buffer *buffer = CreateBuffer(sys_allocator, "*debug*");
|
|
window->absolute_position = true;
|
|
window->draw_line_numbers = false;
|
|
window->draw_scrollbar = false;
|
|
window->dont_save_in_active_window_history = true;
|
|
window->visible = false;
|
|
buffer->no_history = true;
|
|
View *view = CreateView(buffer->id);
|
|
window->active_view = view->id;
|
|
window->z = 2;
|
|
SetActiveView(window, view->id);
|
|
DebugWindowID = window->id;
|
|
}
|
|
|
|
{
|
|
Window *w = CreateWindow();
|
|
w->draw_scrollbar = false;
|
|
w->draw_line_numbers = false;
|
|
w->visible = false;
|
|
w->fuzzy_search = true;
|
|
w->invisible_when_inactive = true;
|
|
w->absolute_position = true;
|
|
w->dont_save_in_active_window_history = true;
|
|
w->deactivate_on_escape = true;
|
|
Buffer *b = CreateBuffer(sys_allocator, "*commands*");
|
|
View *v = CreateView(b->id);
|
|
SetActiveView(w, v->id);
|
|
w->z = 1;
|
|
|
|
Window *titlebar = CreateInfobar(w);
|
|
titlebar->z = 1;
|
|
SetVisibility(w, false);
|
|
|
|
CommandWindowID = w->id;
|
|
}
|
|
|
|
{
|
|
Window *w = CreateWindow();
|
|
w->draw_scrollbar = false;
|
|
w->draw_line_numbers = false;
|
|
w->visible = false;
|
|
w->absolute_position = true;
|
|
w->dont_save_in_active_window_history = true;
|
|
w->invisible_when_inactive = true;
|
|
w->deactivate_on_escape = true;
|
|
Buffer *b = CreateBuffer(sys_allocator, "*search*");
|
|
View *v = CreateView(b->id);
|
|
SetActiveView(w, v->id);
|
|
CreateInfobar(w);
|
|
SetVisibility(w, false);
|
|
|
|
SearchWindowID = w->id;
|
|
}
|
|
|
|
{
|
|
Window *w = CreateWindow();
|
|
w->draw_scrollbar = false;
|
|
w->draw_line_numbers = false;
|
|
w->visible = false;
|
|
w->dont_save_in_active_window_history = true;
|
|
w->invisible_when_inactive = true;
|
|
w->absolute_position = true;
|
|
w->deactivate_on_escape = true;
|
|
w->z = 2;
|
|
Buffer *b = CreateBuffer(sys_allocator, "*popup*");
|
|
b->no_history = true;
|
|
View *v = CreateView(b->id);
|
|
SetActiveView(w, v->id);
|
|
|
|
PopupWindowID = w->id;
|
|
}
|
|
|
|
SetActiveWindow({0});
|
|
}
|
|
|
|
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 *window = GetWindow(ConsoleWindowID);
|
|
if (window->visible) {
|
|
Vec2I size = GetSize(screen_rect);
|
|
window->total_rect = 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 *window = GetWindow(SearchWindowID);
|
|
if (window->visible) {
|
|
Rect2I rect = CutBottom(&screen_rect, FontLineSpacing);
|
|
window->total_rect = rect;
|
|
Window *title_bar_window = GetWindow(window->title_bar_window);
|
|
title_bar_window->total_rect = CutLeft(&window->total_rect, (Int)(FontCharSpacing * 14));
|
|
title_bar_window->document_rect = title_bar_window->total_rect;
|
|
window->document_rect = window->total_rect;
|
|
}
|
|
}
|
|
|
|
Scratch scratch;
|
|
Array<VisualColumn> columns = GetVisualColumns(scratch);
|
|
|
|
float delta_column = 1.0f / (float)columns.len;
|
|
ForItem(col, columns) {
|
|
Rect2I rect = CutLeft(&screen_rect, (Int)(delta_column * sizex));
|
|
|
|
float sizey = (float)GetSize(rect).y;
|
|
float delta_row = 1.0f / (float)col.rows.len;
|
|
ForItem(row, col.rows) {
|
|
row->total_rect = CutTop(&rect, (Int)(delta_row * sizey));
|
|
}
|
|
}
|
|
|
|
For(Windows) {
|
|
Window *window = ⁢
|
|
if (!window->visible || window->absolute_position || window->is_title_bar) continue;
|
|
|
|
Window *title_bar_window = GetWindow(window->title_bar_window);
|
|
if (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 *window = GetWindow(DebugWindowID);
|
|
Rect2 screen_rect = GetScreenRectF();
|
|
Vec2 size = GetSize(screen_rect);
|
|
|
|
Rect2 a = CutLeft(&screen_rect, 0.3f * size.x);
|
|
Rect2 b = CutBottom(&a, 0.4f * size.y);
|
|
Rect2 c = Shrink(b, 20);
|
|
|
|
window->total_rect = ToRect2I(c);
|
|
window->document_rect = window->total_rect;
|
|
}
|
|
|
|
{
|
|
Window *window = GetWindow(CommandWindowID);
|
|
if (window->visible) {
|
|
Rect2 screen_rect = GetScreenRectF();
|
|
Vec2 size = GetSize(screen_rect);
|
|
CutTop(&screen_rect, size.y * 0.05f);
|
|
CutLeft(&screen_rect, size.x * 0.2f);
|
|
CutRight(&screen_rect, size.x * 0.2f);
|
|
Rect2 r = CutTop(&screen_rect, FontLineSpacing * 30.f);
|
|
|
|
window->total_rect = ToRect2I(r);
|
|
window->document_rect = window->total_rect;
|
|
|
|
Window *title_bar_window = GetWindow(window->title_bar_window);
|
|
if (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 *window = GetWindow(PopupWindowID);
|
|
Rect2 screen_rect = GetScreenRectF();
|
|
Vec2 size = GetSize(screen_rect);
|
|
|
|
Rect2 a = CutRight(&screen_rect, 0.3f * size.x);
|
|
Rect2 b = CutBottom(&a, 0.15f * size.y);
|
|
Rect2 c = Shrink(b, 20);
|
|
|
|
window->total_rect = ToRect2I(c);
|
|
window->document_rect = window->total_rect;
|
|
}
|
|
} |