Anyway, here's my charity project for this day :)
;
; Nicelabel
;
; by CS^TBL
;
; ---------------------------------------------
;
; Nicelabel:
;
; label=CreateNicelabel("txt",x,y,width,height,parent)
;
; SetNicelabelText(label,"blah")
;
; SetNicelabelLayout(label,fillstyle,borderstyle,textR,textG,textB,fillR1,fillG1,fillB1,fillR2,fillG2,fillB2)
;
; fillstyle:
; 0 solid color (rgb1)
; 1 vertical gradient (rgb1->rgb2)
; 2 horizontal gradient (rgb1->rgb2)
;
; borderstyle:
; 0 no border
; 1 black border
; 2 sunken 3d border thickness 1
; 3 sunken 3d border thickness 2
;
app=CreateWindow("Nicelabel example - CS^TBL",0,0,640,480)
label=CreateNicelabel("Hello world!",100,100,192,18,app)
SetNicelabelLayout(label,1,2,0,0,0,192,192,192,128,128,128)
label2=CreateNicelabel("Uhm..",100,120,192,18,app)
label3=CreateNicelabel("Yeah..!",100,140,192,18,app)
SetNicelabelLayout(label3,1,1,0,0,0,192,192,192,128,128,128)
label4=CreateNicelabel("Whop!",100,260,192,22,app)
SetNicelabelLayout(label4,2,3,255,255,255,0,0,255,0,0,128)
quit=False
Repeat
WaitEvent()
If EventID()=$803 quit=True
Until quit
FreeBank label
End
Function SetNicelabelLayout(bank,fillstyle=1,borderstyle=2,textR=0,textG=0,textB=0,fillR1=192,fillG1=192,fillB1=192,fillR2=128,fillG2=128,fillB2=128)
If Not bank Break "Bank required!"
PokeByte bank,260,Limit(fillstyle,0,2)
PokeByte bank,261,Limit(borderstyle,0,3)
PokeByte bank,262,Limit(textR,0,255)
PokeByte bank,263,Limit(textG,0,255)
PokeByte bank,264,Limit(textB,0,255)
PokeByte bank,265,Limit(fillR1,0,255)
PokeByte bank,266,Limit(fillG1,0,255)
PokeByte bank,267,Limit(fillB1,0,255)
PokeByte bank,268,Limit(fillR2,0,255)
PokeByte bank,269,Limit(fillG2,0,255)
PokeByte bank,270,Limit(fillB2,0,255)
UpdateNicelabel(bank)
End Function
Function CreateNicelabel(txt$,x,y,width,height,parent)
If Not parent Break "Wrong Parent!"
If (width*height)=0 Break "Image size zero"
If Len(txt$)>255 Break "Text too long ... comeon dude.. it's just supposed to be a f*ck*ng LABEL :)"
bank=CreateBank(256 + 4 + 1+1 + 1+1+1 + 1+1+1 + 1+1+1)
txt$=LSet$(txt$,256)
For t=0 To 255
PokeByte bank,t,Asc(Mid$(txt$,1+t,1))
Next
PokeByte bank,260,0 ; fillstyle
PokeByte bank,261,0 ; borderstyle
PokeByte bank,262,0 ; textR
PokeByte bank,263,0 ; textG
PokeByte bank,264,0 ; textB
PokeByte bank,265,192 ; fillR1
PokeByte bank,266,192 ; fillG1
PokeByte bank,267,192 ; fillB1
PokeByte bank,268,128 ; fillR2
PokeByte bank,269,128 ; fillG2
PokeByte bank,270,128 ; fillB2
canvas=CreateCanvas(x,y,width,height,parent)
PokeInt bank,256,canvas
UpdateNicelabel(bank)
Return bank
End Function
Function SetNicelabelText(bank,txt$)
If Not bank Break "Wrong Parent!"
If Len(txt$)>255 Break "Text too long ... comeon dude.. it's just supposed to be a f*ck*ng LABEL :)"
txt$=LSet$(txt$,256)
For t=0 To 255
PokeByte bank,t,Asc(Mid$(txt$,1+t,1))
Next
UpdateNicelabel(bank)
End Function
Function UpdateNicelabel(bank)
If Not bank Break "Bank required!"
canvas=PeekInt(bank,256)
width=GadgetWidth(canvas)
height=GadgetHeight(canvas)
fillstyle=PeekByte(bank,260)
borderstyle=PeekByte(bank,261)
textR=PeekByte(bank,262)
textG=PeekByte(bank,263)
textB=PeekByte(bank,264)
fillR1=PeekByte(bank,265)
fillG1=PeekByte(bank,266)
fillB1=PeekByte(bank,267)
fillR2=PeekByte(bank,268)
fillG2=PeekByte(bank,269)
fillB2=PeekByte(bank,270)
txt$=""
For t=0 To 255
txt$=txt$+Chr$(PeekByte(bank,t))
Next
txt$=Trim$(txt$)
SetBuffer CanvasBuffer(canvas)
Select fillstyle
Case 0 ; solid color (rgb1)
ClsColor fillR1,fillG1,fillB1:Cls
Color textR,textG,textB
Color textR,textG,textB:Text width/2,height/2,txt$,True,True
Case 1 ; vertical gradient (top:rgb1 bottom:rgb2)
For y=0 To height-1
ph#=Float(y)/Float(height)
r=LinInt(fillR1,fillR2,ph#)
g=LinInt(fillG1,fillG2,ph#)
b=LinInt(fillB1,fillB2,ph#)
Color r,g,b:Line 0,y,width-1,y
Next
Color textR,textG,textB:Text width/2,height/2,txt$,True,True
Case 2 ; horizontal gradient (left:rgb1 right:rgb2)
For x=0 To width-1
ph#=Float(x)/Float(width)
r=LinInt(fillR1,fillR2,ph#)
g=LinInt(fillG1,fillG2,ph#)
b=LinInt(fillB1,fillB2,ph#)
Color r,g,b:Line x,0,x,height-1
Next
Color textR,textG,textB:Text width/2,height/2,txt$,True,True
End Select
Select borderstyle
Case 0 ; no border
Case 1 ; black border
Color 0,0,0
Rect 0,0,width,height,False
Case 2 ; sunken 3d border
Color 255,255,255: Line 1,height-1,width-1,height-1: Line width-1,1,width-1,height-1
Color 0,0,0: Line 0,0,width-2,0: Line 0,0,0,height-2
Case 3 ; sunken 3d border thickness 2
Color 255,255,255:
Line 1,height-1,width-1,height-1
Line 2,height-2,width-2,height-2
Line width-1,1,width-1,height-1
Line width-2,2,width-2,height-2
Color 0,0,0
Line 0,0,width-2,0
Line 1,1,width-3,1
Line 0,0,0,height-2
Line 1,1,1,height-3
End Select
FlipCanvas canvas
End Function
; global functions.. anyone should have them anyway, very handy stuff.. :)
Function Limit(value,minvalue,maxvalue)
If value<minvalue Return minvalue
If value>maxvalue Return maxvalue
Return value
End Function
Function Break(s$)
Notify s$
End
End Function
Function LinInt#(v1#,v2#,phase#)
Return (v1#+((v2#-v1#)*phase#))
End Function
|