ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


functions:addons:rect

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
functions:addons:rect [2016/08/09 22:05] korshunfunctions:addons:rect [2017/07/13 18:42] monsterovich
Line 1: Line 1:
 ====== Rectangle API ====== ====== Rectangle API ======
  
-This is a simple library that implements basic UI elements in ACS. This library is an **addon** for the [[functions:cursor|cursor]] library.+This is a simple library that implements basic UI elements in ACS. This library is an **addon** for the cursor library.
  
-<note tip>**ACSRect** is not bundled with official ACSUtils. You can download it [[https://github.com/Monsterovich/acsutils/archive/acsrect.zip|here]].</note>+<note tip>**ACSRect** is not bundled with official ACSUtils. You can download it [[https://gist.github.com/Monsterovich/33578899cf10790ce7f957f9be4a9de1|here]].</note>
  
 Define ''ACSUTILS_RECTLIB_SAVEDSTATES'' to specify the amount of required rectangles. Define ''ACSUTILS_RECTLIB_SAVEDSTATES'' to specify the amount of required rectangles.
 +
 +===== Usage =====
 +
 +<code>
 +...
 +
 +#define ACSUTILS_RECTLIB_USERVARS 1 // user defined
 +#include "acsutils.acs"
 +#include "acsrect.acs"
 +
 +...
 +</code>
  
 ===== Example ===== ===== Example =====
Line 22: Line 34:
         UpdateCursor();         UpdateCursor();
         HudSetPoint(CursorX(), CursorY());         HudSetPoint(CursorX(), CursorY());
-        HudDrawImage(1, "CURSA0");+        HudDrawText(1, "+");
   
  for (int i = 0; i <= rects; i++)  for (int i = 0; i <= rects; i++)
Line 30: Line 42:
  if (RectIsPressed(i, BT_ATTACK))  if (RectIsPressed(i, BT_ATTACK))
  log(s:"pressed");  log(s:"pressed");
 +
 + for (int j = 0; j <= rects; j++)
 + {
 + if (RectIntersects(i, j))
 + log(s:"rect ", d:i, s:" intersects with ", d:j);
 + }
   
  HudSetPoint(RectX1(i), RectX2(i));  HudSetPoint(RectX1(i), RectX2(i));
Line 129: Line 147:
  
 Returns true if the rectangle contains the point with the coordinates //x y//, otherwise returns false. Returns true if the rectangle contains the point with the coordinates //x y//, otherwise returns false.
 +
 +==== RectIntersects ==== 
 +''bool RectIntersects(int rect, int rect2)''
 +
 +Returns true if the rectangle with id //rect// intersects with other rectangle with id //rect2//.
 +
 +<note tip>Rectangle can't intersect with itself. So, if rect == rect2, this function returns //false//.</note>
  
 ===== User Data ===== ===== User Data =====
Line 189: Line 214:
 ''bool RectIsGrabbed(int rect, int key)'' ''bool RectIsGrabbed(int rect, int key)''
  
-This function is similar to //RectIsDown//, but optimized for rectangle moving. +This function is similar to //RectIsDown//, but optimized for rectangle moving, because it saves the focus until user released the key.
 ==== RectIsPressed ==== ==== RectIsPressed ====
 ''bool RectIsPressed(int rect, int key)'' ''bool RectIsPressed(int rect, int key)''
Line 196: Line 220:
 This function is similar to //RectIsClicked//, but unlike //RectIsClicked// it makes the rectangle work like a normal button: This function is similar to //RectIsClicked//, but unlike //RectIsClicked// it makes the rectangle work like a normal button:
  
-  * Returns true, if user up the //key// after he clicked rectangle. +  * Returns true, if user released the //key// after clicking the rectangle. 
-  * Returns true, if cursor has gone out of rectangle after user hold the //key//.+  * Returns true, if cursor went outside the rectangle after the user had held down the //key//.
  
 Otherwise, it return false. Otherwise, it return false.