ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


new:mouse

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revisionBoth sides next revision
new:mouse [2018/02/15 16:33] – created korshunnew:mouse [2018/02/17 14:16] korshun
Line 1: Line 1:
 ====== Mouse cursor library ====== ====== Mouse cursor library ======
  
-The ACSUtils mouse cursor library is very easy to use:+ACSUtils provides a mouse cursor library, which lets you easily add mouse support to any interface in your mod. It is very easy to use:
  
 <code> <code>
Line 15: Line 15:
 ''UpdateCursor()'' reads player input and uses it to move the cursor, while taking many mouse setting cvars into account to make sure the cursor is not affected by first person mouse settings. ''CursorX()'' and ''CursorY()'' return the coordinates in the cursor in the [[HUD_coordinate_system]] (default size is 640x480). ''UpdateCursor()'' reads player input and uses it to move the cursor, while taking many mouse setting cvars into account to make sure the cursor is not affected by first person mouse settings. ''CursorX()'' and ''CursorY()'' return the coordinates in the cursor in the [[HUD_coordinate_system]] (default size is 640x480).
  
-The cursor library **does not** draw the cursor. This is to give you freedom to draw it any way you want, using the coordinates provided by ''CursorX()'' and ''CursorY()''.+**The cursor library does not draw the cursor.** This is to give you freedom to draw it any way you want, using the coordinates provided by ''CursorX()'' and ''CursorY()''.
  
 The cursor library fully supports widescreen thanks to ACSUtils [[Widescreeen|widescreen support functions]]. The cursor library fully supports widescreen thanks to ACSUtils [[Widescreeen|widescreen support functions]].
 +
 +The cursor library doesn't handle mouse clicks, as ZDoom doesn't provide access to mouse buttons. To read mouse clicks, use [[zdoom>GetPlayerInput]] with ''BT_ATTACK'' (left mouse button) and ''BT_ALTATTACK'' (right mouse button). Better yet, use ACSUtils [[input|GetPlayerInput wrappers]] for simpler input handling that will not register multiple clicks if the player holds a mouse button.
 +
 +To check if a button is clicked on screen, check that the cursor is inside the button's rectangle and was clicked.
  
 <note important>The cursor library **cannot be used serverside**. <note important>The cursor library **cannot be used serverside**.
Line 25: Line 29:
 ===== A complete example ===== ===== A complete example =====
  
-An example using [[HudMessage]]:+An example using [[HudMessage]] (''[[rounding|floor()]]'' is used to clear alignment flags):
  
 <code> <code>
-SetCursorArea(640.0, 480.0); // OPTIONAL: Sets cursor coordinate system, this is the default+// OPTIONAL: Sets cursor coordinate system 
 +// 640x480 is already the default. 
 +SetCursorArea(640.0, 480.0);  
 + 
 +// Main loop
 while (true) while (true)
 { {
Line 47: Line 55:
     UpdateCursor();     UpdateCursor();
          
-    HudResetState();+    HudResetState(); // Sets 640x480 coordinate system by default
     HudSetPoint(CursorX(), CursorY());     HudSetPoint(CursorX(), CursorY());
     HudDrawImage(1, "CURSOR");     HudDrawImage(1, "CURSOR");
Line 56: Line 64:
 ===== Moving the cursor ===== ===== Moving the cursor =====
  
-==== SetCursorPosition ==== +  * ''void SetCursorPosition(fixed x, fixed y)'' -- Teleports the cursor to the new position. 
- +  ''void CenterCursor()'' -- Teleports the cursor to the center of the screen. 
-''void SetCursorPosition(fixed x, fixed y)'' +
- +
-Teleports the cursor to new position. +
- +
-==== CenterCursor ==== +
- +
-''void CenterCursor()'' +
- +
-Teleports the cursor to the center of the screen.  +
  
 ===== Cursor settings ===== ===== Cursor settings =====
Line 77: Line 75:
 SetCursorSpeed(2.0); // Cursor is twice more sensitive SetCursorSpeed(2.0); // Cursor is twice more sensitive
 EnableCursorWrap(true); // Teleport the cursor to the opposite end of the screen if it reaches one end EnableCursorWrap(true); // Teleport the cursor to the opposite end of the screen if it reaches one end
 +
 while (true) while (true)
 { {
new/mouse.txt · Last modified: 2018/02/19 13:04 by korshun