Window flags, improve mouse cursor,
This commit is contained in:
@@ -11,11 +11,10 @@ void InitBuffer(Allocator allocator, Buffer *buffer) {
|
|||||||
Add(&buffer->line_starts, (Int)0);
|
Add(&buffer->line_starts, (Int)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferID CreateBuffer(Allocator allocator) {
|
Buffer *CreateBuffer(Allocator allocator) {
|
||||||
Buffer result = {};
|
Buffer *result = Alloc(&Buffers);
|
||||||
InitBuffer(allocator, &result);
|
InitBuffer(allocator, result);
|
||||||
Add(&Buffers, result);
|
return result;
|
||||||
return result.id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Grow(Buffer *buffer, Int change_size) {
|
void Grow(Buffer *buffer, Int change_size) {
|
||||||
|
|||||||
@@ -22,19 +22,17 @@
|
|||||||
#include "view_draw.cpp"
|
#include "view_draw.cpp"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
- Window IDS and View IDS and Buffer IDS
|
j- Open file (utf8->utf16), process determine line endings, tabs to spaces?, Save file (utf16->utf8)
|
||||||
- Null Window, Null View, Null Buffer
|
|
||||||
- Open file (utf8->utf16), process determine line endings, tabs to spaces?, Save file (utf16->utf8)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- move off raylib
|
|
||||||
- line endings
|
- line endings
|
||||||
- command window
|
- command window
|
||||||
- word completion
|
- word completion
|
||||||
- Colored strings
|
- Colored strings
|
||||||
- file dock on left side
|
- file dock on left side
|
||||||
- Font cache
|
|
||||||
|
- move off raylib
|
||||||
|
- proper double click that works on laptop
|
||||||
|
- font cache and on demand unicode loads
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
@@ -67,62 +65,36 @@ int main(void) {
|
|||||||
MainFont = LoadFontEx("c:\\Windows\\Fonts\\consola.ttf", (int)FontSize, NULL, 500);
|
MainFont = LoadFontEx("c:\\Windows\\Fonts\\consola.ttf", (int)FontSize, NULL, 500);
|
||||||
FontCharSpacing = GetCharSpacing(MainFont, FontSize, FontSpacing);
|
FontCharSpacing = GetCharSpacing(MainFont, FontSize, FontSpacing);
|
||||||
|
|
||||||
|
Allocator sys_allocator = GetSystemAllocator();
|
||||||
// Create null
|
// Create null
|
||||||
{
|
{
|
||||||
CreateBuffer(GetSystemAllocator());
|
Buffer *buffer = CreateBuffer(sys_allocator);
|
||||||
|
View *view = CreateView(buffer->id);
|
||||||
View view = {AllocViewID()};
|
Window *window = CreateWindow();
|
||||||
Add(&view.carets, {0, 0});
|
window->visible = false;
|
||||||
Add(&Views, view);
|
AddView(window->id, view->id);
|
||||||
|
|
||||||
Window window = {AllocWindowID()};
|
|
||||||
Add(&window.views, {0});
|
|
||||||
Add(&Windows, window);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
Window window = {AllocWindowID()};
|
Window *w = CreateWindow();
|
||||||
{
|
Buffer *b = CreateBuffer(sys_allocator);
|
||||||
View view = {};
|
View *v = CreateView(b->id);
|
||||||
view.id = AllocViewID();
|
LoadTextA(b);
|
||||||
Add(&view.carets, {0, 0});
|
AddView(w->id, v->id);
|
||||||
view.buffer_id = CreateBuffer(Perm);
|
|
||||||
Buffer *buffer = GetBuffer(view.buffer_id);
|
|
||||||
LoadTextA(buffer);
|
|
||||||
Add(&Views, view);
|
|
||||||
Add(&window.views, view.id);
|
|
||||||
window.active_view = view.id;
|
|
||||||
}
|
|
||||||
Add(&Windows, window);
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Window window = {AllocWindowID()};
|
Window *w = CreateWindow();
|
||||||
{
|
Buffer *b = CreateBuffer(sys_allocator);
|
||||||
View view = {AllocViewID()};
|
View *v = CreateView(b->id);
|
||||||
Add(&view.carets, {0, 0});
|
LoadUnicode(b);
|
||||||
view.buffer_id = CreateBuffer(Perm);
|
AddView(w->id, v->id);
|
||||||
Buffer *buffer = GetBuffer(view.buffer_id);
|
|
||||||
LoadUnicode(buffer);
|
|
||||||
Add(&Views, view);
|
|
||||||
Add(&window.views, view.id);
|
|
||||||
window.active_view = view.id;
|
|
||||||
}
|
|
||||||
Add(&Windows, window);
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Window window = {AllocWindowID()};
|
Window *w = CreateWindow();
|
||||||
{
|
Buffer *b = CreateBuffer(sys_allocator);
|
||||||
View view = {};
|
View *v = CreateView(b->id);
|
||||||
view.id = AllocViewID();
|
LoadLine(b);
|
||||||
Add(&view.carets, {0, 0});
|
AddView(w->id, v->id);
|
||||||
view.buffer_id = CreateBuffer(Perm);
|
|
||||||
Buffer *buffer = GetBuffer(view.buffer_id);
|
|
||||||
LoadLine(buffer);
|
|
||||||
Add(&Views, view);
|
|
||||||
Add(&window.views, view.id);
|
|
||||||
window.active_view = view.id;
|
|
||||||
}
|
|
||||||
Add(&Windows, window);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!WindowShouldClose()) {
|
while (!WindowShouldClose()) {
|
||||||
@@ -131,35 +103,38 @@ int main(void) {
|
|||||||
Rect2I screen_rect = GetScreenRect();
|
Rect2I screen_rect = GetScreenRect();
|
||||||
float line_numbers_size = MeasureTextEx(MainFont, "12345", (float)FontSize, (float)FontSpacing).x;
|
float line_numbers_size = MeasureTextEx(MainFont, "12345", (float)FontSize, (float)FontSpacing).x;
|
||||||
{
|
{
|
||||||
Windows[1].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 0.33));
|
int i = 1;
|
||||||
Windows[1].document_rect = Windows[1].total_rect;
|
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 0.33));
|
||||||
Windows[1].scrollbar_rect = CutRight(&Windows[1].document_rect, 10);
|
Windows[i].document_rect = Windows[i].total_rect;
|
||||||
Windows[1].infobar_rect = CutBottom(&Windows[1].document_rect, (Int)MenuFontSize);
|
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10);
|
||||||
Windows[1].line_numbers_rect = CutLeft(&Windows[1].document_rect, (Int)line_numbers_size);
|
if (Windows[i].draw_infobar) Windows[i].infobar_rect = CutBottom(&Windows[i].document_rect, (Int)MenuFontSize);
|
||||||
|
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
int i = 2;
|
int i = 2;
|
||||||
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 0.5));
|
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 0.5));
|
||||||
Windows[i].document_rect = Windows[i].total_rect;
|
Windows[i].document_rect = Windows[i].total_rect;
|
||||||
Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10);
|
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10);
|
||||||
Windows[i].infobar_rect = CutBottom(&Windows[i].document_rect, (Int)MenuFontSize);
|
if (Windows[i].draw_infobar) Windows[i].infobar_rect = CutBottom(&Windows[i].document_rect, (Int)MenuFontSize);
|
||||||
Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
|
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
int i = 3;
|
int i = 3;
|
||||||
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 1.0));
|
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 1.0));
|
||||||
Windows[i].document_rect = Windows[i].total_rect;
|
Windows[i].document_rect = Windows[i].total_rect;
|
||||||
Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10);
|
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10);
|
||||||
Windows[i].infobar_rect = CutBottom(&Windows[i].document_rect, (Int)MenuFontSize);
|
if (Windows[i].draw_infobar) Windows[i].infobar_rect = CutBottom(&Windows[i].document_rect, (Int)MenuFontSize);
|
||||||
Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
|
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(ColorBackground);
|
ClearBackground(ColorBackground);
|
||||||
For(Windows) {
|
For(Windows) {
|
||||||
|
if (!it.visible) continue;
|
||||||
HandleKeybindings(&it);
|
HandleKeybindings(&it);
|
||||||
DrawWindow(it);
|
DrawWindow(it);
|
||||||
}
|
}
|
||||||
|
SetMouseCursor();
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
|||||||
@@ -54,9 +54,16 @@ struct Window {
|
|||||||
Rect2I line_numbers_rect;
|
Rect2I line_numbers_rect;
|
||||||
Rect2I document_rect;
|
Rect2I document_rect;
|
||||||
|
|
||||||
int mouse_selecting_scrollbar;
|
|
||||||
bool mouse_selecting;
|
|
||||||
double mouse_scroller_offset;
|
double mouse_scroller_offset;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
bool mouse_selecting_scrollbar : 1;
|
||||||
|
bool mouse_selecting : 1;
|
||||||
|
bool draw_scrollbar : 1;
|
||||||
|
bool draw_line_numbers : 1;
|
||||||
|
bool draw_infobar : 1;
|
||||||
|
bool visible : 1;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Scroller {
|
struct Scroller {
|
||||||
@@ -83,7 +90,7 @@ Array<View> Views = {};
|
|||||||
Array<Window> Windows = {};
|
Array<Window> Windows = {};
|
||||||
WindowID ActiveWindow = {};
|
WindowID ActiveWindow = {};
|
||||||
|
|
||||||
float MenuFontSize = 19.f;
|
float MenuFontSize;
|
||||||
Font MenuFont;
|
Font MenuFont;
|
||||||
|
|
||||||
Font MainFont;
|
Font MainFont;
|
||||||
|
|||||||
@@ -334,17 +334,7 @@ void HandleKeybindings(Window *window) {
|
|||||||
bool mouse_in_scrollbar = CheckCollisionPointRec(_mouse, ToRectangle(window->scrollbar_rect));
|
bool mouse_in_scrollbar = CheckCollisionPointRec(_mouse, ToRectangle(window->scrollbar_rect));
|
||||||
Vec2I mouse = ToVec2I(_mouse);
|
Vec2I mouse = ToVec2I(_mouse);
|
||||||
|
|
||||||
if (!mouse_in_view) SetMouseCursor(MOUSE_CURSOR_DEFAULT);
|
|
||||||
|
|
||||||
if (!(mouse_in_scrollbar || window->mouse_selecting_scrollbar) && (mouse_in_view || window->mouse_selecting)) {
|
if (!(mouse_in_scrollbar || window->mouse_selecting_scrollbar) && (mouse_in_view || window->mouse_selecting)) {
|
||||||
if (!window->mouse_selecting) {
|
|
||||||
if (mouse_in_view) {
|
|
||||||
SetMouseCursor(MOUSE_CURSOR_IBEAM);
|
|
||||||
} else {
|
|
||||||
SetMouseCursor(MOUSE_CURSOR_DEFAULT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec2I mworld = mouse - window->document_rect.min + view.scroll;
|
Vec2I mworld = mouse - window->document_rect.min + view.scroll;
|
||||||
Vec2I pos = mworld / Vec2I{FontCharSpacing, FontLineSpacing};
|
Vec2I pos = mworld / Vec2I{FontCharSpacing, FontLineSpacing};
|
||||||
XY xy = {(Int)(pos.x), (Int)(pos.y)};
|
XY xy = {(Int)(pos.x), (Int)(pos.y)};
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ void DrawWindow(Window &window) {
|
|||||||
EndScissorMode();
|
EndScissorMode();
|
||||||
|
|
||||||
// Draw scrollbar
|
// Draw scrollbar
|
||||||
{
|
if (window.draw_scrollbar) {
|
||||||
Vec2 mouse = GetMousePosition();
|
Vec2 mouse = GetMousePosition();
|
||||||
bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, ToRectangle(window.scrollbar_rect));
|
bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, ToRectangle(window.scrollbar_rect));
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ void DrawWindow(Window &window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw line numbers
|
// Draw line numbers
|
||||||
{
|
if (window.draw_line_numbers) {
|
||||||
Rect2I r = window.line_numbers_rect;
|
Rect2I r = window.line_numbers_rect;
|
||||||
DrawRectangleRec(ToRectangle(r), ColorBackground);
|
DrawRectangleRec(ToRectangle(r), ColorBackground);
|
||||||
BeginScissorMode((int)r.min.x, (int)r.min.y, (int)r.max.x - (int)r.min.x, (int)r.max.y - (int)r.min.y);
|
BeginScissorMode((int)r.min.x, (int)r.min.y, (int)r.max.x - (int)r.min.x, (int)r.max.y - (int)r.min.y);
|
||||||
@@ -213,7 +213,7 @@ void DrawWindow(Window &window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw info bar
|
// Draw info bar
|
||||||
{
|
if (window.draw_infobar) {
|
||||||
Rect2I r = window.infobar_rect;
|
Rect2I r = window.infobar_rect;
|
||||||
DrawRectangleRec(ToRectangle(r), ColorScrollbarBackground);
|
DrawRectangleRec(ToRectangle(r), ColorScrollbarBackground);
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
Window *CreateWindow() {
|
||||||
|
Window *w = Alloc(&Windows);
|
||||||
|
w->visible = true;
|
||||||
|
w->draw_scrollbar = true;
|
||||||
|
w->draw_line_numbers = true;
|
||||||
|
w->draw_infobar = true;
|
||||||
|
w->id = AllocWindowID();
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddView(WindowID window, ViewID view) {
|
||||||
|
Window *w = GetWindow(window);
|
||||||
|
if (w->active_view.id == 0) w->active_view = view;
|
||||||
|
For(w->views) if (it.id == view.id) return;
|
||||||
|
Add(&w->views, view);
|
||||||
|
}
|
||||||
|
|
||||||
|
View *CreateView(BufferID buffer_id) {
|
||||||
|
View *w = Alloc(&Views);
|
||||||
|
w->id = AllocViewID();
|
||||||
|
w->buffer_id = buffer_id;
|
||||||
|
Add(&w->carets, {0, 0});
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetMouseCursor() {
|
||||||
|
Window *w = GetActiveWindow();
|
||||||
|
Vec2 mouse = GetMousePosition();
|
||||||
|
|
||||||
|
bool mouse_in_document = CheckCollisionPointRec(mouse, ToRectangle(w->document_rect));
|
||||||
|
bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, ToRectangle(w->scrollbar_rect));
|
||||||
|
bool mouse_in_total = CheckCollisionPointRec(mouse, ToRectangle(w->total_rect));
|
||||||
|
|
||||||
|
if (w->mouse_selecting || mouse_in_document) {
|
||||||
|
SetMouseCursor(MOUSE_CURSOR_IBEAM);
|
||||||
|
} else if (mouse_in_scrollbar || w->mouse_selecting_scrollbar) {
|
||||||
|
SetMouseCursor(MOUSE_CURSOR_DEFAULT);
|
||||||
|
} else {
|
||||||
|
SetMouseCursor(MOUSE_CURSOR_POINTING_HAND);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user