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 21:57] – [RectWidth] 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 128: Line 146:
 ''bool RectIsPointInside(int rect, fixed x, fixed y)'' ''bool RectIsPointInside(int rect, fixed x, fixed y)''
  
-Returns true if rectangle contains point with //x y// coordianteselse 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 138: Line 163:
 ''void SetRectUserData(int rect, int id, int value)'' ''void SetRectUserData(int rect, int id, int value)''
  
-Sets the value of custom property with //id// of given rectangle. +Sets the value of the given custom property of the rectangle.
 ==== RectGetUserData ==== ==== RectGetUserData ====
 ''int RectGetUserData(int rect, int id)'' ''int RectGetUserData(int rect, int id)''
  
-Returns the value of custom property with //id// of given rectangle.+Returns the value of the rectangle's given custom property.
  
 ==== Example ==== ==== Example ====
  
-A simple implementation of checkbox button.+A simple implementation of checkbox button.
  
 <code> <code>
Line 175: Line 199:
 ''bool RectIsHovered(int rect)'' ''bool RectIsHovered(int rect)''
  
-Returns true if rectangle contains mouse cursor.+Returns true if the mouse cursor is inside the rectangle.
  
 ==== RectIsClicked ==== ==== RectIsClicked ====
 ''bool RectIsClicked(int rect, int key)'' ''bool RectIsClicked(int rect, int key)''
  
-Returns true if user clicked rectangle once with //key//.+Returns true if user clicked the rectangle once with //key//.
  
 ==== RectIsDown ==== ==== RectIsDown ====
 ''bool RectIsDown(int rect, int key)'' ''bool RectIsDown(int rect, int key)''
  
-Returns true if user has the //key// down and rectangle contains mouse cursor.+Returns true if user is holding the //key// down and the mouse cursor is inside the rectangle.
  
 ==== RectIsGrabbed ==== ==== RectIsGrabbed ====
 ''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)''
  
-This function is similar to //RectIsClicked//, but unlike //RectIsClicked// it makes rectangle work like normal button:+This function is similar to //RectIsClicked//, but unlike //RectIsClicked// it makes the rectangle work like 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.