Small mouse fix
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
2
examples/text_editor/prototype.lc
Normal file
2
examples/text_editor/prototype.lc
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
UpdatePrototype :: proc(rect: Rect2P) {
|
||||||
|
}
|
||||||
@@ -8,23 +8,27 @@ 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) {
|
||||||
TeInited = true;
|
if !TeInited {
|
||||||
TeFont = font;
|
TeInited = true;
|
||||||
TeFontSpacing = font_spacing;
|
TeFont = font;
|
||||||
TeFontSize = font_size;
|
TeFontSpacing = font_spacing;
|
||||||
|
TeFontSize = font_size;
|
||||||
|
|
||||||
glyph_info: GlyphInfo = GetGlyphInfo(TeFont, 'A');
|
glyph_info: GlyphInfo = GetGlyphInfo(TeFont, 'A');
|
||||||
size := MeasureTextEx(TeFont, "A", TeFontSize, TeFontSpacing);
|
size := MeasureTextEx(TeFont, "A", TeFontSize, TeFontSpacing);
|
||||||
Monosize = {:float(glyph_info.image.width), size.y};
|
Monosize = {:float(glyph_info.image.width), size.y};
|
||||||
|
|
||||||
file_content := LoadFileText("C:/Work/language/examples/text_editor/main.lc");
|
file_content := LoadFileText("C:/Work/language/examples/text_editor/main.lc");
|
||||||
AddText(&TeBuffer, {file_content, :int(strlen(file_content))});
|
AddText(&TeBuffer, {file_content, :int(strlen(file_content))});
|
||||||
UnloadFileText(file_content);
|
UnloadFileText(file_content);
|
||||||
|
|
||||||
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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user