Small mouse fix

This commit is contained in:
Krzosa Karol
2024-06-08 15:58:18 +02:00
parent 2ec4a2a28d
commit b08c7c9ce6
3 changed files with 27 additions and 19 deletions

View File

@@ -81,11 +81,9 @@ main :: proc(): int {
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
if sandbox_chosen == SANDBOX_TEXT_EDITOR { if sandbox_chosen == SANDBOX_TEXT_EDITOR {
if !TeInited InitTextEditor(font, font_size, font_spacing); UpdateTextEditor(screen_rect, font, font_size, font_spacing);
ComputeWindowRects(screen_rect);
UpdateAndDrawWindows(font, font_size);
} else if sandbox_chosen == SANDBOX_PROTOTYPE { } else if sandbox_chosen == SANDBOX_PROTOTYPE {
UpdatePrototype(screen_rect);
} }
DrawRect(top_bar_original, LIGHTGRAY); DrawRect(top_bar_original, LIGHTGRAY);

View File

@@ -0,0 +1,2 @@
UpdatePrototype :: proc(rect: Rect2P) {
}

View File

@@ -8,7 +8,8 @@ FocusedWindow: *Window;
WindowStack: [8]Window; WindowStack: [8]Window;
WindowStackCount: int; WindowStackCount: int;
InitTextEditor :: proc(font: Font, font_size: float, font_spacing: float) { UpdateTextEditor :: proc(rect: Rect2P, font: Font, font_size: float, font_spacing: float) {
if !TeInited {
TeInited = true; TeInited = true;
TeFont = font; TeFont = font;
TeFontSpacing = font_spacing; TeFontSpacing = font_spacing;
@@ -25,6 +26,9 @@ InitTextEditor :: proc(font: Font, font_size: float, font_spacing: float) {
AddWindow({buffer = &TeBuffer}); AddWindow({buffer = &TeBuffer});
AddWindow({buffer = &TeBuffer}); AddWindow({buffer = &TeBuffer});
FocusedWindow = &WindowStack[0]; FocusedWindow = &WindowStack[0];
}
ComputeWindowRects(rect);
UpdateAndDrawWindows(font, font_size);
} }
Window :: struct { Window :: struct {
@@ -32,6 +36,7 @@ Window :: struct {
cursor: Selection; cursor: Selection;
scroll: Vector2; scroll: Vector2;
mouse_scrolling: bool; mouse_scrolling: bool;
mouse_selecting: bool;
rect: Rect2P; rect: Rect2P;
} }
@@ -330,6 +335,7 @@ UpdateAndDrawWindow :: proc(w: *Window, font: Font, font_size: float) {
if CheckCollisionPointRec(mouse_p, Rect2PToRectangle(w.rect)) { if CheckCollisionPointRec(mouse_p, Rect2PToRectangle(w.rect)) {
if CheckCollisionPointRec(mouse_p, Rect2PToRectangle(text_window_rect)) && !w.mouse_scrolling { if CheckCollisionPointRec(mouse_p, Rect2PToRectangle(text_window_rect)) && !w.mouse_scrolling {
if IsMouseButtonPressed(MOUSE_BUTTON_LEFT) { if IsMouseButtonPressed(MOUSE_BUTTON_LEFT) {
w.mouse_selecting = true;
p := Vector2Add(mouse_p, w.scroll); p := Vector2Add(mouse_p, w.scroll);
p = Vector2Subtract(p, text_window_rect.min); p = Vector2Subtract(p, text_window_rect.min);
p = Vector2Divide(p, Monosize); p = Vector2Divide(p, Monosize);
@@ -348,7 +354,7 @@ UpdateAndDrawWindow :: proc(w: *Window, font: Font, font_size: float) {
} }
} }
if IsMouseButtonDown(MOUSE_BUTTON_LEFT) { if w.mouse_selecting && IsMouseButtonDown(MOUSE_BUTTON_LEFT) {
SetMouseCursor(MOUSE_CURSOR_DEFAULT); SetMouseCursor(MOUSE_CURSOR_DEFAULT);
p := Vector2Add(mouse_p, w.scroll); p := Vector2Add(mouse_p, w.scroll);
p = Vector2Subtract(p, text_window_rect.min); p = Vector2Subtract(p, text_window_rect.min);
@@ -356,6 +362,8 @@ UpdateAndDrawWindow :: proc(w: *Window, font: Font, font_size: float) {
x := :int(floorf(p.x)); x := :int(floorf(p.x));
y := :int(floorf(p.y)); y := :int(floorf(p.y));
w.cursor.b = CalculatePosFromVisualPos(w.buffer, {x, y}); w.cursor.b = CalculatePosFromVisualPos(w.buffer, {x, y});
} else {
w.mouse_selecting = false;
} }
if w.mouse_scrolling { if w.mouse_scrolling {