Basic GUI designer

General FreeBASIC programming questions.
Gablea
Posts: 1049
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Basic GUI designer

Postby Gablea » Jun 29, 2015 12:17

Hi all,
I remember a few years ago I was using a simple gui designer application to make forms etc for my Freebasic project

Can someone tell me if the application or something simpler is available this is a youtube video I found of the app

https://www.youtube.com/watch?v=xbZC2dCGpmo

Thanks

Andy
Tourist Trap
Posts: 2880
Joined: Jun 02, 2015 16:24

Re: Basic GUI designer

Postby Tourist Trap » Jun 29, 2015 15:50

I'm not using it for that but FBEdit has some GUI capabilities I think since it has a compile in GUI WINDOW mode. Just start a project with new project and try.
Link to FBEdit is on the download pages of FB official site.
Lothar Schirm
Posts: 333
Joined: Sep 28, 2013 15:08
Location: Bavaria, Germany

Re: Basic GUI designer

Postby Lothar Schirm » Jun 29, 2015 16:59

Gablea, you can find the code here: http://www.freebasic.net/forum/viewtopic.php?f=8&t=13010&hilit=A+not+so+crappy+FreeBASIC+gui+code+maker. I tested the last code some months ago, but it did not work properly. You could try FireFly, rather simple to use, but produces a lot of code in different files. Actually I work without a GUI designer.
Gablea
Posts: 1049
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Basic GUI designer

Postby Gablea » Jun 29, 2015 20:39

I would use the other ones but they will not compile for DOS so I am limited to what i can use
BasicCoder2
Posts: 3558
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Basic GUI designer

Postby BasicCoder2 » Jun 29, 2015 21:01

Gablea wrote:I would use the other ones but they will not compile for DOS so I am limited to what i can use

How complex is your GUI requirements?
You can roll your own which is what is used to do with QBASIC on the old MSDOS machines.
Gablea
Posts: 1049
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Basic GUI designer

Postby Gablea » Jun 29, 2015 22:01

Mine is not that complicated the ONLY thing that is really stopping me from doing my own is the mouse support.

I have spend almost a year trying to design my own (with the up and down look of the buttons) but I can not get it to work nor can I get them to work with the mouse (not sure what I am doing)

So for now I would be happy with a Interface that actually works.

unless someone has a video tutorial on mouse support in Freebasic (DOS would be great as that is the OS I am going to be using)
BasicCoder2
Posts: 3558
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Basic GUI designer

Postby BasicCoder2 » Jun 30, 2015 0:06

Gablea wrote:Mine is not that complicated the ONLY thing that is really stopping me from doing my own is the mouse support.

Doesn't FreeBASIC have MSDOS mouse support?
Last edited by BasicCoder2 on Jun 30, 2015 10:20, edited 1 time in total.
grindstone
Posts: 726
Joined: May 05, 2015 5:35
Location: Germany

Re: Basic GUI designer

Postby grindstone » Jun 30, 2015 0:38

@Gablea: Maybe this little snipet can help you, I use it in some of my own programmes. You can simply adapt it to your needs, with some slight changes it even works at the console window.

Code: Select all

Declare Function mouseMenu(text As String, separator As String = "", lin As Integer = 1, _
                            col As Integer = 1, foreground As UInteger, background As UInteger, _
                            mode As Integer = 0) As Integer
ScreenRes 640,480,32
Do
   If mouseMenu(" button 1 ",,5,10,RGB(255,255,255),RGB(0,0,0)) = 9 Then
      Locate 20,20
      Print "BUTTON 1"
   ElseIf mouseMenu(" button 2 ",,-2,10,RGB(255,255,255),RGB(0,0,0)) = 9 Then
      Locate 20,20
      Print "BUTTON 2"
   ElseIf mouseMenu(" exit ",,-2,10,RGB(255,255,255),RGB(0,0,0)) = 9 Then
      End
   EndIf
Loop

#Macro PrintMenuItem()

   Color foreground, background 'normal colours
   compareColor = foreground + 16 * background
   PrintMenuItemMain()

#EndMacro

#Macro PrintMenuItemInv()

   Color background, foreground 'inverse colours
   compareColor = background + 16 * foreground
   PrintMenuItemMain()

#EndMacro

#Macro PrintMenuItemMain()
   
   For x = 1 To Len(text)
     If (Screen(lin,col - 1 + x,0) <> Asc(Mid(text,x,1))) Or _
         (Screen(lin,col - 1 + x,1) <> compareColor) Then 'only print if necessary
        Locate lin, col, 0 'adjust menu text to separator
        If (mode And 2) Then 'draw frame around text
           Line (col * 8 - 9,lin * 8 - 9)-((col + Len(text) - 1) * 8,lin  * 8),foreground,b
        EndIf
        Print text
        Exit For
     EndIf
   Next
   
