GimelBot/src/Scripts/Scrollbars/scrollbar_draw_ext.gml

90 lines
5.1 KiB
Plaintext

/*
CALL: scrollbar_draw_ext(id,x,y,slotw/h,slots,maxslots)
INFO: Draws the selected scrollbar. The value is measured in slots.
ARGUMENTS: id = The ID of the scrollbar to draw.
x = The x starting position of the scrollbar.
y = The y starting position of the scrollbar.
slotw/h = The width or height of a slot.
slots = The number of slots to show.
maxslots = The maximum number of slots.
WRITTEN BY: Davve
*/
var sb,xx,yy,swh,s,ms,wh,mwh,spr,sw,sh,sel,sel2,a,sp,ep,tp;
sb=argument0
xx=argument1
yy=argument2
swh=argument3
s=argument4
ms=argument5
wh=s*swh
mwh=ms*swh
spr=global.___sb[sb,2]
sw=sprite_get_width(spr)
sh=sprite_get_height(spr)
tp=global.___sb[sb,0]
if (global.___sbcurrent=sb) {
global.___sbtimer=max(0,(global.___sbtimer-1)*mouse_check_button(mb_left))
}
for (a=((xx+sw)*(tp=0))+((yy+sh)*(tp>0)) a<((xx+wh+sw)*(tp=0))+((yy+wh+sh)*(tp>0)) a+=2) {
draw_sprite(spr,(15*(tp=0))+(19*(tp>0)),(a*(tp=0))+(xx*(tp>0)),(yy*(tp=0))+(a*(tp>0)))
}
if (!mouse_check_button(mb_left) && global.___sbdrag>-1) {
global.___sbdrag=-1
}
if (mwh>wh && wh>0) {
sp=(((xx+sw)*(tp=0))+((yy+sh)*(tp>0)))+(global.___sb[sb,1]*((s/ms)*swh))
ep=sp+max((wh*(wh/mwh)),4)
if (global.___sbdrag=sb && ((mouse_x*(tp=0))+(mouse_y*(tp>0)))>=((xx+sw)*(tp=0))+((yy+sh)*(tp>0)) && ((mouse_x*(tp=0))+(mouse_y*(tp>0)))<((xx+(sw*2)+wh)*(tp=0))+((yy+(sh*2)+wh)*(tp>0))) {
global.___sb[sb,1]+=((((mouse_x*(tp=0))+(mouse_y*(tp>0)))-((global.___mxprev*(tp=0))+(global.___myprev*(tp>0)))))/(wh/ms)
global.___mxprev=mouse_x
global.___myprev=mouse_y
}
if (global.___sbcurrent=sb && global.___sb[sb,3]>0) {
global.___sb[sb,1]+=((-1*mouse_wheel_up())+(1*mouse_wheel_down()))
}
sel=(global.___sbdrag=-1 && (mouse_x*(tp=0))+(mouse_y*(tp>0))>=((xx+sw)*(tp=0))+((yy+sh)*(tp>0)) && (mouse_x*(tp=0))+(mouse_y*(tp>0))<sp && mouse_check_button(mb_left) && (mouse_y*(tp=0))+(mouse_x*(tp>0))>(yy*(tp=0))+(xx*(tp>0)) && (mouse_y*(tp=0))+(mouse_x*(tp>0))<((yy+sh)*(tp=0))+((xx+sh)*(tp>0)))
sel+=2*(global.___sbdrag=-1 && (mouse_x*(tp=0))+(mouse_y*(tp>0))>ep && (mouse_x*(tp=0))+(mouse_y*(tp>0))<((xx+sw+wh)*(tp=0))+((yy+sh+wh)*(tp>0)) && mouse_check_button(mb_left) && (mouse_y*(tp=0))+(mouse_x*(tp>0))>(yy*(tp=0))+(xx*(tp>0)) && (mouse_y*(tp=0))+(mouse_x*(tp>0))<((yy+sh)*(tp=0))+((xx+sh)*(tp>0)))
if (sel>0 && global.___sbtimer=0) {
global.___sb[sb,1]+=(-1*(sel=1))+(1*(sel=2))
global.___sb[sb,1]=max(0,min(ms-s,global.___sb[sb,1]))
global.___sbtimer=ceil(fps/(15-(12*mouse_check_button_pressed(mb_left))))
global.___sbcurrent=sb
}
global.___sb[sb,1]=min(ms-s,max(0,global.___sb[sb,1]))
if (global.___sbdrag<>sb) {
global.___sb[sb,1]=round(global.___sb[sb,1])
}
sp=(((xx+sw)*(tp=0))+((yy+sh)*(tp>0)))+(global.___sb[sb,1]*((s/ms)*swh))
ep=sp+max((wh*(wh/mwh)),4)
for (a=floor(sp+1) a<=ceil(ep-2) a+=1) {
draw_sprite(spr,(13*(tp=0))+(17*(tp>0)),(a*(tp=0))+(xx*(tp>0)),(yy*(tp=0))+(a*(tp>0)))
}
draw_sprite(spr,(12*(tp=0))+(16*(tp>0)),(floor(sp)*(tp=0))+(xx*(tp>0)),(floor(sp)*(tp>0))+(yy*(tp=0)))
draw_sprite(spr,(14*(tp=0))+(18*(tp>0)),((ceil(ep)-2)*(tp=0))+(xx*(tp>0)),((ceil(ep)-2)*(tp>0))+(yy*(tp=0)))
sel=(((mouse_x*(tp=0))+(mouse_y*(tp>0)))>=sp && ((mouse_x*(tp=0))+(mouse_y*(tp>0)))<ep && ((mouse_y*(tp=0))+(mouse_x*(tp>0)))>=(yy*(tp=0))+(xx*(tp>0)) && ((mouse_y*(tp=0))+(mouse_x*(tp>0)))<((yy+sh)*(tp=0))+((xx+sw)*(tp>0)) && mouse_check_button_pressed(mb_left))
if (sel=1 && global.___sbdrag=-1) {
global.___sbcurrent=sb
global.___sbdrag=sb
global.___mxprev=mouse_x
global.___myprev=mouse_y
}
} else if (global.___sbdrag=sb) {
global.___sbdrag=-1
}
sel=(((mouse_x*(tp=0))+(mouse_y*(tp>0)))>=(xx*(tp=0))+(yy*(tp>0)) && ((mouse_x*(tp=0))+(mouse_y*(tp>0)))<((xx+sw)*(tp=0))+((yy+sh)*(tp>0)) && ((mouse_y*(tp=0))+(mouse_x*(tp>0)))>=(yy*(tp=0))+(xx*(tp>0)) && ((mouse_y*(tp=0))+(mouse_x*(tp>0)))<((yy+sh)*(tp=0))+((xx+sw)*(tp>0)) && mouse_check_button(mb_left) && global.___sbdrag=-1 && mwh>wh)
sel2=(((mouse_x*(tp=0))+(mouse_y*(tp>0)))>=((xx+wh+sw)*(tp=0))+((yy+wh+sh)*(tp>0)) && ((mouse_x*(tp=0))+(mouse_y*(tp>0)))<((xx+(sw*2)+wh)*(tp=0))+((yy+(sh*2)+wh)*(tp>0)) && ((mouse_y*(tp=0))+(mouse_x*(tp>0)))>=(yy*(tp=0))+(xx*(tp>0)) && ((mouse_y*(tp=0))+(mouse_x*(tp>0)))<((yy+sh)*(tp=0))+((xx+sw)*(tp>0)) && mouse_check_button(mb_left) && global.___sbdrag=-1 && mwh>wh)
if (sel+sel2>0 && global.___sbtimer=0) {
global.___sb[sb,1]+=(-1*(sel=1))+(1*(sel2=1))
global.___sb[sb,1]=max(0,min(ms-s,global.___sb[sb,1]))
global.___sbtimer=ceil(fps/(15-(12*mouse_check_button_pressed(mb_left))))
global.___sbcurrent=sb
}
draw_sprite(spr,(0*(tp=0))+(6*(tp>0))+(sel>0 || mwh<=wh)+(mwh<=wh),xx,yy)
draw_sprite(spr,(3*(tp=0))+(9*(tp>0))+(sel2>0 || mwh<=wh)+(mwh<=wh),((xx+wh+sw)*(tp=0))+(xx*(tp>0)),(yy*(tp=0))+((yy+wh+sh)*(tp>0)))