Refactor active windows
This commit is contained in:
@@ -219,16 +219,12 @@ void ReloadFont(Int font_size) {
|
|||||||
|
|
||||||
void HandleGlobalCommands() {
|
void HandleGlobalCommands() {
|
||||||
Window *command_window = GetWindow(CommandWindowID);
|
Window *command_window = GetWindow(CommandWindowID);
|
||||||
if (!IsActive(command_window)) {
|
|
||||||
command_window->visible = false;
|
|
||||||
}
|
|
||||||
if (CtrlPress(KEY_P)) {
|
if (CtrlPress(KEY_P)) {
|
||||||
if (command_window->visible) {
|
if (command_window->visible) {
|
||||||
SetActiveWindow(GetLastActiveWindow());
|
SetActiveWindow(GetLastActiveWindow());
|
||||||
} else {
|
} else {
|
||||||
SetActiveWindow(command_window->id);
|
SetActiveWindow(command_window->id);
|
||||||
}
|
}
|
||||||
command_window->visible = !command_window->visible;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlPress(KEY_MINUS)) {
|
if (CtrlPress(KEY_MINUS)) {
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ void HandleActiveWindowBindings(Window *window) {
|
|||||||
|
|
||||||
if (window->fuzzy_search && search) {
|
if (window->fuzzy_search && search) {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
String16 first_line_string = GetLineStringWithoutNL(*buffer, 0);
|
String16 first_line_string = GetLineString(*buffer, 0);
|
||||||
Array<FuzzyPair> ratings = FuzzySearchLines(scratch, buffer, 1, buffer->line_starts.len, first_line_string);
|
Array<FuzzyPair> ratings = FuzzySearchLines(scratch, buffer, 1, buffer->line_starts.len, first_line_string);
|
||||||
|
|
||||||
Buffer *temp_buffer = CreateTempBuffer(scratch, buffer->cap);
|
Buffer *temp_buffer = CreateTempBuffer(scratch, buffer->cap);
|
||||||
@@ -340,13 +340,6 @@ void HandleActiveWindowBindings(Window *window) {
|
|||||||
Command_Replace(&view, L"\n");
|
Command_Replace(&view, L"\n");
|
||||||
Command_SelectRange(&view, {});
|
Command_SelectRange(&view, {});
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (window->id.id == CommandWindowID.id) {
|
|
||||||
Window *command_window = GetWindow(CommandWindowID);
|
|
||||||
command_window->visible = !command_window->visible;
|
|
||||||
ActiveWindow = GetLastActiveWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
Window *window = GetWindow(GetLastActiveWindow());
|
Window *window = GetWindow(GetLastActiveWindow());
|
||||||
View *view = GetView(window->active_view);
|
View *view = GetView(window->active_view);
|
||||||
@@ -477,10 +470,9 @@ void HandleWindowBindings(Window *window) {
|
|||||||
ProfileFunction();
|
ProfileFunction();
|
||||||
View &view = *GetActiveView(window);
|
View &view = *GetActiveView(window);
|
||||||
Buffer *buffer = GetBuffer(view.buffer_id);
|
Buffer *buffer = GetBuffer(view.buffer_id);
|
||||||
|
bool is_active = IsActive(window);
|
||||||
|
|
||||||
if (IsActive(window)) {
|
if (is_active) HandleActiveWindowBindings(window);
|
||||||
HandleActiveWindowBindings(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clip scroll
|
// Clip scroll
|
||||||
{
|
{
|
||||||
@@ -498,21 +490,27 @@ void HandleWindowBindings(Window *window) {
|
|||||||
void ChangeActiveWindowAndScroll(Array<Int> &order) {
|
void ChangeActiveWindowAndScroll(Array<Int> &order) {
|
||||||
For(order) {
|
For(order) {
|
||||||
Window *window = &Windows[it];
|
Window *window = &Windows[it];
|
||||||
View *view = GetActiveView(window);
|
|
||||||
|
|
||||||
|
if (window->invisible_when_inactive) {
|
||||||
|
if (IsActive(window)) window->visible = true;
|
||||||
|
else window->visible = false;
|
||||||
|
}
|
||||||
|
if (!window->visible) continue;
|
||||||
|
|
||||||
|
View *view = GetActiveView(window);
|
||||||
Vec2 mouse = GetMousePosition();
|
Vec2 mouse = GetMousePosition();
|
||||||
bool mouse_in_window = CheckCollisionPointRec(mouse, ToRectangle(window->total_rect));
|
bool mouse_in_window = CheckCollisionPointRec(mouse, ToRectangle(window->total_rect));
|
||||||
if (mouse_in_window) {
|
if (mouse_in_window) {
|
||||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||||
SetActiveWindow(window->id);
|
SetActiveWindow(window->id);
|
||||||
}
|
}
|
||||||
if (LastFrameIDWhenSwitchedActiveWindow != FrameID) {
|
if (LastFrameIDWhenScrolled != FrameID) {
|
||||||
if (IsKeyDown(KEY_F1)) {
|
if (IsKeyDown(KEY_F1)) {
|
||||||
view->scroll.x -= (Int)(GetMouseWheelMove() * 48);
|
view->scroll.x -= (Int)(GetMouseWheelMove() * 48);
|
||||||
} else {
|
} else {
|
||||||
view->scroll.y -= (Int)(GetMouseWheelMove() * 48);
|
view->scroll.y -= (Int)(GetMouseWheelMove() * 48);
|
||||||
}
|
}
|
||||||
LastFrameIDWhenSwitchedActiveWindow = FrameID;
|
LastFrameIDWhenScrolled = FrameID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,23 +50,20 @@ View *CreateView(BufferID buffer_id) {
|
|||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool IsSpecial(WindowID window) {
|
|
||||||
bool result = window.id == CommandWindowID.id || window.id == InfoBarWindowID.id;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
WindowID GetLastActiveWindow() {
|
WindowID GetLastActiveWindow() {
|
||||||
For(IterateInReverse(&WindowSwitchHistory)) {
|
For(IterateInReverse(&WindowSwitchHistory)) {
|
||||||
if (!IsSpecial(it)) return it;
|
return it;
|
||||||
}
|
}
|
||||||
return NullWindowID;
|
return NullWindowID;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetActiveWindow(WindowID window) {
|
void SetActiveWindow(WindowID window) {
|
||||||
if (window.id != ActiveWindow.id && LastFrameIDWhenSwitchedActiveWindow != FrameID) {
|
if (window.id != ActiveWindow.id && LastFrameIDWhenSwitchedActiveWindow != FrameID) {
|
||||||
Add(&WindowSwitchHistory, window);
|
|
||||||
ActiveWindow = window;
|
ActiveWindow = window;
|
||||||
LastFrameIDWhenSwitchedActiveWindow = FrameID;
|
LastFrameIDWhenSwitchedActiveWindow = FrameID;
|
||||||
|
|
||||||
|
Window *w = GetWindow(window);
|
||||||
|
if (!w->dont_save_in_active_window_history) Add(&WindowSwitchHistory, window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,13 +32,8 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
- Save file (utf16->utf8)
|
- Save file (utf16->utf8)
|
||||||
- reuse buffers!!
|
|
||||||
- resize windows
|
- resize windows
|
||||||
- Change font size
|
- list files and open
|
||||||
- command window
|
|
||||||
- maybe use lua and have there be lua commands that you choose with cursor
|
|
||||||
- open "asd/asd/asd/asd"
|
|
||||||
- list "directory" and since it returns strings we can fill up the command buffer with files to open
|
|
||||||
- file dock on left side
|
- file dock on left side
|
||||||
- We can actually combine this with command window and lua, it's just going to be a buffer of
|
- We can actually combine this with command window and lua, it's just going to be a buffer of
|
||||||
- open "asd/asd/asd/asd"
|
- open "asd/asd/asd/asd"
|
||||||
@@ -96,7 +91,7 @@ int main(void) {
|
|||||||
LoadTextA(b);
|
LoadTextA(b);
|
||||||
AddView(w, v->id);
|
AddView(w, v->id);
|
||||||
}
|
}
|
||||||
ActiveWindow.id = 1;
|
SetActiveWindow({1});
|
||||||
|
|
||||||
{
|
{
|
||||||
Window *w = CreateWindow();
|
Window *w = CreateWindow();
|
||||||
@@ -116,6 +111,7 @@ int main(void) {
|
|||||||
Window *w = CreateWindow();
|
Window *w = CreateWindow();
|
||||||
w->draw_scrollbar = false;
|
w->draw_scrollbar = false;
|
||||||
w->draw_line_numbers = false;
|
w->draw_line_numbers = false;
|
||||||
|
w->dont_save_in_active_window_history = true;
|
||||||
Buffer *b = CreateBuffer(sys_allocator, "*infobar*");
|
Buffer *b = CreateBuffer(sys_allocator, "*infobar*");
|
||||||
b->no_history = true;
|
b->no_history = true;
|
||||||
View *v = CreateView(b->id);
|
View *v = CreateView(b->id);
|
||||||
@@ -130,6 +126,8 @@ int main(void) {
|
|||||||
w->visible = false;
|
w->visible = false;
|
||||||
w->fuzzy_search = true;
|
w->fuzzy_search = true;
|
||||||
w->execute_line = true;
|
w->execute_line = true;
|
||||||
|
w->invisible_when_inactive = true;
|
||||||
|
w->dont_save_in_active_window_history = true;
|
||||||
Buffer *b = CreateBuffer(sys_allocator, "*commands*");
|
Buffer *b = CreateBuffer(sys_allocator, "*commands*");
|
||||||
View *v = CreateView(b->id);
|
View *v = CreateView(b->id);
|
||||||
ReplaceText(b, GetEndAsRange(*b), L"\n");
|
ReplaceText(b, GetEndAsRange(*b), L"\n");
|
||||||
@@ -203,9 +201,11 @@ int main(void) {
|
|||||||
ReplaceInfobarData();
|
ReplaceInfobarData();
|
||||||
For(IterateInReverse(&order)) {
|
For(IterateInReverse(&order)) {
|
||||||
Window &window = Windows[it];
|
Window &window = Windows[it];
|
||||||
|
if (window.visible) {
|
||||||
HandleWindowBindings(&window);
|
HandleWindowBindings(&window);
|
||||||
DrawWindow(window);
|
DrawWindow(window);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
SetMouseCursor();
|
SetMouseCursor();
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,8 @@ struct Window {
|
|||||||
|
|
||||||
bool fuzzy_search : 1;
|
bool fuzzy_search : 1;
|
||||||
bool execute_line : 1;
|
bool execute_line : 1;
|
||||||
|
bool invisible_when_inactive : 1;
|
||||||
|
bool dont_save_in_active_window_history : 1;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -103,7 +105,7 @@ Int FontLineSpacing;
|
|||||||
Int FontCharSpacing;
|
Int FontCharSpacing;
|
||||||
|
|
||||||
Int FrameID;
|
Int FrameID;
|
||||||
Int LastFrameIDWhenScrolled;
|
Int LastFrameIDWhenScrolled = -1;
|
||||||
|
|
||||||
Int LastFrameIDWhenSwitchedActiveWindow;
|
Int LastFrameIDWhenSwitchedActiveWindow;
|
||||||
Array<WindowID> WindowSwitchHistory; // @todo: probably better as a circular buffer
|
Array<WindowID> WindowSwitchHistory; // @todo: probably better as a circular buffer
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ void SetMouseCursor() {
|
|||||||
|
|
||||||
Array<Int> GetWindowZOrder(Allocator allocator) {
|
Array<Int> GetWindowZOrder(Allocator allocator) {
|
||||||
Array<Int> order = {allocator};
|
Array<Int> order = {allocator};
|
||||||
For(Windows) if (it.z == 2 && it.visible) Add(&order, GetIndex(Windows, it));
|
For(Windows) if (it.z == 2) Add(&order, GetIndex(Windows, it));
|
||||||
For(Windows) if (it.z == 1 && it.visible) Add(&order, GetIndex(Windows, it));
|
For(Windows) if (it.z == 1) Add(&order, GetIndex(Windows, it));
|
||||||
For(Windows) if (it.z == 0 && it.visible) Add(&order, GetIndex(Windows, it));
|
For(Windows) if (it.z == 0) Add(&order, GetIndex(Windows, it));
|
||||||
return order;
|
return order;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user