Parcourir la source

Fix middle and right mouse button in js window

Karl Zylinski il y a 2 mois
Parent
commit
1fb259cdc8

+ 10 - 0
.sublime/karl2d.sublime-project

@@ -111,6 +111,16 @@
 					"shell_cmd": "odin run build_web_example -- raylib_ports/bunnymark",
 					"working_dir": "$project_path/../examples",
 				},
+				{
+					"name": "mouse",
+					"shell_cmd": "odin run . -vet -strict-style -keep-executable",
+					"working_dir": "$project_path/../examples/mouse",
+				},
+				{
+					"name": "mouse (web)",
+					"shell_cmd": "odin run build_web_example -- mouse",
+					"working_dir": "$project_path/../examples",
+				},
 				{
 					"name": "gamepad",
 					"shell_cmd": "odin run . -vet -strict-style -keep-executable",

+ 1 - 1
examples/build_web_example/web_entry_templates/index_template.html

@@ -5,7 +5,7 @@
 		<meta name="viewport" content="width=device-width, initial-scale=1">
 		<title>Karl2D Minimal</title>
 	</head>
-	<body id="body" style="height: 100%; padding: 0; margin: 0; overflow: hidden; background-color: black;">
+	<body id="body" style="height: 100%; padding: 0; margin: 0; overflow: hidden; background-color: black;" oncontextmenu="return false;">
 		<canvas id="webgl-canvas"></canvas>
 	
 		<script type="text/javascript" src="odin.js"></script>

+ 1 - 0
karl2d.odin

@@ -1396,6 +1396,7 @@ BLACK :: Color { 0, 0, 0, 255 }
 GRAY  :: Color { 127, 127, 127, 255 }
 RED   :: Color { 198, 40, 90, 255 }
 GREEN :: Color { 30, 240, 30, 255 }
+YELLOW :: Color {240, 190, 0, 255 }
 BLANK :: Color { 0, 0, 0, 0 }
 BLUE  :: Color { 30, 116, 240, 255 }
 

+ 22 - 2
window_js.odin

@@ -94,14 +94,34 @@ js_event_mouse_move :: proc(e: js.Event) {
 }
 
 js_event_mouse_down :: proc(e: js.Event) {
+	button := Mouse_Button.Left
+
+	if e.mouse.button == 2 {
+		button = .Right
+	}
+
+	if e.mouse.button == 1 {
+		button = .Middle 
+	}
+
 	append(&s.events, Window_Event_Mouse_Button_Went_Down {
-		button = .Left,
+		button = button,
 	})
 }
 
 js_event_mouse_up :: proc(e: js.Event) {
+	button := Mouse_Button.Left
+
+	if e.mouse.button == 2 {
+		button = .Right
+	}
+
+	if e.mouse.button == 1 {
+		button = .Middle 
+	}
+
 	append(&s.events, Window_Event_Mouse_Button_Went_Up {
-		button = .Left,
+		button = button,
 	})
 }