Post by Rod on May 13, 2021 12:23:45 GMT
Following on from Sprite Creator I have started a Button Creator project. Just in its infancy but surprising what you can do. Again this deliberately avoids API code. It is all native.
For this demo you will need to get this bmp file.
This simple fragment allows six button and tab styles to be drawn. The code looks at the color and if the RGB are the same it draws that color. That draws the frame if there is one. If they are varied then it takes the green color and lets you alter any R G or B so creating any color glass shading. The text is merged in transparently on a similar basis.
This is the demo's output random buttons and tabs in random colors, they can change width, the text will centre.
For this demo you will need to get this bmp file.
This simple fragment allows six button and tab styles to be drawn. The code looks at the color and if the RGB are the same it draws that color. That draws the frame if there is one. If they are varied then it takes the green color and lets you alter any R G or B so creating any color glass shading. The text is merged in transparently on a similar basis.
This is the demo's output random buttons and tabs in random colors, they can change width, the text will centre.
nomainwin
WindowWidth = 800
WindowHeight = 600
UpperLeftX = int((DisplayWidth-WindowWidth)/2)
UpperLeftY = int((DisplayHeight-WindowHeight)/2)
midx=int(WindowWidth/2)
midy=int(WindowHeight/2)
open "Button Maker" for graphics_nsb as #1
#1 "down ; trapclose [quit]"
#1 "font ms_sans_serif 10"
for y = 60 to 500 step 35
for x = 100 to 600 step 105
'set button text
txt$="0123456789"
'set button width
w=100
'set button style
s=int(rnd(0)*6)
'set button background color to white
bcol$="255 255 255"
'set random color for text
tcol$=str$(int(rnd(0)*128+128))+" "+str$(int(rnd(0)*128+128))+" "+str$(int(rnd(0)*128+128))
'set random color for glass shade
scol$=str$(int(rnd(0)*255))+" "+str$(int(rnd(0)*255))+" "+str$(int(rnd(0)*255))
nul=createButton(txt$,w,s,bcol$,tcol$,scol$)
#1 "getbmp button 0 0 100 30"
#1 "drawbmp button ";x;" ";y
next
next
wait
[quit]
close #1
end
function createButton(txt$,w,s,bcol$,tcol$,scol$)
'open graphic resouce
open "buttontest.bmp" for binary as #bmp
'centre and draw text then capture it
texlen=len(txt$)*7
texx=int((w-texlen)/2)
#1 "place 0 0 ; color black ; backcolor black ; boxfilled ";w;" 30"
#1 "color ";tcol$;" ; place ";texx;" 20 ;\";txt$
#1 "getbmp tmp 0 0 ";w;" 30"
bmpsave "tmp","tmp.bmp"
'open text resource
open "tmp.bmp" for binary as #txt
red=val(word$(scol$,1))/255
green=val(word$(scol$,2))/255
blue=val(word$(scol$,3))/255
'background
#1 "backcolor ";bcol$;" ; color ";bcol$;" ; place 0 0 ; boxfilled ";w;" 30"
'left image
for y= 0 to 29
for x= 0 to 14
c$=GetPixel$(x+s*15,y)
if c$=" 0 0 0" then [skip0]
if mid$(c$,1,3)=mid$(c$,5,3) and mid$(c$,1,3)=mid$(c$,9,3) then
#1 "color ";c$
else
#1 "color ";val(mid$(c$,5,3))*red;" ";val(mid$(c$,5,3))*green;" ";val(mid$(c$,5,3))*blue
end if
#1 "set ";x;" ";y
[skip0]
next
next
'middle image
for y= 0 to 29
for x=15 to w-15
c$=GetTxt$(x,y,w)
#1 "color ";c$
if c$=" 0 0 0" then
c$=GetPixel$(14+s*15,y)
if c$=" 0 0 0" then [skip1]
if word$(c$,1)=word$(c$,2) and word$(c$,1)=word$(c$,3) then
#1 "color ";c$
else
#1 "color ";val(mid$(c$,5,3))*red;" ";val(mid$(c$,5,3))*green;" ";val(mid$(c$,5,3))*blue
end if
end if
#1 "set ";x;" ";y
[skip1]
scan
next
next
' right image
for y= 0 to 29
for x= 14 to 0 step -1
c$=GetPixel$(x+s*15,y)
if c$=" 0 0 0" then [skip2]
if mid$(c$,1,3)=mid$(c$,5,3) and mid$(c$,1,3)=mid$(c$,9,3) then
#1 "color ";c$
else
#1 "color ";val(mid$(c$,5,3))*red;" ";val(mid$(c$,5,3))*green;" ";val(mid$(c$,5,3))*blue
end if
#1 "set ";(w-1)-x;" ";y
[skip2]
next
next
close #bmp
close #txt
end function
function GetTxt$(x,y,w)
'set for 32bit w x 30 bmp offset 66, 4 bytes per pixel no padding
y=29-y 'invert y as bmp is stored inverted
seek #txt, 66+x*4+y*w*4
s$ = input$(#txt,3)
red = asc(right$(s$,1))
green = asc(mid$(s$,2,1))
blue = asc(left$(s$,1))
'concatenate the return value to Liberty color string
GetTxt$ = using("###",red)+" "+using("###",green)+" "+using("###",blue)
end function
function GetPixel$(x,y)
'set for 24bit 100 x 30 bmp offset 54, 3 bytes per pixel no padding
y=29-y 'invert y as bmp is stored inverted
seek #bmp, 54+x*3+y*100*3
s$ = input$(#bmp,3)
red = asc(right$(s$,1))
green = asc(mid$(s$,2,1))
blue = asc(left$(s$,1))
'concatenate the return value to Liberty color string
GetPixel$ = using("###",red)+" "+using("###",green)+" "+using("###",blue)
end function