Windows manager
What is a window?A window is a graphic element having a background and borders, the first one is fully scaled to the size of the window, and the borders don't.

How it works?
The window will use 10 bitmaps, (A window id is the ten of the bitmap id) then you have to use a NPC graphic as a source.
The window graphic is organized like this:

Here's the template, the purple part is the window background, the yellow part is the border and the red part is the corner.

You can put as many window graphics as you want in one file, just put together vertically, the value to use one of those window graphics are called "winid"

The script (To past above all the ones)
Code: Select all
' o Create window
export script Window_create(id as double, picid as double, winid as double, useScreenCoords as double, isVisible as double, destx as double, desty as double, width as double, height as double, color as double, gap as double)
' o Fix incorrect values
winid = int(winid)
' o Erase all slots already taken to overwrite
call Window_erase(id)
' o Create window background
call bmpcreate(id*10, picid, useScreenCoords, isVisible, 0, 0+64*winid, 64, 64, destx+gap, desty+gap, 1/64*(width-gap*2), 1/64*(height-gap*2), 0, 0, 0, color)
' o Create up left border
call bmpcreate(id*10+1, picid, useScreenCoords, isVisible, 64, 0+64*winid, 16, 16, destx, desty, 1, 1, 0, 0, 0, -1)
' o Create up border
call bmpcreate(id*10+2, picid, useScreenCoords, isVisible, 80, 0+64*winid, 32, 16, destx+16, desty, 1/32*(width-32), 1, 0, 0, 0, -1)
' o Create up right border
call bmpcreate(id*10+3, picid, useScreenCoords, isVisible, 112, 0+64*winid, 16, 16, destx+width-16, desty, 1, 1, 0, 0, 0, -1)
' o Create right border
call bmpcreate(id*10+4, picid, useScreenCoords, isVisible, 112, 16+64*winid, 16, 32, destx+width-16, desty+16, 1, 1/32*(height-32), 0, 0, 0, -1)
' o Create down right border
call bmpcreate(id*10+5, picid, useScreenCoords, isVisible, 112, 48+64*winid, 16, 16, destx+width-16, desty+height-16, 1, 1, 0, 0, 0, -1)
' o Create down border
call bmpcreate(id*10+6, picid, useScreenCoords, isVisible, 80, 48+64*winid, 32, 16, destx+16, desty+height-16, 1/32*(width-32), 1, 0, 0, 0, -1)
' o Create down left border
call bmpcreate(id*10+7, picid, useScreenCoords, isVisible, 64, 48+64*winid, 16, 16, destx, desty+height-16, 1, 1, 0, 0, 0, -1)
' o Create left border
call bmpcreate(id*10+8, picid, useScreenCoords, isVisible, 64, 16+64*winid, 16, 32, destx, desty+16, 1, 1/32*(height-32), 0, 0, 0, -1)
' o Create an invisible bitmap to stock some informations
call bmpcreate(id*10+9, picid, useScreenCoords, isVisible, gap, 1, width, height, 1, 1, 1, 1.0, 0, 0, 0, 0)
' * sx/scrx = gap
' * scrwidth = width
' * scrheight = height
' * sy/scry = used for loop function
end script
' o Erase window
export script Window_erase(id as double)
for bitmap(id*10+9).scry = id*10 to id*10+9
call BErase(2, bitmap(id*10+9).scry)
next
end script
' o Set window infos
export script Set_Window_X(id as double, xpos as double)
' o Move window background
bitmap(id*10).destx = xpos+bitmap(id*10+9).scrx
' o Move up left border
bitmap(id*10+1).destx = xpos
' o Move up border
bitmap(id*10+2).destx = xpos+16
' o Move up right border
bitmap(id*10+3).destx = xpos+bitmap(id*10+9).scrwidth-16
' o Move right and right down border
bitmap(id*10+4).destx = bitmap(id*10+3).destx
bitmap(id*10+5).destx = bitmap(id*10+3).destx
' o Move down border
bitmap(id*10+6).destx = bitmap(id*10+2).destx
' o Move down left border
bitmap(id*10+7).destx = bitmap(id*10+1).destx
' o Move left border
bitmap(id*10+8).destx = bitmap(id*10+1).destx
end script
export script Set_Window_Y(id as double, ypos as double)
' o Move window background
bitmap(id*10).desty = ypos+bitmap(id*10+9).scrx
' o Move up left border
bitmap(id*10+1).desty = ypos
' o Move up border
bitmap(id*10+2).desty = bitmap(id*10+1).desty
' o Move up right border
bitmap(id*10+3).desty = bitmap(id*10+1).desty
' o Move right border
bitmap(id*10+4).desty = ypos+16
' o Move right down border
bitmap(id*10+5).desty = Ypos+bitmap(id*10+9).scrheight-16
' o Move down border
bitmap(id*10+6).desty = bitmap(id*10+5).desty
' o Move down left border
bitmap(id*10+7).desty = bitmap(id*10+5).desty
' o Move left border
bitmap(id*10+8).desty = bitmap(id*10+4).desty
end script
export script Set_Window_pos(id as double, xpos as double, ypos as double)
call Set_Window_X(id, xpos)
call Set_Window_Y(id, ypos)
end script
export script Set_Window_width(id as double, width as double)
' o Change window background width
bitmap(id*10).scalex = 1/64*(width-bitmap(id*10+9).scrx*2)
' o Change up border
bitmap(id*10+2).scalex = 1/32*(width-32)
' o Change up right border
bitmap(id*10+3).destx = bitmap(id*10+1).destx+width-16
' o Change right border
bitmap(id*10+4).destx = bitmap(id*10+3).destx
' o Change down right border
bitmap(id*10+5).destx = bitmap(id*10+3).destx
' o Change down border
bitmap(id*10+6).scalex = bitmap(id*10+2).scalex
' o Set width info
bitmap(id*10+9).scrwidth = width
end script
export script Set_Window_height(id as double, height as double)
' o Change window background width
bitmap(id*10).scaley = 1/64*(height-bitmap(id*10+9).scrx*2)
' o Change right border
bitmap(id*10+4).scaley = 1/32*(height-32)
' o Change right down border
bitmap(id*10+5).desty = bitmap(id*10+3).desty+height-16
' o Change down border
bitmap(id*10+6).desty = bitmap(id*10+5).desty
' o Change down left border
bitmap(id*10+7).desty = bitmap(id*10+5).desty
' o Change left border
bitmap(id*10+8).scaley = bitmap(id*10+4).scaley
' o Set width info
bitmap(id*10+9).scrheight = height
end script
export script Set_Window_size(id as double, width as double, height as double)
call Set_Window_width(id, width)
call Set_Window_height(id, height)
end script
export script Set_Window_hide(id as double, hid as double)
for bitmap(id*10+9).scry = id*10 to id*10+8
bitmap(bitmap(id*10+9).scry)).hide = hid
next
end script
export script Set_Window_Zpos(id as double, z as double)
for bitmap(id*10+9).scry = id*10 to id*10+8
bitmap(bitmap(id*10+9).scry)).zpos = z
next
end script
export script Set_Window_color(id as double, color as string, value as double)
select case color
case "c"
bitmap(id*10).color = value
case "r"
bitmap(id*10).forecolor_r = value
case "g"
bitmap(id*10).forecolor_g = value
case "b"
bitmap(id*10).forecolor_b = value
case "a"
bitmap(id*10).forecolor_a = value
end select
end script
export script Set_Window_border_color(id as double, color as string, value as double)
select case color
case "c"
for bitmap(id*10+9).scry = id*10+1 to id*10+8
bitmap(bitmap(id*10+9).scry)).color = value
next
case "r"
for bitmap(id*10+9).scry = id*10+1 to id*10+8
bitmap(bitmap(id*10+9).scry)).forecolor_r = value
next
case "g"
for bitmap(id*10+9).scry = id*10+1 to id*10+8
bitmap(bitmap(id*10+9).scry)).forecolor_g = value
next
case "b"
for bitmap(id*10+9).scry = id*10+1 to id*10+8
bitmap(bitmap(id*10+9).scry)).forecolor_b = value
next
case "a"
for bitmap(id*10+9).scry = id*10+1 to id*10+8
bitmap(bitmap(id*10+9).scry)).forecolor_a = value
next
end select
end script
export script Set_Window_blend(id as double, value as double)
bitmap(id*10).Blendmode = value
end script
export script Set_Window_border_blend(id as double, value as double)
for bitmap(id*10+9).scry = id*10+1 to id*10+8
bitmap(bitmap(id*10+9).scry)).Blendmode = value
next
end script
export script Set_Window_attscreen(id as double, value as double)
for bitmap(id*10+9).scry = id*10 to id*10+8
bitmap(bitmap(id*10+9).scry)).attscreen = value
next
end script
export script Set_Window_npcid(id as double, value as double)
for bitmap(id*10+9).scry = id*10 to id*10+8
bitmap(bitmap(id*10+9).scry)).scrid = value
next
end script
export script Set_Window_winid(id as double, winid as double)
' o Change background
bitmap(id*10).scry = winid*64
' o Change up left border
bitmap(id*10+1).scry = 0+64*winid
' o Change up border
bitmap(id*10+2).scry = 0+64*winid
' o Change up right border
bitmap(id*10+3).scry = 0+64*winid
' o Change right border
bitmap(id*10+4).scry = 16+64*winid
' o Change down right border
bitmap(id*10+5).scry = 48+64*winid
' o Change down border
bitmap(id*10+6).scry = 48+64*winid
' o Change down left border
bitmap(id*10+7).scry = 48+64*winid
' o Change left border
bitmap(id*10+8).scry = 16+64*winid
end script
export script Set_Window_gap(id as double, value as double)
bitmap(id*10).destx = bitmap(id*10+1).destx + value
bitmap(id*10).desty = bitmap(id*10+1).desty + value
bitmap(id*10).scalex = 1/64*(bitmap(id*10+9).scrwidth - value*2)
bitmap(id*10).scaley = 1/64*(bitmap(id*10+9).scrheight - value*2)
bitmap(id*10+9).scrx = value
end script
' o Get window infos
export script Window_X(id as double, return double) return bitmap(id*10+1).destx end
export script Window_Y(id as double, return double) return bitmap(id*10+1).desty end
export script Window_width(id as double, return double) return (bitmap(id*10+3).destx-bitmap(id*10+1).destx+bitmap(id*10+1).scrwidth) end
export script Window_height(id as double, return double) return (bitmap(id*10+7).desty-bitmap(id*10+1).desty+bitmap(id*10+1).scrheight) end
export script Window_hide(id as double, return double) return bitmap(id*10).hide end
export script Window_Zpos(id as double, return double) return bitmap(id*10).Zpos end
export script Window_color(id as double, return double) return bitmap(id*10).color end
export script Window_border_color(id as double, return double) return bitmap(id*10+1).color end
export script Window_Blendmode(id as double, return double) return bitmap(id*10).Blendmode end
export script Window_border_Blendmode(id as double, return double) return bitmap(id*10+1).Blendmode end
export script Window_attscreen(id as double, return double) return bitmap(id*10).attscreen end
export script Window_winid(id as double, return double) return int(bitmap(id*10).scry/64) end
export script Window_npcid(id as double, return double) return bitmap(id*10).scrid end
export script Window_forecolor_r(id as double, return double) return bitmap(id*10).forecolor_r end
export script Window_forecolor_g(id as double, return double) return bitmap(id*10).forecolor_g end
export script Window_forecolor_b(id as double, return double) return bitmap(id*10).forecolor_b end
export script Window_forecolor_a(id as double, return double) return bitmap(id*10).forecolor_a end
export script Window_border_forecolor_r(id as double, return double) return bitmap(id*10+1).forecolor_r end
export script Window_border_forecolor_g(id as double, return double) return bitmap(id*10+1).forecolor_g end
export script Window_border_forecolor_b(id as double, return double) return bitmap(id*10+1).forecolor_b end
export script Window_border_forecolor_a(id as double, return double) return bitmap(id*10+1).forecolor_a end
export script Window_gap(id as double, return double) return bitmap(id*10+9).scrx end
export script Window_debug(id as double)
call Debug("____WINDOW "&id&" INFO____")
call Debug("* POSITION X: "&Window_X(id)&" Y: "&Window_Y(id))
call Debug("* POSITION Z: "&Window_Zpos(id))
call Debug("* SIZE W: "&Window_width(id)&" H: "&Window_height(id))
call Debug("* COLOR R: "&window_forecolor_r(id)&" G: "&window_forecolor_g(id)&" B: "&window_forecolor_b(id)&" A: "&window_forecolor_a(id))
call Debug("* COLOR C: "&Window_color(id)&" BLENDMODE: "&Window_Blendmode(id))
call Debug("* COLOR B R: "&window_border_forecolor_r(id)&" G: "&window_border_forecolor_g(id)&" B: "&window_border_forecolor_b(id)&" A: "&window_border_forecolor_a(id))
call Debug("* COLOR B C: "&Window_border_color(id)&" BLENDMODE B: "&Window_border_Blendmode(id))
call Debug("* NPCID: "&window_npcid(id)&" WINID: "&window_winid(id))
call Debug("* ATTSCREEN: "&Window_attscreen(id)&" HIDE: "&Window_hide(id)&" GAP: "&window_gap(id))
call Debug("______________________")
end script