This is a little demo program for the mouse / keyboard
Code: [Local Link Removed for Guests]
usb.setup 640, 480
onMouseClick Mouse_click
onKeyboard Keyboard_Press
active_text_Object = -1
myText$ = ""
vga.pinout 4,5,6, 7,15,16, 17, 18, 8,3
vga.delete
vga.init 2, 4
vga.writepage 0
vgagui.init 40, darkgrey'reserve memory for 20 GUI objects. clears screen to black
tft.loadfont "/fonts/FreeMono9pt7b.bin",10
tft.loadfont "/fonts/FreeMonoBold12pt7b.bin",11
tft.loadfont "/fonts/FreeSansBoldOblique24pt7b.bin",12
vga.image "/img/girl.jpg"
vga.copy 0, 3
ob1 = vgagui.circle(580, 250, 50, blue, yellow, red)
ob2 = vgagui.box(580, 300, 50, 50, red, green, blue)
ob3 = vgagui.line(500, 350, 600, 450, magenta)
t1 = vgagui.Textline(10,50,190,40, "Text Line", 1,yellow, darkgrey,magenta) 'x,y,w,h,text,fontsize
b1 = vgagui.Button(30, 5, 100, 40, "BUTTON!",0, 10, toggle ) 'x,y,w,h,text,fontsize
c1 = vgagui.checkbox(10,10,20,20,1, 2)
s1 = vgagui.slider 250,10,20,100,50,1
g1 = vgagui.gauge 250,200,150,150,0,red
t2 = vgagui.Textline(10,100,190,40, "Text Line", 2,red,yellow,magenta) 'x,y,w,h,text,fontsize
t3 = vgagui.Textline(400,120,200,60, "RED", 12,red,white,red) 'x,y,w,h,text,fontsize
r1 = vgagui.Ramp(400, 200, 160, 160, 50)
p1 = vgagui.ProgressBar(50, 430, 500, 40, 50)
b2 = vgagui.Button(30, 150, 100, 40, "BUTTON2",0, 10 ) 'x,y,w,h,text,fontsize
b3 = vgagui.Button(30, 200, 100, 40, "BUTTON3",0, 10, toggle ) 'x,y,w,h,text,fontsize
s2 = vgagui.slider 300,10,40,150,50,vertical, green
cc1 = vgagui.checkbox(400,10,20,20, 0, RADIO, 2)
cc2 = vgagui.checkbox(450,10,20,20, 0, RADIO, 2)
cc3 = vgagui.checkbox(500,10,20,20, 0, RADIO, 2)
cc4 = vgagui.checkbox(550,10,20,20, 0, RADIO, 2)
cc5 = vgagui.checkbox(400,40,20,20, 0, SQUARED, 3)
cc6 = vgagui.checkbox(450,40,20,20, 0, SQUARED, 3)
cc7 = vgagui.checkbox(500,40,20,20, 0, SQUARED, 3)
cc8 = vgagui.checkbox(550,40,20,20, 0, SQUARED, 3)
cc10 = vgagui.checkbox(400,70,20,20, 0, CROSSED)
cc11 = vgagui.checkbox(450,70,20,20, 0, CROSSED)
cc12 = vgagui.checkbox(500,70,20,20, 0, CROSSED)
cC13 = vgagui.checkbox(550,70,20,20, 0, CROSSED)
bi1 = vgagui.ButtonImage(10, 250, 48, 48, "/icons/48x48/Positive_48x48.bmp", "/icons/48x48/Negative_48x48.bmp", toggle, 4)
bi2 = vgagui.ButtonImage(60, 250, 48, 48, "/icons/48x48/Positive_48x48.bmp", "/icons/48x48/Negative_48x48.bmp", toggle, 4)
bi3 = vgagui.ButtonImage(110, 250, 48, 48, "/icons/48x48/Positive_48x48.bmp", "/icons/48x48/Negative_48x48.bmp", toggle, 4)
bi4 = vgagui.ButtonImage(160, 250, 48, 48, "/icons/48x48/Positive_48x48.bmp", "/icons/48x48/Negative_48x48.bmp", toggle, 4)
bi1 = vgagui.ButtonImage(10, 300, 48, 48, "/icons/48x48/Check_48x48.bmp", "/icons/48x48/Delete_48x48.bmp", toggle, 5)
bi2 = vgagui.ButtonImage(60, 300, 48, 48, "/icons/48x48/Check_48x48.bmp", "/icons/48x48/Delete_48x48.bmp", toggle, 5)
bi3 = vgagui.ButtonImage(110, 300, 48, 48, "/icons/48x48/Check_48x48.bmp", "/icons/48x48/Delete_48x48.bmp", toggle, 5)
bi4 = vgagui.ButtonImage(160, 300, 48, 48, "/icons/48x48/Check_48x48.bmp", "/icons/48x48/Delete_48x48.bmp", toggle, 5)
t4 = vgagui.Textline(10, 380, 250, 40, "MyText123", 1,red,yellow,magenta) 'x,y,w,h,text,fontsize
t5 = vgagui.Textline(300, 380, 250, 40, "Polletto", 1,red,yellow,magenta) 'x,y,w,h,text,fontsize
vgagui.refresh
vga.showpage 0
vga.show
vga.copy 0, 3
vga.showpage 3
VGA.SPRITESHEET "/sprites/mouse-pointers-white.bmp"
vga.setsprite 1, 32, 32, 64, 0, 0, 0
i = 0
backcolor = vga.color(magenta)
vga.writepage 1
vga.fill backcolor
for z = 0 to 100000
vga.writepage 0
vgagui.settext t1, str$(z)
vgagui.settext b1, str$(z)
vgagui.settext t2, str$(z)
vgagui.settext t3, str$(z)
vgagui.setvalue s1, z mod 100
vgagui.setvalue g1, z mod 100
vgagui.setvalue r1, z mod 100
vgagui.setvalue p1, z mod 100
vgagui.refresh 1, mouseX, mouseY, mouseZ
'vga.copy 0,act
vga.writepage 1
'vga.fill 0
mx = mouseX : my = mouseY
vga.next 530, 320, 48, z*180 , red, 7
vga.drawSprite 1, mx, my, 6
vga.merge 0, 1, 3, backcolor
vga.rect mx, my, 32, 32, backcolor , 1
vga.rect 480, 270, 100, 100, backcolor, 1
vga.show
next z
end
event:
vgagui.setvalue b1,i mod 2
i = i + 1
vgagui.setvalue c1,i mod 2
return
mouse_move:
print "move", mouseX, mouseY
return
Mouse_click:
print "click", mouseX, mouseY, mouseZ, mouseW
print "Object under Mouse", mouseObj
if (mouseObj = t4) or (mouseObj = t5) then
active_text_Object = mouseObj
vgagui.setcolor active_text_Object , green, black
end if
return
Keyboard_Press:
print kbdcode
if (active_text_Object = -1) then return
vgagui.gettext active_text_Object, myText$
select case kbdcode
case 0, 160
' nothing
case 8
if (len(myText$) > 0) then
myText$ = left$(myText$, len(myText$)-1)
end if
vgagui.setText active_text_Object, myText$
case 13
vgagui.setcolor active_text_Object, red, yellow
active_text_Object = -1
case else
if (len(myText$) < 20) then
myText$ = myText$ + chr$(kbdcode)
end if
vgagui.setText active_text_Object, myText$
end select
return
And this is for the Gamepad :
Code: [Local Link Removed for Guests]
usb.setup 640, 480
onGamePad GamePadChange
onMouseClick Mouse_click
onKeyboard Keyboard_Press
active_text_Object = -1
myText$ = ""
vga.pinout 4,5,6, 7,15,16, 17, 18, 8,3
vga.delete
vga.init 2, 4
vga.writepage 0
vgagui.init 40, darkgrey'reserve memory for 20 GUI objects. clears screen to black
tft.loadfont "/fonts/FreeMono9pt7b.bin",10
tft.loadfont "/fonts/FreeMonoBold12pt7b.bin",11
tft.loadfont "/fonts/FreeSansBoldOblique24pt7b.bin",12
'vga.image "/img/Annex_new_logo_640x480.bmp"
vga.copy 0, 3
t1 = vgagui.Textline(10,10,300,40, "Annex ESP32-S3 USB", 2,green, black,red) 'x,y,w,h,text,fontsize
t2 = vgagui.Textline(10,60,300,40, "Enter free Text", 2,green, black,red) 'x,y,w,h,text,fontsize
b1 = vgagui.Button(100, 210, 80, 40, "BUTTON1",0, 10 ) 'x,y,w,h,text,fontsize
s1 = vgagui.slider(10,260,30,200,50,vertical, green)
s2 = vgagui.slider(50,430,200,30,50,horizontal, green)
b2 = vgagui.Button(410, 210, 80, 40, "BUTTON2",0, 10 ) 'x,y,w,h,text,fontsize
s3 = vgagui.slider(320,260,30,200,50,vertical, blue)
s4 = vgagui.slider(360,430,200,30,50,horizontal, blue)
vgagui.setrange s1, 128, -128
vgagui.setrange s2, -128, 128
vgagui.setrange s3, 128, -128
vgagui.setrange s4, -128, 128
b3 = vgagui.Button(60, 150, 50, 40, "SELECT",0, 10 ) 'x,y,w,h,text,fontsize
b4 = vgagui.Button(160, 150, 50, 40, "START",0, 10 ) 'x,y,w,h,text,fontsize
c1 = vgagui.checkbox(350, 110, 20, 20, 0, SQUARED)
c2 = vgagui.checkbox(400, 150, 20, 20, 0, SQUARED)
c3 = vgagui.checkbox(350, 200, 20, 20, 0, SQUARED)
c4 = vgagui.checkbox(300, 150, 20, 20, 0, SQUARED)
c5 = vgagui.checkbox(550, 110, 20, 20, 0, RADIO)
c6 = vgagui.checkbox(600, 150, 20, 20, 0, RADIO)
c7 = vgagui.checkbox(550, 200, 20, 20, 0, RADIO)
c8 = vgagui.checkbox(500, 150, 20, 20, 0, RADIO)
l1 = vgagui.Button(335, 10, 50, 30, "L1",0, 10 )
l2 = vgagui.Button(335, 50, 50, 30, "L2",0, 10 )
r1 = vgagui.Button(535, 10, 50, 30, "R1",0, 10 )
r2 = vgagui.Button(535, 50, 50, 30, "R2",0, 10 )
box1 = vgagui.box 70, 260, 160, 160, black, white
box1 = vgagui.box 380, 260, 160, 160, black, white
vgagui.refresh
vga.showpage 0
vga.show
VGA.SPRITESHEET "/sprites/mouse-pointers-white.bmp"
vga.setsprite 1, 32, 32, 64, 0, 0, 0
i = 0
act = 1
for z = 0 to 100000000
vga.writepage 0
'print bin$(KeyPadCodes(5)), bin$(KeyPadCodes(6))
if GamePadCodes(0) = 1 then
vgagui.setvalue s1, GamePadCodes(4) - 128
vgagui.setvalue s2, GamePadCodes(3) - 128
vgagui.setvalue s3, GamePadCodes(2) - 128
vgagui.setvalue s4, GamePadCodes(1) - 128
k1 = GamePadCodes(5)
k2 = GamePadCodes(6)
vgagui.setvalue l1, k2 and &b1
vgagui.setvalue l2, k2 and &b100
vgagui.setvalue r1, k2 and &b10
vgagui.setvalue r2, k2 and &b1000
vgagui.setvalue b1, k2 and &b1000000
vgagui.setvalue b2, k2 and &b10000000
vgagui.setvalue b3, k2 and &b10000
vgagui.setvalue b4, k2 and &b100000
vgagui.setvalue c1, 0
vgagui.setvalue c2, 0
vgagui.setvalue c3, 0
vgagui.setvalue c4, 0
select case (k1 and &b1111)
case 0
vgagui.setvalue c1, 1
case 1
vgagui.setvalue c1, 1
vgagui.setvalue c2, 1
case 2
vgagui.setvalue c2, 1
case 3
vgagui.setvalue c2, 1
vgagui.setvalue c3, 1
case 4
vgagui.setvalue c3, 1
case 5
vgagui.setvalue c3, 1
vgagui.setvalue c4, 1
case 6
vgagui.setvalue c4, 1
case 7
vgagui.setvalue c1, 1
vgagui.setvalue c4, 1
end select
vgagui.setvalue c5, k1 and &b10000
vgagui.setvalue c6, k1 and &b100000
vgagui.setvalue c7, k1 and &b1000000
vgagui.setvalue c8, k1 and &b10000000
vga.rect 71, 261, 158, 158, black, 1
vga.circle (GamePadCodes(3) - 128) / 128*60 + 155, (GamePadCodes(4) - 128) / 128*60 + 340, 5, green, 1
vga.rect 381, 261, 158, 158, black, 1
vga.circle (GamePadCodes(1) - 128) / 128*60 + 460, (GamePadCodes(2) - 128) / 128*60 + 340, 5, blue, 1
end if
vgagui.refresh
'vgagui.refresh 1, mouseX, mouseY, mouseZ
vga.copy 0,act
vga.writepage act
vga.drawSprite 1, mouseX, mouseY, 6
vga.showpage act
act = 3-act
vga.show
next z
end
event:
vgagui.setvalue b1,i mod 2
i = i + 1
vgagui.setvalue c1,i mod 2
return
mouse_move:
print "move", mouseX, mouseY
return
Mouse_click:
print "click", mouseX, mouseY, mouseZ, mouseW
vgagui.refresh 1, mouseX, mouseY, mouseZ
print "Object under Mouse", mouseObj
if (mouseObj = t1) or (mouseObj = t2) then
active_text_Object = mouseObj
vgagui.setcolor active_text_Object , red, white
end if
return
Keyboard_Press:
print kbdcode
if (active_text_Object = -1) then return
vgagui.gettext active_text_Object, myText$
select case kbdcode
case 0, 160
' nothing
case 8
if (len(myText$) > 0) then
myText$ = left$(myText$, len(myText$)-1)
end if
vgagui.setText active_text_Object, myText$
case 13
vgagui.setcolor active_text_Object, green, black
active_text_Object = -1
case else
if (len(myText$) < 20) then
myText$ = myText$ + chr$(kbdcode)
end if
vgagui.setText active_text_Object, myText$
end select
return
GamePadChange:
print "gamepad"
return