This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
functions:addons:rect [2016/08/16 21:18] – [RectIntersects] monsterovich | functions:addons:rect [2019/04/20 00:20] (current) – removed korshun | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Rectangle API ====== | ||
- | |||
- | This is a simple library that implements basic UI elements in ACS. This library is an **addon** for the [[functions: | ||
- | |||
- | <note tip> | ||
- | |||
- | Define '' | ||
- | |||
- | ===== Example ===== | ||
- | |||
- | This script implements two simple buttons. You also can move them by using the right mouse button. | ||
- | |||
- | < | ||
- | script 1 (void) net clientside | ||
- | { | ||
- | int rects; | ||
- | rects = RectCreate(0, | ||
- | rects = RectCreate(128.0, | ||
- | |||
- | while(true) | ||
- | { | ||
- | UpdateCursor(); | ||
- | HudSetPoint(CursorX(), | ||
- | HudDrawImage(1, | ||
- | |||
- | for (int i = 0; i <= rects; i++) | ||
- | { | ||
- | if (RectIsGrabbed(i, | ||
- | RectFollowCursor(i); | ||
- | if (RectIsPressed(i, | ||
- | log(s:" | ||
- | |||
- | HudSetPoint(RectX1(i), | ||
- | HudDrawText(2+(i*4), | ||
- | HudSetPoint(RectX2(i), | ||
- | HudDrawText(3+(i*4), | ||
- | HudSetPoint(RectX1(i), | ||
- | HudDrawText(4+(i*4), | ||
- | HudSetPoint(RectX2(i), | ||
- | HudDrawText(5+(i*4), | ||
- | } | ||
- | |||
- | delay(1); | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | ====== Functions ====== | ||
- | |||
- | ==== RectCreate ==== | ||
- | '' | ||
- | |||
- | Creates a rectangle on the stack with the given parameters. The result value is the rectangle' | ||
- | |||
- | ==== RectsDelete ==== | ||
- | '' | ||
- | |||
- | Deletes a group of rectangles from stack, //start// == 0 will delete all rectangles. Use non-zero values to delete the rectangles only from the top of the stack. | ||
- | |||
- | ===== Rectangle coordinates ===== | ||
- | |||
- | {{ : | ||
- | |||
- | |||
- | |||
- | ==== RectX1 ==== | ||
- | |||
- | '' | ||
- | |||
- | Returns the X coordinate of rectangle vertexes №1, №3. | ||
- | |||
- | ==== RectY1 ==== | ||
- | |||
- | '' | ||
- | |||
- | Returns the Y coordinate of rectangle vertexes №1, №2. | ||
- | |||
- | ==== RectX2 ==== | ||
- | |||
- | '' | ||
- | |||
- | Returns the X coordinate of rectangle vertexes №2, №4. | ||
- | |||
- | ==== RectY2 ==== | ||
- | |||
- | '' | ||
- | |||
- | Returns the Y coordinate of rectangle vertexes №3, №4. | ||
- | |||
- | ==== RectCenterX ==== | ||
- | |||
- | '' | ||
- | |||
- | Returns the X coordinate of the rectangle' | ||
- | |||
- | ==== RectCenterY ==== | ||
- | |||
- | '' | ||
- | |||
- | Returns the Y coordinate of the rectangle' | ||
- | |||
- | ==== SetRectPosition ==== | ||
- | '' | ||
- | |||
- | Sets the //X Y// of given rectangle. Rectangle position is its (X1; Y1) point. | ||
- | |||
- | ==== SetRectSize ==== | ||
- | '' | ||
- | |||
- | Changes the rectangle' | ||
- | |||
- | ==== RectWidth ==== | ||
- | '' | ||
- | |||
- | Returns the width of the given rectangle. | ||
- | |||
- | ==== RectHeight ==== | ||
- | '' | ||
- | |||
- | Returns the height of the given rectangle. | ||
- | |||
- | ==== RectFollowCursor ==== | ||
- | '' | ||
- | |||
- | Makes rect to follow mouse coordinates. | ||
- | |||
- | ==== RectIsPointInside ==== | ||
- | '' | ||
- | |||
- | Returns true if the rectangle contains the point with the coordinates //x y//, otherwise returns false. | ||
- | |||
- | ==== RectIntersects ==== | ||
- | '' | ||
- | |||
- | Returns true if the rectangle with id //rect// intersects with other rectangle with id //rect2//. | ||
- | |||
- | <note tip> | ||
- | |||
- | ===== User Data ===== | ||
- | |||
- | You may also create custom user-defined rectangle properties. | ||
- | Define **ACSUTILS_RECTLIB_USERVARS** to specify the amount of these properties. | ||
- | |||
- | ==== SetRectUserData ==== | ||
- | '' | ||
- | |||
- | Sets the value of the given custom property of the rectangle. | ||
- | ==== RectGetUserData ==== | ||
- | '' | ||
- | |||
- | Returns the value of the rectangle' | ||
- | |||
- | ==== Example ==== | ||
- | |||
- | A simple implementation of a checkbox button. | ||
- | |||
- | < | ||
- | #define ACSRECT_USER_CHECKED 0 | ||
- | |||
- | ... | ||
- | |||
- | int checker = RectCreate(0, | ||
- | |||
- | ... | ||
- | |||
- | while(true) | ||
- | { | ||
- | ... | ||
- | int checked = RectGetUserData(checker, | ||
- | if (RectIsClicked(checker, | ||
- | SetRectUserData(checker, | ||
- | ... | ||
- | |||
- | delay(1); | ||
- | } | ||
- | </ | ||
- | |||
- | ===== Rectangle action handlers ===== | ||
- | |||
- | ==== RectIsHovered ==== | ||
- | '' | ||
- | |||
- | Returns true if the mouse cursor is inside the rectangle. | ||
- | |||
- | ==== RectIsClicked ==== | ||
- | '' | ||
- | |||
- | Returns true if user clicked the rectangle once with //key//. | ||
- | |||
- | ==== RectIsDown ==== | ||
- | '' | ||
- | |||
- | Returns true if user is holding the //key// down and the mouse cursor is inside the rectangle. | ||
- | |||
- | ==== RectIsGrabbed ==== | ||
- | '' | ||
- | |||
- | This function is similar to // | ||
- | |||
- | ==== RectIsPressed ==== | ||
- | '' | ||
- | |||
- | This function is similar to // | ||
- | |||
- | * Returns true, if user released the //key// after clicking the rectangle. | ||
- | * Returns true, if cursor went outside the rectangle after the user had held down the //key//. | ||
- | |||
- | Otherwise, it return false. | ||
- | |||