mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-24 05:10:42 -04:00
Start porting MouseDevice to C.
This commit is contained in:
parent
99ca17407d
commit
39c1fb563c
@ -213,6 +213,7 @@
|
||||
<ClInclude Include="ModelBuilder.h" />
|
||||
<ClInclude Include="ModelCache.h" />
|
||||
<ClInclude Include="Key.h" />
|
||||
<ClInclude Include="Mouse.h" />
|
||||
<ClInclude Include="NetworkEnums.h" />
|
||||
<ClInclude Include="NormalBuilder.h" />
|
||||
<ClInclude Include="Options.h" />
|
||||
@ -291,6 +292,7 @@
|
||||
<ClCompile Include="MapRenderer.c" />
|
||||
<ClCompile Include="ModelBuilder.c" />
|
||||
<ClCompile Include="ModelCache.c" />
|
||||
<ClCompile Include="Mouse.c" />
|
||||
<ClCompile Include="NormalBuilder.c" />
|
||||
<ClCompile Include="PackedCol.c" />
|
||||
<ClCompile Include="Funcs.c" />
|
||||
|
@ -411,6 +411,9 @@
|
||||
<ClInclude Include="Window.h">
|
||||
<Filter>Header Files\Platform\Window</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Mouse.h">
|
||||
<Filter>Header Files\Platform\Window</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="NotchyGenerator.c">
|
||||
@ -629,5 +632,8 @@
|
||||
<ClCompile Include="Key.c">
|
||||
<Filter>Source Files\Platform\Window</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Mouse.c">
|
||||
<Filter>Source Files\Platform\Window</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -72,7 +72,6 @@ typedef enum Key_ {
|
||||
Key_Tilde, Key_Minus, Key_Plus, Key_BracketLeft, Key_BracketRight,
|
||||
Key_Semicolon, Key_Quote, Key_Comma, Key_Period, Key_Slash, Key_BackSlash,
|
||||
|
||||
/* Last available keyboard key */
|
||||
Key_Count,
|
||||
} Key;
|
||||
|
||||
|
27
src/Client/Mouse.c
Normal file
27
src/Client/Mouse.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include "Mouse.h"
|
||||
#include "Events.h"
|
||||
|
||||
bool MouseButton_States[MouseButton_Count];
|
||||
bool Mouse_GetPressed(MouseButton btn) { return MouseButton_States[btn]; }
|
||||
|
||||
void Mouse_SetPressed(MouseButton btn, bool pressed) {
|
||||
if (MouseButton_States[btn] != pressed) {
|
||||
MouseButton_States[btn] = pressed;
|
||||
|
||||
if (pressed) {
|
||||
Event_RaiseInt32(&KeyEvents_KeyDown, key);
|
||||
} else {
|
||||
Event_RaiseInt32(&KeyEvents_KeyUp, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Mouse_SetWheel(Real32 wheel) {
|
||||
Mouse_Wheel = wheel;
|
||||
Event_RaiseInt32(&KeyEvents_KeyUp, key);
|
||||
}
|
||||
|
||||
void Mouse_SetPosition(Int32 x, Int32 y) {
|
||||
Mouse_X = x; Mouse_Y = y;
|
||||
Event_RaiseInt32(&KeyEvents_KeyUp, key);
|
||||
}
|
62
src/Client/Mouse.h
Normal file
62
src/Client/Mouse.h
Normal file
@ -0,0 +1,62 @@
|
||||
#ifndef CS_MOUSE_H
|
||||
#define CS_MOUSE_H
|
||||
#include "Typedefs.h"
|
||||
/* Manages the mouse, and raises events when mouse buttons are pressed, moved, wheel scrolled, etc.
|
||||
Copyright 2017 ClassicalSharp | Licensed under BSD-3 | Based on OpenTK code
|
||||
*/
|
||||
|
||||
/*
|
||||
The Open Toolkit Library License
|
||||
|
||||
Copyright (c) 2006 - 2009 the Open Toolkit library.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
typedef enum MouseButton_ {
|
||||
/* The left mouse button. */
|
||||
MouseButton_Left,
|
||||
/* The right mouse button. */
|
||||
MouseButton_Right,
|
||||
/* The middle mouse button. */
|
||||
MouseButton_Middle,
|
||||
/* The first extra mouse button. */
|
||||
MouseButton_Button1,
|
||||
/* The second extra mouse button. */
|
||||
MouseButton_Button2,
|
||||
|
||||
MouseButton_Count,
|
||||
} MouseButton;
|
||||
|
||||
/* Gets whether the given mouse button is currently being pressed. */
|
||||
bool Mouse_GetPressed(MouseButton btn);
|
||||
/* Sets whether the given mouse button is currently being pressed. */
|
||||
void Mouse_SetPressed(MouseButton btn, bool pressed);
|
||||
|
||||
/* Gets the current wheel value of the mouse. */
|
||||
Real32 Mouse_Wheel;
|
||||
/* Gets the current position of the mouse. */
|
||||
Int32 Mouse_X, Mouse_Y;
|
||||
|
||||
/* Sets the current wheel value of the mouse. */
|
||||
void Mouse_SetWheel(Real32 wheel);
|
||||
/* Sets the current position of the mouse. */
|
||||
void Mouse_SetPosition(Int32 x, Int32 y);
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user