소스 검색

Cursor cleanup

luboslenco 3 주 전
부모
커밋
efdfb15a59

+ 1 - 1
base/sources/backends/android_system.c

@@ -1064,7 +1064,7 @@ void iron_mouse_get_position(int *x, int *y) {
 	y = 0;
 }
 
-void iron_mouse_set_cursor(int cursor_index) {}
+void iron_mouse_set_cursor(iron_cursor_t cursor_index) {}
 
 void initAndroidFileReader();
 // void IronAndroidVideoInit();

+ 1 - 1
base/sources/backends/ios_system.m

@@ -110,7 +110,7 @@ void iron_mouse_show(void) {}
 void iron_mouse_hide(void) {}
 void iron_mouse_set_position(int x, int y) {}
 void iron_mouse_get_position(int *x, int *y) {}
-void iron_mouse_set_cursor(int cursor_index) {}
+void iron_mouse_set_cursor(iron_cursor_t cursor_index) {}
 
 bool with_autoreleasepool(bool (*f)(void)) {
 	@autoreleasepool {

+ 22 - 50
base/sources/backends/linux_system.c

@@ -1211,57 +1211,29 @@ void iron_mouse_hide() {
 	}
 }
 
-void iron_mouse_set_cursor(int cursor_index) {
-	struct iron_x11_window *window = &x11_ctx.windows[0];
-	if (!mouse_hidden) {
-		Cursor cursor;
-		if (cursor_index == 0) {
-			cursor = xlib.XcursorLibraryLoadCursor(x11_ctx.display, "left_ptr"); // "arrow"
-		}
-		else if (cursor_index == 1) {
-			cursor = xlib.XcursorLibraryLoadCursor(x11_ctx.display, "hand1");
-		}
-		else if (cursor_index == 2) {
-			cursor = xlib.XcursorLibraryLoadCursor(x11_ctx.display, "xterm");
-		}
-		else if (cursor_index == 3) {
-			cursor = xlib.XcursorLibraryLoadCursor(x11_ctx.display, "sb_h_double_arrow");
-		}
-		else if (cursor_index == 4) {
-			cursor = xlib.XcursorLibraryLoadCursor(x11_ctx.display, "sb_v_double_arrow");
-		}
-		else if (cursor_index == 5) {
-			cursor = xlib.XcursorLibraryLoadCursor(x11_ctx.display, "top_right_corner");
-		}
-		else if (cursor_index == 6) {
-			cursor = xlib.XcursorLibraryLoadCursor(x11_ctx.display, "bottom_right_corner");
-		}
-		else if (cursor_index == 7) {
-			cursor = xlib.XcursorLibraryLoadCursor(x11_ctx.display, "top_left_corner");
-		}
-		else if (cursor_index == 8) {
-			cursor = xlib.XcursorLibraryLoadCursor(x11_ctx.display, "bottom_left_corner");
-		}
-		else if (cursor_index == 9) {
-			cursor = xlib.XcursorLibraryLoadCursor(x11_ctx.display, "grab");
-		}
-		else if (cursor_index == 10) {
-			cursor = xlib.XcursorLibraryLoadCursor(x11_ctx.display, "grabbing");
-		}
-		else if (cursor_index == 11) {
-			cursor = xlib.XcursorLibraryLoadCursor(x11_ctx.display, "not-allowed");
-		}
-		else if (cursor_index == 12) {
-			cursor = xlib.XcursorLibraryLoadCursor(x11_ctx.display, "watch");
-		}
-		else if (cursor_index == 13) {
-			cursor = xlib.XcursorLibraryLoadCursor(x11_ctx.display, "crosshair");
-		}
-		else {
-			cursor = xlib.XcursorLibraryLoadCursor(x11_ctx.display, "arrow");
-		}
-		xlib.XDefineCursor(x11_ctx.display, window->window, cursor);
+void iron_mouse_set_cursor(iron_cursor_t cursor_index) {
+	if (mouse_hidden) {
+		return;
+	}
+
+	Cursor cursor;
+	if (cursor_index == IRON_CURSOR_HAND) {
+		cursor = xlib.XcursorLibraryLoadCursor(x11_ctx.display, "hand1");
+	}
+	else if (cursor_index == IRON_CURSOR_IBEAM) {
+		cursor = xlib.XcursorLibraryLoadCursor(x11_ctx.display, "xterm");
+	}
+	else if (cursor_index == IRON_CURSOR_SIZEWE) {
+		cursor = xlib.XcursorLibraryLoadCursor(x11_ctx.display, "sb_h_double_arrow");
+	}
+	else if (cursor_index == IRON_CURSOR_SIZENS) {
+		cursor = xlib.XcursorLibraryLoadCursor(x11_ctx.display, "sb_v_double_arrow");
 	}
+	else {
+		cursor = xlib.XcursorLibraryLoadCursor(x11_ctx.display, "left_ptr"); // "arrow"
+	}
+	struct iron_x11_window *window = &x11_ctx.windows[0];
+	xlib.XDefineCursor(x11_ctx.display, window->window, cursor);
 }
 
 void iron_mouse_set_position(int x, int y) {

+ 5 - 5
base/sources/backends/macos_system.m

@@ -540,21 +540,21 @@ void iron_mouse_get_position(int *x, int *y) {
 	*y = (int)point.y;
 }
 
-void iron_mouse_set_cursor(int cursor_index) {
+void iron_mouse_set_cursor(iron_cursor_t cursor_index) {
 	if (current_cursor_index == cursor_index) {
 		return;
 	}
 	current_cursor_index = cursor_index;
-	if (cursor_index == 1) {
+	if (cursor_index == IRON_CURSOR_HAND) {
 		[[NSCursor pointingHandCursor] set];
 	}
-	else if (cursor_index == 2) {
+	else if (cursor_index == IRON_CURSOR_IBEAM) {
 		[[NSCursor IBeamCursor] set];
 	}
-	else if (cursor_index == 3) {
+	else if (cursor_index == IRON_CURSOR_SIZEWE) {
 		[[NSCursor resizeLeftRightCursor] set];
 	}
-	else if (cursor_index == 4) {
+	else if (cursor_index == IRON_CURSOR_SIZENS) {
 		[[NSCursor resizeUpDownCursor] set];
 	}
 	else {

+ 7 - 16
base/sources/backends/windows_system.c

@@ -424,15 +424,18 @@ static bool gamepadFound = false;
 
 static bool cursors_initialized = false;
 static int cursor = 0;
-#define NUM_CURSORS 14
-static HCURSOR cursors[NUM_CURSORS];
+static HCURSOR cursors[5];
 static bool bg_erased = false;
 
-void iron_mouse_set_cursor(int set_cursor) {
-	cursor = set_cursor >= NUM_CURSORS ? 0 : set_cursor;
+void iron_mouse_set_cursor(iron_cursor_t set_cursor) {
+	cursor = set_cursor;
 	if (cursors_initialized) {
 		SetCursor(cursors[cursor]);
 	}
+	// Set hand icon for drag even when mouse button is pressed
+	if (set_cursor == IRON_CURSOR_HAND) {
+		SetCursor(LoadCursor(NULL, IDC_HAND));
+	}
 }
 
 LRESULT WINAPI IronWindowsMessageProcedure(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
@@ -508,19 +511,7 @@ LRESULT WINAPI IronWindowsMessageProcedure(HWND hWnd, UINT msg, WPARAM wParam, L
 		cursors[2] = LoadCursor(0, IDC_IBEAM);
 		cursors[3] = LoadCursor(0, IDC_SIZEWE);
 		cursors[4] = LoadCursor(0, IDC_SIZENS);
-		cursors[5] = LoadCursor(0, IDC_SIZENESW);
-		cursors[6] = LoadCursor(0, IDC_SIZENWSE);
-		cursors[7] = LoadCursor(0, IDC_SIZENWSE);
-		cursors[8] = LoadCursor(0, IDC_SIZENESW);
-		cursors[9] = LoadCursor(0, IDC_SIZEALL);
-		cursors[10] = LoadCursor(0, IDC_SIZEALL);
-		cursors[11] = LoadCursor(0, IDC_NO);
-		cursors[12] = LoadCursor(0, IDC_WAIT);
-		cursors[13] = LoadCursor(0, IDC_CROSS);
 		cursors_initialized = true;
-		if (cursor != 0) {
-			SetCursor(cursors[cursor]);
-		}
 		return TRUE;
 	case WM_SETCURSOR:
 		if (LOWORD(lParam) == HTCLIENT) {

+ 0 - 10
base/sources/iron.h

@@ -1457,16 +1457,6 @@ void iron_set_save_and_quit_callback(void (*callback)(bool)) {
 	iron_window_set_close_callback(_window_close_callback, NULL);
 }
 
-void iron_set_mouse_cursor(i32 id) {
-	iron_mouse_set_cursor(id);
-	#ifdef IRON_WINDOWS
-	// Set hand icon for drag even when mouse button is pressed
-	if (id == 1) {
-		SetCursor(LoadCursor(NULL, IDC_HAND));
-	}
-	#endif
-}
-
 void iron_delay_idle_sleep() {
 	paused_frames = 0;
 }

+ 9 - 1
base/sources/iron_system.h

@@ -24,6 +24,14 @@ int iron_primary_display(void);
 int iron_count_displays(void);
 iron_display_mode_t iron_display_current_mode(int display_index);
 
+typedef enum {
+	IRON_CURSOR_ARROW,
+	IRON_CURSOR_HAND,
+	IRON_CURSOR_IBEAM,
+	IRON_CURSOR_SIZEWE,
+	IRON_CURSOR_SIZENS
+} iron_cursor_t;
+
 typedef enum {
 	IRON_WINDOW_MODE_WINDOW,
 	IRON_WINDOW_MODE_FULLSCREEN
@@ -317,7 +325,7 @@ bool iron_mouse_can_lock(void);
 bool iron_mouse_is_locked(void);
 void iron_mouse_lock();
 void iron_mouse_unlock(void);
-void iron_mouse_set_cursor(int cursor);
+void iron_mouse_set_cursor(iron_cursor_t cursor);
 void iron_mouse_show(void);
 void iron_mouse_hide(void);
 void iron_mouse_set_position(int x, int y);

+ 2 - 2
base/sources/iron_ui.c

@@ -527,10 +527,10 @@ bool ui_input_changed() {
 void ui_end_input() {
 	if (ui_on_tab_drop != NULL && current->drag_tab_handle != NULL) {
 		if (current->input_dx != 0 || current->input_dy != 0) {
-			iron_mouse_set_cursor(1); // Hand
+			iron_mouse_set_cursor(IRON_CURSOR_HAND);
 		}
 		if (current->input_released) {
-			iron_mouse_set_cursor(0); // Default
+			iron_mouse_set_cursor(IRON_CURSOR_ARROW);
 			current->drag_tab_handle = NULL;
 		}
 	}

+ 3 - 3
base/sources/ts/base.ts

@@ -308,7 +308,7 @@ function base_redraw_ui() {
 
 function base_update() {
 	if (mouse_movement_x != 0 || mouse_movement_y != 0) {
-		iron_set_mouse_cursor(0); // Arrow
+		iron_mouse_set_cursor(cursor_t.ARROW);
 	}
 
 	let has_drag: bool = base_drag_asset != null ||
@@ -428,7 +428,7 @@ function base_update() {
 			base_drag_layer = null;
 		}
 
-		iron_set_mouse_cursor(0); // Arrow
+		iron_mouse_set_cursor(cursor_t.ARROW);
 		base_is_dragging = false;
 	}
 	if (context_raw.color_picker_callback != null && (mouse_released() || mouse_released("right"))) {
@@ -556,7 +556,7 @@ function base_render() {
 	context_raw.frame++;
 
 	if (base_is_dragging) {
-		iron_set_mouse_cursor(1); // Hand
+		iron_mouse_set_cursor(cursor_t.HAND);
 		let img: gpu_texture_t = base_get_drag_image();
 		let scale_factor: f32 = UI_SCALE();
 		let size: f32 = (base_drag_size == -1 ? 50 : base_drag_size) * scale_factor;

+ 9 - 1
base/sources/ts/iron/iron.ts

@@ -332,7 +332,7 @@ declare type draw_font_t = {
 };
 
 declare function iron_set_save_and_quit_callback(callback: (save: bool)=>void): void;
-declare function iron_set_mouse_cursor(id: i32): void;
+declare function iron_mouse_set_cursor(id: cursor_t): void;
 declare function iron_delay_idle_sleep(): void;
 declare function iron_open_dialog(filter_list: string, default_path: string, open_multiple: bool): string[];
 declare function iron_save_dialog(filter_list: string, default_path: string): string;
@@ -672,6 +672,14 @@ enum shader_type_t {
 	FRAGMENT,
 }
 
+enum cursor_t {
+	ARROW,
+	HAND,
+	IBEAM,
+	SIZEWE,
+	SIZENS,
+}
+
 declare let ui_nodes_enum_texts: (s: string)=>string[];
 declare let ui_touch_scroll: bool;
 declare let ui_touch_hold : bool;

+ 3 - 3
base/sources/ts/ui_base.ts

@@ -1509,8 +1509,8 @@ function ui_base_on_border_hover(handle: ui_handle_t, side: i32) {
 	}
 
 	side == border_side_t.LEFT || side == border_side_t.RIGHT ?
-		iron_set_mouse_cursor(3) : // Horizontal
-		iron_set_mouse_cursor(4);  // Vertical
+		iron_mouse_set_cursor(cursor_t.SIZEWE) :
+		iron_mouse_set_cursor(cursor_t.SIZENS);
 
 	if (ui.input_started) {
 		ui_base_border_started = side;
@@ -1520,7 +1520,7 @@ function ui_base_on_border_hover(handle: ui_handle_t, side: i32) {
 }
 
 function ui_base_on_text_hover() {
-	iron_set_mouse_cursor(2); // I-cursor
+	iron_mouse_set_cursor(cursor_t.IBEAM);
 }
 
 function ui_base_on_deselect_text() {

+ 3 - 3
base/tools/pad/sources/main.ts

@@ -185,7 +185,7 @@ function render() {
 	storage.window_x = iron_window_x();
 	storage.window_y = iron_window_y();
 	if (ui.input_dx != 0 || ui.input_dy != 0) {
-		iron_set_mouse_cursor(0); // Arrow
+		iron_mouse_set_cursor(cursor_t.ARROW);
 	}
 
 	ui_begin(ui);
@@ -365,7 +365,7 @@ function on_border_hover(handle: ui_handle_t, side: i32) {
 		return; // Right
 	}
 
-	iron_set_mouse_cursor(3); // Horizontal
+	iron_mouse_set_cursor(cursor_t.SIZEWE);
 
 	if (ui.input_started) {
 		resizing_sidebar = true;
@@ -373,7 +373,7 @@ function on_border_hover(handle: ui_handle_t, side: i32) {
 }
 
 function on_text_hover() {
-	iron_set_mouse_cursor(2); // I-cursor
+	iron_mouse_set_cursor(cursor_t.IBEAM);
 }
 
 ////