Well maybe it is your project?dasyar wrote:I am trying to stay away from making this look like my personal blog, and maybe "tutorial" was the wrong word to use.
I see the thread has been move to the hardware interface/communication section.
It is not sleep 2.1 it is sleep 2,1 (comma not full stop)
The fun of programming is debugging :)When you click on the ComboBox and make a selection, it is not displaying the chosen selection.
However how you go about designing code can make bugs much less likely.
Cowboy programming as I have done is prone to errors.
My code above did have errors and I went back and corrected them.
If you write your own code based on your own logic and not just copy without understanding, errors become easier to figure out.
Checking area for header is y to y+16
Checking area for list is y+16 to y+h
Item on list will be (my-y-16)\16
Code: Select all
' +-----------------+ x+w,y
' | BAUD - |
' +-----------------+ x+w,y+16
' | 9600 |
' | 19200 |
' | 38400 |
' | 57600 |
' | 115200 |
' +-----------------+ x+w,y+h
Code: Select all
Type COMBO_BOX
As String title
As String List(0 to 4)
As Integer x
As Integer y
As Integer w
As Integer h
As String selItem
As Integer a
End Type
' ComboBox
Sub drawComboBox(cmb as COMBO_BOX)
Line (cmb.x,cmb.y)-(cmb.x + cmb.w, cmb.y + 16), rgb(0,0,0), b
Draw String (cmb.x+4,cmb.y+4),cmb.title & cmb.selItem
If cmb.a = 1 Then
Line (cmb.x,cmb.y)-(cmb.x + cmb.w, cmb.y + cmb.h),rgb(0,0,0),b
For i as Integer = 0 to 4
Draw String (cmb.x+4,cmb.y+i*16+4+16),cmb.list(i)
Next i
End If
End Sub
Type BUTTON
As String title
As Integer x
As Integer y
As Integer w
As Integer h
As ulong c1
As ulong c2
As Integer a
End Type
' Button
Sub drawButton(btn as BUTTON)
Line (btn.x,btn.y)-(btn.x + btn.w,btn.y + 16),rgb(238,223,204), bf ' Antique white
' Button outline, fixed color is gray
Line (btn.x,btn.y)-(btn.x + btn.w,btn.y + 16),rgb(190,190,190), b 'Gray
Draw String (btn.x+4,btn.y+4),btn.title,btn.c1
End Sub
'================================================================================
' fbtermg.bas
'
' October 26, 2017
'
#include "fbgfx.bi"
#if __FB_LANG__ = "fb"
Using fb
#endif
'#include "mygui.bi"
'Screen 20 '1024x768
Screenres 640,480,32
Color rgb(0,0,0),rgb(135,206,250):cls
WindowTitle "FBtermg Program"
Dim e As EVENT
Dim Shared as Integer mx,my,mb
Dim Shared As BUTTON btnConnect, btnQuit
Dim Shared As COMBO_BOX cmbPort, cmbBaud
Declare Sub update()
Dim As Integer hit
' Quit button
btnQuit.x = 0 ' Window column
btnQuit.y = 0 ' Window row
btnQuit.w = 8 * 6 ' Width of button outline
btnQuit.h = 16 * 6 ' Height of button outline
btnQuit.title = "Quit"
'btnQuit.c2 = rgb(238,223,204) ' Button background
'btnQuit.c1 = rgb(0,250,154) ' Button foreground
' Connect button
btnConnect.x = 60
btnConnect.y = 0
btnConnect.w = 8 * 9
btnConnect.h = 16 * 6
btnConnect.title = "Connect"
'btnQuit.c2 = rgb(238,223,204)
'btnQuit.c1 = rgb(0,250,154)
'Port combobox
cmbPort.x = 150
cmbPort.y = 0
cmbPort.w = 8 * 22
cmbPort.h = 16 * 6
cmbPort.title = "Port -"
cmbPort.list(0) = "/dev/ttyAMA0:"
cmbPort.list(1) = "/dev/ttyUSB0:"
cmbPort.list(2) = "/dev/ttyUSB1:"
cmbPort.list(3) = "/dev/TTYUSB2:"
cmbPort.list(4) = "/dev/ttyUSB3:"
'Baud combobox
cmbBaud.x = 345
cmbBaud.y = 0
cmbBaud.w = 8 * 22
cmbBaud.h = 16 * 6
cmbBaud.title = "BAUD -"
cmbBaud.list(0) = "9600"
cmbBaud.list(1) = "19200"
cmbBaud.list(2) = "38400"
cmbBaud.list(3) = "57600"
cmbBaud.list(4) = "115200"
Do
getmouse mx,my,,mb ' Start mouse
' Close the window using the "X"
If(ScreenEvent(@e)) Then
Select Case e.Type
Case EVENT_WINDOW_CLOSE ' X in window
Close
End
End Select
End If
If mb = 1 Then
hit = 0
' Mouse over btnQuit
If mx>btnQuit.x And mx<btnQuit.x+btnQuit.w and my>btnQuit.y and my<btnQuit.y+16 Then
btnQuit.a = 1
btnConnect.a = 0
cmbBaud.a = 0
cmbPort.a = 0
hit = 1
Close
End
End If
If mx>btnConnect.x And mx<btnConnect.x+btnConnect.w and my>btnConnect.y and my<btnConnect.y+16 Then
btnQuit.a = 0
btnConnect.a = 1
cmbBaud.a = 0
cmbPort.a = 0
hit = 1
End If
'is it over cmbBaud HEADER?
if mx>cmbBaud.x and mx<cmbBaud.x+cmbBaud.w and my>cmbBaud.y and my<cmbBaud.y+16 then
cmbBaud.a = 1
cmbPort.a = 0
hit = 1
end if
'is it over cmbPort HEADER?
if mx>cmbPort.x and mx<cmbPort.x+cmbPort.w and my>cmbPort.y and my<cmbPort.y+16 then
cmbPort.a = 1
cmbBaud.a = 0
hit = 1
end if
'is it over cmbBaud LIST
if cmbBaud.a = 1 and mx>cmbBaud.x and mx<cmbBaud.x+cmbBaud.w and my>cmbBaud.y + 16 and my<cmbBaud.y+cmbBaud.h then
cmbBaud.selItem = cmbBaud.list((my-cmbBaud.y-16)\16)
hit = 1
end if
'is it over cmbPort LIST
if cmbPort.a = 1 and mx>cmbPort.x and mx<cmbPort.x+cmbPort.w and my>cmbPort.y + 16 and my<cmbPort.y+cmbPort.h then
cmbPort.selItem = cmbPort.list((my-cmbPort.y-16)\16)
hit = 1
end if
if hit = 0 then 'mouse down outside any object so deactivate any activated object
cmbPort.a = 0
cmbBaud.a =0
end if
End If
update()
' Mouse event
While mb = 1
getmouse mx,my,,mb
Wend
Sleep 2,1
Loop until multikey(&H01) ' Esc key to close
''''''''''''''''''''''''''''''
End
' Screen update
Sub update()
Screenlock
Cls
drawButton(btnQuit)
drawButton(btnConnect) ' Not active for now
drawComboBox(cmbPort)
drawComboBox(cmbBaud)
Screenunlock
End Sub