#EndMacro
Function mouseMenu(text As String, separator As String = "", lin As Integer = 1, _
                    col As Integer = 1, foreground As UInteger, background As UInteger, _
                    mode As Integer = 0) As Integer 
  'mode 0 -> highlight at touch with cursor (default)
  'mode 1 -> highlight at click
  'mode 2 -> draw frame around text
 
  Dim As Integer mc, ml, wheel, buttons, textmin, textmax, x, compareColor, separatorpos, _
                 pressedButton = 0, returnValue = 0
  Static As Integer oldlin, oldcol
       
  If lin = 0 Then
     lin = oldlin
  ElseIf lin < 0 Then
     lin = oldlin - lin
  EndIf
 
  If col = 0 Then
     col = Pos
  ElseIf col < 0 Then
     col = oldcol - col
  EndIf
 
  oldlin = lin
  oldcol = col
     
  If separator = "" Then
     separatorpos = Len(text) 'whole text as return value
  Else
     separatorpos = InStr(text,separator) - 1 'text left from separator as return value
     col = col - separatorpos + 1 'position text at separator
  EndIf
 
  If col < 1 Then
     col = 1
  EndIf
   
  textmin = col - 2
   textmax = textmin + Len(text) + 1
   
   GetMouse (mc,ml,wheel,buttons)
  mc = mc / 8 'text column
  ml = ml / 8 'text line
   
  Select Case (mode And 1)
     Case 0 'highlight at touch
        If ml + 1 = lin Then 'mouse line = text line
           Select Case mc
              Case textmin To textmax 'cursor touches the text
                 returnValue Or= 8
                 PrintMenuItemInv() 'highlight menu item
                 If buttons Then 'mouse button pressed
                    returnValue Or= buttons
                    Do 'wait for release of the mouse button
                       GetMouse (mc,ml,wheel,buttons)
                    Loop While buttons
                 EndIf
                 Color foreground,background
                 Return returnValue
           End Select
        EndIf
     Case 1 'highlight at click
        If buttons Then 'mouse button pressed
           returnValue Or= buttons
           If ml + 1 = lin Then 'mouse line = text line
              Select Case mc
                 Case textmin To textmax 'cursor touches the text
                    returnValue Or= 8
                    PrintMenuItemInv() 'highlight menu item
                    Do 'wait for release of the mouse button
                       GetMouse (mc,ml,wheel,buttons)
                    Loop While buttons
                    Color foreground,background
                    Return returnValue    
              End Select
           EndIf
        EndIf
  End Select
 
  PrintMenuItem()
     
End Function

Regards
grindstone
Gablea
Posts: 1049
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Basic GUI designer

Postby Gablea » Jun 30, 2015 8:35

@grindstone
Thanks I shall look into that code :)

@BasicCoder2
Yes FB DOS Does support mouse but I can never get the X and Y of the mouse to match up with the command buttons
Lothar Schirm
Posts: 333
Joined: Sep 28, 2013 15:08
Location: Bavaria, Germany

Re: Basic GUI designer

Postby Lothar Schirm » Jun 30, 2015 14:01

I do not understand your problem. "GetMouse" delivers the x and y position of the mouse, and you only have to check whether these are inside you button. Example:

Code: Select all

ScreenRes 640, 480
Width 80, 30

Dim As Integer mx, my, mb

'Draw a button:
Line (200, 100) - (300, 120),,B
Draw String (210, 102), "Click me!"

'Request the mouse until the window is closed:
Do
  GetMouse(mx, my, , mb)
  If mb = 1 And mx > 200 And mx < 300 And my > 100 And my < 120 Then
    Print "Button was clicked!"
    'Wait until mouse button is released:
    Do
      GetMouse(mx, my, , mb)
    Loop Until mb = 0
  End If
  Sleep 1
Loop Until Inkey = Chr(255, 107)

End


Or does this not work in DOS? Can you give a short example of your problem?
Gablea
Posts: 1049
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Basic GUI designer

Postby Gablea » Jun 30, 2015 14:41

This is the bit I can not work out very well

If mb = 1 And mx > 200 And mx < 300 And my > 100 And my < 120 Then


how do I get the figures etc is there not a simple sub function that controls this?

And How do I make the buttons move up and down?
Lothar Schirm
Posts: 333
Joined: Sep 28, 2013 15:08
Location: Bavaria, Germany

Re: Basic GUI designer

Postby Lothar Schirm » Jun 30, 2015 16:37

You may also study Westbeams example: http://www.freebasic.net/forum/viewtopic.php?f=7&t=15438. Building a GUI with Freebasic is not as comfortable as with Visual Basic where you write only code for subs which handle everything. You have several possibilities:

