- Joined
- Mar 18, 2012
- Messages
- 1,716
UIBorder
Creates borders, including a background image for full screen systems.
JASS:
library UIBorder uses UIBasic/* v 1.0
**************************************************************
*
* Creates borders, including a background image for full screen systems.
*
**************************************************************
*/
globals
private boolean INCLUDED = UI_BORDER_INCLUDED_IN_RECT
private real WIDTH = UI_BORDER_WIDTH
private string BACKGROUND = UI_BORDER_BACKGROUND
private string LEFT = UI_BORDER_LEFT
private string RIGHT = UI_BORDER_RIGHT
private string TOP = UI_BORDER_TOP
private string BOTTOM = UI_BORDER_BOTTOM
private string BOTTOM_LEFT = UI_BORDER_BOTTOM_LEFT
private string BOTTOM_RIGHT = UI_BORDER_BOTTOM_RIGHT
private string TOP_LEFT = UI_BORDER_TOP_LEFT
private string TOP_RIGHT = UI_BORDER_TOP_RIGHT
private integer BACKGROUND_RED = UI_BORDER_BACKGOUND_RED
private integer BACKGROUND_GREEN = UI_BORDER_BACKGOUND_GREEN
private integer BACKGROUND_BLUE = UI_BORDER_BACKGOUND_BLUE
private integer BACKGROUND_ALPHA = UI_BORDER_BACKGOUND_ALPHA
private integer IMAGE_TYPE = UI_BORDER_IMAGE_TYPE
endglobals
private function Reset takes nothing returns nothing
set UI_BORDER_INCLUDED_IN_RECT = INCLUDED
set UI_BORDER_BACKGROUND = BACKGROUND
set UI_BORDER_WIDTH = WIDTH
set UI_BORDER_LEFT = LEFT
set UI_BORDER_RIGHT = RIGHT
set UI_BORDER_TOP = TOP
set UI_BORDER_BOTTOM = BOTTOM
set UI_BORDER_BOTTOM_LEFT = BOTTOM_LEFT
set UI_BORDER_BOTTOM_RIGHT = BOTTOM_RIGHT
set UI_BORDER_TOP_LEFT = TOP_LEFT
set UI_BORDER_TOP_RIGHT = TOP_RIGHT
set UI_BORDER_BACKGOUND_RED = BACKGROUND_RED
set UI_BORDER_BACKGOUND_GREEN = BACKGROUND_GREEN
set UI_BORDER_BACKGOUND_BLUE = BACKGROUND_BLUE
set UI_BORDER_BACKGOUND_ALPHA = BACKGROUND_ALPHA
set UI_BORDER_IMAGE_TYPE = IMAGE_TYPE
endfunction
globals
private constant integer OFFSET = 0x186A0//* 100000
private constant real RATIO = (UI_TILE_SIZE + 2.)/UI_TILE_SIZE
endglobals
struct UIBorder
private Table stack
private method operator sizeDest= takes integer value returns nothing
set stack[-2] = value
endmethod
public method operator sizeDest takes nothing returns integer
return stack[-2]
endmethod
private method operator size= takes integer value returns nothing
set stack[-1] = value
endmethod
public method operator size takes nothing returns integer
return stack[-1]
endmethod
method destroy takes nothing returns nothing
local integer i = 0
local integer max = size
loop
exitwhen i == max
call ReleaseImage(stack.image[i])
set i = i + 1
endloop
/*set i = OFFSET
set max = sizeDest + OFFSET
loop
exitwhen i == max
call RemoveDestructable(stack.destructable[i])
set i = i + 1
endloop*/
call stack.destroy()
call deallocate()
endmethod
//* Use GetLocalPlayer or IsPlayerInForce.
method show takes boolean show returns nothing
local integer i = 0
local integer max = size
loop
exitwhen i == max
call ShowImage(stack.image[i], show)
call SetImageRenderAlways(stack.image[i], show)
set i = i + 1
endloop
endmethod
//* Image type API:
//* ===============
method addImage takes string file, real sizeX, real sizeY, real posX, real posY, integer imageType returns image
set stack.image[size] = NewImage(file, sizeX, sizeY, posX, posY, 0, imageType)
set size = size + 1
return stack.image[size - 1]
endmethod
// Custom Window by Maker:
// - [url]https://www.hiveworkshop.com/forums/spells-569/customwindow-v1-1-1-2-a-207526/?prev=search%3Dwindow%26d%3Dlist%26r%3D20[/url]
method construct takes real centerX, real centerY, real sizeX, real sizeY, real borderScale returns thistype
//! textmacro UI_WINDOW_BORDER_NEW takes MODEL, SIZEX, SIZEY, CENTERX, CENTERY
if (UI_BORDER_$MODEL$ != "") then
set stack.image[index] = NewImage(UI_BORDER_$MODEL$, $SIZEX$, $SIZEY$, $CENTERX$, $CENTERY$, 0, UI_BORDER_IMAGE_TYPE)
set index = index + 1
endif
//! endtextmacro
local integer index = size
local integer i = 0
local integer nx = 0 // x pieces
local integer ny = 0 // y pieces
local real sx = 0
local real sy = 0
local real cx = 0
local real cy = 0
local real sxa = 0
local real sya = 0
local real bwidth = UI_BORDER_WIDTH*borderScale
local real x = UI_TILE_SIZE*borderScale
local real y = UI_TILE_SIZE*borderScale
if not UI_BORDER_INCLUDED_IN_RECT then
set sizeX = sizeX + bwidth*2
set sizeY = sizeY + bwidth*2
endif
if (sizeX < 2*x) then
set sizeX = 2*x
endif
set sx = x*RATIO
set nx = R2I((sizeX - 2*x)/x)
if (nx == 0) and (((sizeX - 2*x)/x) != 0.) then
set nx = 1
endif
if (nx != 0) then
set sxa = (sizeX - 2*x)/(nx*x)*sx
else
set sxa = 1
endif
set cx = centerX - sizeX/2 + x - borderScale
if (sizeY < 2*y) then
set sizeY = 2*y
endif
set sy = y*RATIO
set ny = R2I((sizeY - 2*y)/y)
if (ny == 0) and (((sizeY - 2*y)/y) != 0.) then
set ny = 1
endif
if (ny != 0) then
set sya = (sizeY - 2*x)/(ny*x)*sy
else
set sya = 1
endif
set cy = centerY - sizeY/2 + y - borderScale
// 1. Background image
if (UI_BORDER_BACKGROUND != "") and (UI_BORDER_BACKGROUND != null) then
set stack.image[index] = NewImage(UI_BORDER_BACKGROUND, sizeX - bwidth, sizeY - bwidth, centerX - (sizeX - bwidth)*.5, centerY - (sizeY - bwidth)*.5, 0, IMAGE_TYPE_INDICATOR)
call SetImageColor(stack.image[index], UI_BORDER_BACKGOUND_RED, UI_BORDER_BACKGOUND_GREEN, UI_BORDER_BACKGOUND_BLUE, UI_BORDER_BACKGOUND_ALPHA)
set index = index + 1
endif
set centerX = centerX - borderScale
set centerY = centerY - borderScale
// 2. Corner images.
//! runtextmacro UI_WINDOW_BORDER_NEW("BOTTOM_LEFT", "sx", "sy", "centerX - sizeX*0.5", "centerY - sizeY*0.5")
//! runtextmacro UI_WINDOW_BORDER_NEW("TOP_LEFT", "sx", "sy", "centerX - sizeX*0.5", "centerY + sizeY*0.5 - sy/RATIO")
//! runtextmacro UI_WINDOW_BORDER_NEW("TOP_RIGHT", "sx", "sy", "centerX + sizeX*0.5 - x", "centerY + sizeY*0.5 - sy/RATIO")
//! runtextmacro UI_WINDOW_BORDER_NEW("BOTTOM_RIGHT", "sx", "sy", "centerX + sizeX*0.5 - x", "centerY - sizeY*0.5")
// 3. Upwards and downwards.
set i = 0
loop
exitwhen i == nx
//! runtextmacro UI_WINDOW_BORDER_NEW("TOP", "sxa", "sy", "cx", "centerY + sizeY*0.5 - y")
//! runtextmacro UI_WINDOW_BORDER_NEW("BOTTOM", "sxa", "sy", "cx", "centerY - sizeY*0.5")
set cx = cx + sxa/RATIO
set i = i + 1
endloop
// 4. Left and right
set i = 0
loop
exitwhen i == ny
//! runtextmacro UI_WINDOW_BORDER_NEW("LEFT", "sx", "sya", "centerX - sizeX*0.5", "cy")
//! runtextmacro UI_WINDOW_BORDER_NEW("RIGHT", "sx", "sya", "centerX + sizeX*0.5 - x", "cy")
set cy = cy + sya/RATIO
set i = i + 1
endloop
set size = index
call Reset()
return this
endmethod
method constructRect takes rect r, real borderScale returns thistype
return construct(GetRectCenterX(r), GetRectCenterY(r), GetRectMaxX(r) - GetRectMinX(r), GetRectMaxY(r) - GetRectMinY(r), borderScale)
endmethod
static method create takes nothing returns thistype
local thistype this = thistype.allocate()
set stack = Table.create()
set size = 0
return this
endmethod
//* Destructable type API:
//* ======================
//* Not yet coded.
method addDest takes integer destId, real x, real y, real z, real face, real scale returns destructable
set stack.destructable[sizeDest + OFFSET] = CreateDestructableZ(destId, x, y, z, face, scale, 0)
set sizeDest = sizeDest + 1
return stack.destructable[sizeDest + OFFSET - 1]
endmethod
method constructDest takes real originX, real originY, real width, real height, real borderScale returns thistype
debug call ThrowWarning(true, "UIBorder", "constructDest", "-", this, "This method is not yet coded in this version of UIPackage!")
return this
endmethod
method constructRectDest takes rect r, real borderScale returns thistype
return constructDest(GetRectMinX(r), GetRectMinY(r), GetRectMaxX(r) - GetRectMinX(r), GetRectMaxY(r) - GetRectMinY(r), borderScale)
endmethod
endstruct
endlibrary
Last edited:

