Täs ois mun GUI libaryn Buttoni näin etukäteen jaossa. (Lisää osia tulossa tähän GUI:ni)
Code: Select all
Global DSG_R, DSG_G, DSG_B
Global DSG_RLit, DSG_GLit, DSG_BLit
Global DSG_RDark, DSG_GDark, DSG_BDark
Const DSG_SettingOFF = -1
font = LoadFont("Arial",15,1)
DSG_Colorize(0,150,150)
Palette = LoadImage("Media\Palette.BMP")
Repeat
Color 255,255,255
ClearText
Locate 20,0
AddText "Valitse väri täältä "
AddText "hiiren vasemmalla "
AddText "Näppäimellä. "
DrawImage Palette, 20, 50
If MouseX() > 20 And MouseX() < 20 + ImageWidth(Palette) And MouseY() > 50 And MouseY() < 50 + ImageHeight(Palette)
If MouseDown(1) Then
PickImageColor Palette, MouseX() - 20, MouseY() - 20
DSG_Colorize(DSG_SettingOFF)
EndIf
EndIf
SetFont font
Color cbblue
If DSG_Button("Start Game!", ScreenWidth()/2, ScreenHeight()/2, 100, 50, 1) Then MakeError "There's no game available!"
DrawScreen
Forever
Function DSG_Colorize(R = 0, G = 128, B = 128,Bright# = 45.0, Darken# = - 20.0)
If R < 0 Then
DSG_R = getRGB(1)
DSG_G = getRGB(2)
DSG_B = getRGB(3)
Else
DSG_R = R
DSG_G = G
DSG_B = B
EndIf
DSG_RLit = Max(0,Min(255, DSG_R + Bright))
DSG_GLit = Max(0,Min(255, DSG_G + Bright))
DSG_BLit = Max(0,Min(255, DSG_B + Bright))
DSG_RDark = Max(0,Min(255, DSG_R - Darken))
DSG_GDark = Max(0,Min(255, DSG_G - Darken))
DSG_BDark = Max(0,Min(255, DSG_B - Darken))
Return 0
EndFunction
Function DSG_ColorSlide(x, y, w, h, r1#, g1#, b1#, r2# = -1, g2# = -1, b2# = -1, style = 0)
If r2 = -1 And b2 = -1 And g2 = -1 Then
r2 = r1
g2 = g1
b2 = b1
r1 = getRGB(1)
g1 = getRGB(2)
b1 = getRGB(3)
EndIf
If style = 0 Then
For i = 0 To h
Color r1 + (r2 - r1) / h * i, g1 + (g2 - g1) / h * i, b1 + (b2 - b1) / h * i
Box x, y+i, w, 1
Next i
Else
For i = 0 To w
Color r1 + (r2 - r1) / w * i, g1 + (g2 - g1) / w * i, b1 + (b2 - b1) / w * i
Box x+i, y, 1, h
Next i
EndIf
EndFunction
Function DSG_Button(text$,x,y,w,h,centering = 0, Lightness# = 1)
If w < TextWidth(Text$) Then w = TextWidth(Text$) + 20
If h < TextHeight("|") Then h = TextHeight("|") + 20
If centering Then
x = x - w / 2
y = y - h / 2
EndIf
rkerroinl# = DSG_RLit /((DSG_GLit + DSG_BLit)/2)
gkerroinl# = DSG_GLit /((DSG_BLit + DSG_RLit)/2)
bkerroinl# = DSG_BLit /((DSG_GLit + DSG_RLit)/2)
rkerroind# = DSG_RDark /((DSG_GDark + DSG_BDark)/2)
gkerroind# = DSG_GDark /((DSG_BDark + DSG_RDark)/2)
bkerroind# = DSG_BDark /((DSG_GDark + DSG_RDark)/2)
If Not (MouseX() => x And MouseX() =< x + w And MouseY() => y And MouseY() =< y + h) Then
Color DSG_R, DSG_G, DSG_B
DSG_ColorSlide(x, y, w, h/2, 255, 255, 255)
Color 0, 0, 0
DSG_ColorSlide(x, y+h/2, w, h/2, DSG_R, DSG_G, DSG_B)
white = (DSG_R + DSG_G + DSG_B) / 3
Color white, white, white
CenterText x+w/2,y+h/2,Text$,2
Else
Color DSG_RLit, DSG_GLit, DSG_BLit
DSG_ColorSlide(x, y, w, h/2, 255, 255, 255)
Color 0, 0, 0
DSG_ColorSlide(x, y+h/2, w, h/2, DSG_RLit, DSG_GLit, DSG_BLit)
white = (DSG_RLit + DSG_RLit + DSG_RLit) / 3
Color white, white, white
CenterText x+w/2,y+h/2,Text$,2
If MouseDown(1) Then
Color DSG_RDark, DSG_GDark, DSG_BDark
DSG_ColorSlide(x, y, w, h/2, 0, 0, 0)
Color DSG_RDark, DSG_GDark, DSG_BDark
DSG_ColorSlide(x, y+h/2, w, h/2, 255, 255, 255)
white = (DSG_RDark + DSG_GDark + DSG_BDark) / 3
Color white, white, white
CenterText x+w/2+1,y+h/2+1,Text$,2
EndIf
If MouseUp(1) Then
Return True
EndIf
EndIf
EndFunction
Saatte vapaasti käyttää ylläolevaa koodia.