1. You can write the code for yourself, using a FreeBasic graphics window. In this case you have to write everything for yourself: Creation of textboxes, buttons etc. and also the subs which handle everything. There are some libraries which use this method (e.g. Muttonheads sGUI (http://www.freebasic.net/forum/viewtopic.php?f=8&t=13903&hilit=sGUI or my own GUI (http://www.freebasic.net/forum/viewtopic.php?f=7&t=23202&hilit=sGUI).

2. You can use a library (e.g. FLTK or GTK+) where you have less work.

3. You can use a comfortable GUI designer, e.g. FireFly (for Windows only). Here you have to write code only for subs which handle everything, similiar to Visual Basic. There is also a GUI designer for GTK+ (Glade).

Nearly all possibilities to create a GUI in Freebasic have been discussed here: http://www.freebasic.net/forum/viewtopic.php?f=2&t=23186.

What do you mean by moving the buttons up and down? Do you mean sprites (for games or animations)?
Gablea
Posts: 1049
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Basic GUI designer

Postby Gablea » Jun 30, 2015 22:48

sorry. what i mean when i cal move up and down. is the effect if the button being clicked. (like in visual basic when you click the mouse button the command button goes down)

sorry for any spelling errors this was typed on my iPhone.
BasicCoder2
Posts: 3558
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Basic GUI designer

Postby BasicCoder2 » Jun 30, 2015 23:16

Something like this:

Code: Select all

screenres 640,480,32
color rgb(0,0,0),rgb(100,100,255):cls

dim as integer mx,my,mb  'mouse variables


type BUTTON
    as integer x
    as integer y
    as integer w
    as integer h
    as integer a   'mouse down on button
    as string  t
end type

dim as BUTTON btn1
btn1.x = 100
btn1.y = 100
btn1.t = "EXIT"
btn1.w = len(btn1.t)*8+8
btn1.h = 16

sub drawButton(btn as BUTTON)
    dim as uinteger c1,c2
    if btn.a = 1 then
        c1 = rgb(20,20,20)
        c2 = rgb(200,200,200)
    else
        c1 = rgb(200,200,200)
        c2 = rgb(20,20,20)
    end if
    line (btn.x,btn.y)-(btn.x+btn.w,btn.y+btn.h),rgb(100,100,100),bf
    line (btn.x,btn.y)-(btn.x+btn.w,btn.y),c1  'top line
    line (btn.x,btn.y)-(btn.x,btn.y+btn.h),c1  'left line
    line (btn.x,btn.y+btn.h)-(btn.x+btn.w,btn.y+btn.h),c2
    line (btn.x+btn.w,btn.y)-(btn.x+btn.w,btn.y+btn.h),c2
    draw string (btn.x+4,btn.y+4),btn.t,rgb(255,255,255)
end sub

locate 2,2
print "CLICK BUTTON OR ESC KEY TO END"
drawButton(btn1)
do
    getmouse mx,my,,mb
    if mb=1 then
        if mx > btn1.x and mx < btn1.x + btn1.w and my > btn1.y and my < btn1.y + btn1.h then
            btn1.a = 1
            drawButton(btn1)
            while mb = 1
                getmouse mx,my,,mb
            wend
            btn1.a = 0
            drawButton(btn1)
        end if
    end if
    sleep 2
loop until multikey(&H01)


sleep
fxm
Posts: 9698
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Basic GUI designer

Postby fxm » Jul 01, 2015 7:27

A small improvement that I am using usually:
- Only one line is changed:
draw string (btn.x+5-btn.a,btn.y+5-btn.a),btn.t,rgb(255,255,255)
- This small change gives a better impression (in perspective) that the button is really pushed!

Code: Select all

screenres 640,480,32
color rgb(0,0,0),rgb(100,100,255):cls

dim as integer mx,my,mb  'mouse variables


type BUTTON
    as integer x
    as integer y
    as integer w
    as integer h
    as integer a   'mouse down on button
    as string  t
end type

dim as BUTTON btn1
btn1.x = 100
btn1.y = 100
btn1.t = "EXIT"
btn1.w = len(btn1.t)*8+8
btn1.h = 16

sub drawButton(btn as BUTTON)
    dim as uinteger c1,c2
    if btn.a = 1 then
        c1 = rgb(20,20,20)
        c2 = rgb(200,200,200)
    else
        c1 = rgb(200,200,200)
        c2 = rgb(20,20,20)
    end if
    line (btn.x,btn.y)-(btn.x+btn.w,btn.y+btn.h),rgb(100,100,100),bf
    line (btn.x,btn.y)-(btn.x+btn.w,btn.y),c1  'top line
    line (btn.x,btn.y)-(btn.x,btn.y+btn.h),c1  'left line
    line (btn.x,btn.y+btn.h)-(btn.x+btn.w,btn.y+btn.h),c2
    line (btn.x+btn.w,btn.y)-(btn.x+btn.w,btn.y+btn.h),c2
    draw string (btn.x+5-btn.a,btn.y+5-btn.a),btn.t,rgb(255,255,255)
end sub

locate 2,2
print "CLICK BUTTON OR ESC KEY TO END"
drawButton(btn1)
do
    getmouse mx,my,,mb
    if mb=1 then
        if mx > btn1.x and mx < btn1.x + btn1.w and my > btn1.y and my < btn1.y + btn1.h then
            btn1.a = 1
            drawButton(btn1)
            while mb = 1
                getmouse mx,my,,mb
            wend
            btn1.a = 0
            drawButton(btn1)
        end if
    end if
    sleep 2
loop until multikey(&H01)


sleep

Return to “General”

Who is online

Users browsing this forum: deltarho[1859], srvaldez and 4 guests