FLTK Form Designer (very basic)

User projects written in or related to FreeBASIC.
ike
Posts: 387
Joined: Jan 17, 2011 18:59

FLTK Form Designer (very basic)

Postby ike » May 29, 2015 3:50

https://www.youtube.com/watch?v=Sa2KSwFufiE
https://youtu.be/S56D1fg23xw
split.bi

Code: Select all

DECLARE FUNCTION split(src AS STRING, _
                       del AS STRING, _
                       res() AS STRING) AS INTEGER
'':::::  v1ctor
FUNCTION split(src AS STRING, _
               del AS STRING, _
               res() AS STRING) AS INTEGER

CONST MAXDELIMITERS = 256       
       
        DIM AS INTEGER char, d, i, s, l
        DIM AS INTEGER delpos(0 TO MAXDELIMITERS+1)

        char = ASC( del )

        '' find all delimiters
        d = 0
        delpos(d) = 0
        FOR i = 0 TO LEN( src )-1
                IF src[i] = char THEN
                        d += 1
                        IF( d > MAXDELIMITERS ) THEN
                                EXIT FOR
                        END IF
                        delpos(d) = i + 1
                END IF
        NEXT
       
        '' allocate the result array
        REDIM res(0 TO d)
       
        IF( d = 0 ) THEN
                res(0) = src
                RETURN 1
        END IF
               
        '' copy strings
        delpos(d+1) = LEN( src ) + 1
        FOR i = 0 TO d

                s = delpos(i) + 1
                l = delpos(i+1) - s
                IF( l > 0 ) THEN
                        res(i) = MID$( src, s, l )
                END IF
               
        NEXT

        FUNCTION = d + 1
       
END FUNCTION



/'
DIM AS STRING res()

PRINT "strings:"; split( ",abc,defgh,,ij,k,lmnopq,", ",", res() )
DIM AS INTEGER i
FOR i = 0 TO UBOUND(res)
   PRINT "|"; res(i); "|"
NEXT i
'/










SUB STRreplace(BYREF T AS STRING, BYREF I AS STRING, BYREF S AS STRING, BYVAL A AS INTEGER = 1)
  VAR p = INSTR(A, T, I), li = LEN(I), ls = LEN(S) : IF li = ls THEN li = 0
  WHILE p
    IF li THEN T = LEFT(T, p - 1) & S & MID(T, p + li) ELSE MID(T, p) = S
    p = INSTR(p + ls, T, I)
  WEND
END SUB

'STRreplace( s, "darryl","Darryl" )

FUNCTION str_replace(BYREF haystack AS STRING, BYREF needle1 AS STRING, BYREF needle2 AS STRING) AS STRING
    'tjf
    DIM AS INTEGER len1 = LEN(needle1), len2 = LEN(needle2)
    DIM AS INTEGER i
   
    DIM AS STRING haystack_ = haystack
   
    i = INSTR(haystack_, needle1)
    WHILE i
       
        haystack_ = LEFT(haystack_, i - 1) _
                  & needle2 _
                  & MID(haystack_, i + len1)
       
        i = INSTR(i + len2, haystack_, needle1)
       
    WEND
   
    FUNCTION = haystack_
   
END FUNCTION

/'
PRINT str_replace("FreeBASIC is awesome BASIC language", "e", "3")
PRINT str_replace("FreeBASIC is awesome BASIC language", "BASIC", "basic")
PRINT str_replace("FreeBASIC is awesome BASIC language", "e", "ee") 'test for infinite replacing
'/





FUNCTION PACKIT(s AS STRING, deli AS STRING, ind AS INTEGER, newvalue AS STRING) AS STRING
DIM AS STRING res(), ret
DIM AS INTEGER i
split(s, deli, res())
res(ind)=newvalue
FOR i = 0 TO UBOUND(res)-1
ret+=res(i)+deli
NEXT i
RETURN ret
END FUNCTION

FUNCTION SIZEIT(s AS STRING, deli AS STRING) AS INTEGER
DIM AS INTEGER i, cnt=0
DIM AS STRING ret, znak
FOR i = 1 TO LEN(s)
    znak = MID(s, i, 1)
    IF znak = deli THEN cnt+=1
NEXT i
RETURN cnt
END FUNCTION

FUNCTION SPLITIT(s AS STRING, deli AS STRING, ind AS INTEGER) AS STRING
DIM AS INTEGER i, cnt=0, start1, end1
DIM AS STRING ret, znak
FOR i = 1 TO LEN(s)
    znak = MID(s, i, 1)
    IF znak = deli THEN cnt+=1
    IF cnt = ind AND start1 = 0 THEN start1 = i
    IF cnt = ind+1 AND end1 = 0 THEN end1 = i
NEXT i
IF end1 = 0 AND start1=0 THEN
    RETURN "OUT"
END IF

IF end1 = 0 THEN
    end1=LEN(s)
    ret =  MID(s, start1+1)
    RETURN ret
END IF

IF ind = 0 THEN
    ret =  MID(s,start1, end1-start1)
ELSE
    ret =  MID(s,start1+1, end1-start1-1)
END IF
RETURN ret
END FUNCTION





main.bas

Code: Select all

'#########################################################################
#include once "vbcompat.bi"
#include once "fltk-c.bi"
#include once "split.bi"
#include once "string.bi"

'#define MAX_FILES 100

ENUM STYL_
  XYWHT = 4 
  XYWH = 3
  WHT = 2
  WH = 1
END ENUM

TYPE KEYDATA
    kkk AS STRING
    template AS STRING
    desc AS STRING
END TYPE

'DIM SHARED AS STRING fbc_path, filenames(MAX_FILES)

DIM SHARED AS INTEGER fcnt, whichtab

DIM SHARED AS STRING aaa(), filetoedit
'DIM SHARED AS Fl_Text_Buffer PTR buf(MAX_FILES)

#include once "form1.bi"
#include once "main.bi"





FormMAINCREATE
'CREATE_ALL_FORMS
FRM_DESIGNCREATE

FormMAINSHOW
Fl_Run
'#########################################################################



main.bi

Code: Select all

namespace MAIN
DIM AS Fl_Input PTR infilename
DIM AS Fl_Input PTR innew
DIM AS Fl_Button PTR btn2
DIM AS Fl_Button PTR btn1
DIM AS Fl_Window PTR win
DIM AS Fl_FILE_BROWSER PTR fbr
end namespace
'#############################################################
SUB MAIN_btn1_cb CDECL (widget AS FL_WIDGET PTR)
filetoedit = *Fl_Input_GetValue(MAIN.infilename)
if instr(filetoedit, ".bi") > 0 then
   FormDesignShow
else
   beep
end if
END SUB


SUB MAIN_btn2_cb CDECL (widget AS FL_WIDGET PTR)
DIM AS STRING txt, fn
txt =*Fl_Input_GetValue(MAIN.innew)
fn=exepath()+"\"+txt
DIM AS INTEGER ret = Fl_Input_SetValue (MAIN.infilename,fn)
open fn for output as #1
Print #1, !"\'New form"
close #1
filetoedit = fn
if instr(filetoedit, ".bi") > 0 then
   FormDesignShow
else
   beep
end if
END SUB


SUB MAIN_infilename_cb CDECL (widget AS FL_WIDGET PTR)
END SUB


SUB Callback CDECL (widget AS FL_WIDGET PTR)
   DIM AS STRING txt
   DIM AS INTEGER SelectedLine = Fl_BrowserGetValue(MAIN.fbr)
   txt = *Fl_BrowserGetText(MAIN.fbr,SelectedLine)

   DIM AS INTEGER ret = Fl_Input_SetValue (MAIN.infilename,exepath()+"\"+txt)


END SUB

'marker01
'#############################################################
SUB FormMAINCREATE()
IF MAIN.win THEN RETURN
DIM AS INTEGER xx,yy,ww,hh
Fl_ScreenWorkAreaXYWH xx, yy, ww, hh
MAIN.win = Fl_Double_windowExNew2((ww-690)/2, (hh-680)/2, 690, 680, "Form Select or Create New")
'Fl_WindowSetModal (MAIN.win)
MAIN.btn1 = Fl_ButtonNew(570, 10, 110, 25, "Edit Form")
Fl_WidgetSetCallback0 MAIN.btn1, @MAIN_btn1_cb
MAIN.btn2 = Fl_ButtonNew(520, 40, 160, 25, "Create New Form")
Fl_WidgetSetCallback0 MAIN.btn2, @MAIN_btn2_cb

MAIN.infilename = Fl_InputNew(130, 10, 430, 25, "File Name")
Fl_WidgetSetCallback0 MAIN.infilename, @MAIN_infilename_cb
Fl_Input_SetTextColor  MAIN.infilename, FL_BLUE
Fl_Input_SetTextFont  MAIN.infilename, Fl_COURIER
Fl_Input_SetTextSize  MAIN.infilename, 14
Fl_WidgetSetColor MAIN.infilename, FL_YELLOW
Fl_WidgetSetWhen MAIN.infilename, FL_WHEN_CHANGED

MAIN.innew = Fl_InputNew(130, 40, 380, 25, "New File Name")
Fl_Input_SetTextColor  MAIN.innew, FL_BLUE
Fl_Input_SetTextFont  MAIN.innew, Fl_COURIER
Fl_Input_SetTextSize  MAIN.innew, 14
Fl_WidgetSetColor MAIN.innew, FL_GREEN


MAIN.fbr = Fl_File_BrowserNew(10, 80, 670, 590)
Fl_File_BrowserSetFiletype (MAIN.fbr, FL_FILECHOOSER_SINGLE)
Fl_WidgetSetType         MAIN.fbr, FL_HOLDBROWSER
Fl_File_BrowserSetFilter MAIN.fbr, "*.bi"
   Fl_Browser_SetHasScrollbar MAIN.fbr,FL_SCROLL_VERTICAL
   Fl_File_BrowserLoad      MAIN.fbr, EXEPATH() & "\"
   Fl_Browser_SetTextFont(MAIN.fbr, Fl_COURIER) 
   Fl_Browser_SetTextsize(MAIN.fbr, 18)

Fl_File_BrowserSetFiletype MAIN.fbr,FL_FILES

Fl_WidgetSetCallback0 MAIN.fbr, @Callback

'marker00
Fl_GroupEnd MAIN.win
Fl_GroupSetResizable(MAIN.win, MAIN.fbr)
END SUB

SUB FormMAINSHOW()
Fl_Input_SetValue (MAIN.infilename, exepath())
Fl_WindowShow MAIN.win
END SUB






form1.bi

Code: Select all

NAMESPACE DZ
   DIM AS STRING NMSPC
   DIM AS INTEGER widgets_(0 TO 3, 0 TO 250)
   DIM AS INTEGER numberofwidgets
   DIM AS FL_BUTTON PTR btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9
   DIM AS FL_BUTTON PTR btnSkipToNextWidget, btnMemory, btnList, btn22, btnRELOAD, btnSAVECH
   DIM AS FL_INPUT PTR in1
   DIM AS Fl_Scroll PTR scr1
   DIM AS Fl_BoxEx  PTR box1
   DIM AS FL_BROWSER PTR brw_DESIGN
   DIM AS Fl_Counter PTR countXPOSITION, countYPOSITION, countWIDTH, countHEIGHT, countLEADSPACES

   DIM AS STRING TT_(250), line_(250) , l1_(250), l2_(250), l3_(250)
   DIM SHARED AS INTEGER x_(250), y_(250), w_(250), h_(250), where2save(250), style_(250)

   DIM SHARED AS INTEGER nLINES = -1, poz_, i_
   DIM SHARED AS Fl_Double_Window PTR win
END NAMESPACE
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
FUNCTION kount(m AS STRING, n AS STRING) AS INTEGER
   DIM AS INTEGER cnt, i
   FOR i = 1 TO LEN(m)
      IF MID(m, i, 1) = n THEN
      cnt+=1
      END IF
   NEXT i
   RETURN cnt
END FUNCTION
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB FILL_DATA_FROM_LIST_TO_MEMORY(a AS STRING, pp AS INTEGER)
   DIM AS INTEGER pos1, pos2, ttt
   DIM AS INTEGER i, sty_
   DIM AS STRING a1_,a2_, a3_
   DIM AS INTEGER x, y, w, h
   DIM tekst AS STRING

   pos1 = INSTR(a, "(")
   pos2 = INSTR(a, ")")

   IF kount(a, "(") <> 1 THEN RETURN
   IF kount(a, ")") <> 1 THEN RETURN

   IF pos1>0 AND pos2 > 0 THEN

   DZ.nLines = DZ.nLines + 1
   a1_ = MID(a, 1, pos1)
   a2_ = MID(a, pos1+1, pos2-pos1-1)
   a3_ = MID(a, pos2)
   ttt = split (a2_, ",", aaa())

   IF UBOUND(aaa) = 4 THEN
      x = VALINT(aaa(0))
      y = VALINT(aaa(1))
      w = VALINT(aaa(2))
      h = VALINT(aaa(3))
      tekst = aaa(4)
      sty_ = XYWHT
   END IF
   IF UBOUND(aaa) = 2 THEN
      x = 0: y = 0
      w = VALINT(aaa(0))
      h = VALINT(aaa(1))
      sty_ = WHT
      tekst = aaa(2)
   END IF
   IF UBOUND(aaa) = 3 THEN
      x = VALINT(aaa(0))
      y = VALINT(aaa(1))
      w = VALINT(aaa(2))
      h = VALINT(aaa(3))
      tekst = "_"
      sty_ = XYWH
   END IF

   DZ.l1_(DZ.nLines) = a1_
   DZ.l2_(DZ.nLines) = a2_
   DZ.l3_(DZ.nLines) = a3_
   DZ.tt_(DZ.nLines) = TRIM(tekst)
   DZ.x_(DZ.nLines) = x
   DZ.y_(DZ.nLines) = y
   DZ.w_(DZ.nLines) = w
   DZ.h_(DZ.nLines) = h
   DZ.where2save(DZ.nLines) = pp
   DZ.style_(DZ.nLines) = sty_
   END IF
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB DRAW_IT()
   DIM  AS INTEGER i
   DIM AS INTEGER x =  Fl_WidgetGetX(DZ.box1), y =  Fl_WidgetGetY(DZ.box1), w = Fl_WidgetGetW(DZ.box1), h = Fl_WidgetGetH(DZ.box1)
   DIM AS INTEGER x2=x+w-1, y2=y+h-1, xx1, yy1, xx2, yy2

   'DrawRectFillColor x, y, w, h, FL_BLACK
   DIM AS STRING lll
   DIM AS FL_color kolor

   DZ.numberofwidgets = -1

   FOR i = 0 TO DZ.nLines
      lll=DZ.l1_(i)

      DZ.numberofwidgets+=1

      DZ.widgets_(0,DZ.numberofwidgets) = DZ.x_(i)
      DZ.widgets_(1,DZ.numberofwidgets) = DZ.y_(i)
      DZ.widgets_(2,DZ.numberofwidgets) = DZ.x_(i) + DZ.w_(i)
      DZ.widgets_(3,DZ.numberofwidgets) = DZ.y_(i) + DZ.h_(i)


      IF i = dz.poz_ THEN
        DrawRectColor DZ.x_(i)+x, DZ.y_(i)+y, DZ.w_(i), DZ.h_(i), Fl_RED
        DrawStr DZ.TT_(i), DZ.x_(i)+x + 10, DZ.y_(i)+y + 15
      ELSE
        kolor = FL_GREEN
        IF INSTR(lll,"FL_GROUP") > 0 THEN kolor = FL_YELLOW
        IF INSTR(lll,"FL_BUTTON") > 0 THEN kolor = FL_BLUE
        IF INSTR(lll,"BROWSER") > 0 THEN kolor = Fl_MAGENTA

        DrawRectColor DZ.x_(i)+x, DZ.y_(i)+y, DZ.w_(i), DZ.h_(i), kolor

        'a'a'a'a'a
        DrawStr DZ.TT_(i), DZ.x_(i)+x + 10, DZ.y_(i)+y + 15
      END IF
   NEXT i


'? "=="
'for i = 0 to DZ.numberofwidgets
'? DZ.widgets_(0,i),DZ.widgets_(1,i)
'? DZ.widgets_(2,i),DZ.widgets_(3,i)
'next i
'? "=="
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB btnList_Clicked CDECL (me AS FL_WIDGET PTR)
   DIM AS STRING tekst, newl2
   DIM AS INTEGER i, ws, j
   FOR i = 0 TO DZ.nLines

      IF DZ.style_(i)= WHT THEN
         newl2= STR(DZ.w_(i)) + ", " + STR(DZ.h_(i)) + ", " + DZ.TT_(i)
      END IF

      IF DZ.style_(i)= XYWHT THEN
         newl2= STR(DZ.x_(i)) + ", " + STR(DZ.y_(i)) + ", " + STR(DZ.w_(i)) + ", " + STR(DZ.h_(i)) + ", " + DZ.TT_(i)
      END IF

      IF DZ.style_(i)= XYWH THEN
         newl2= STR(DZ.x_(i)) + ", " + STR(DZ.y_(i)) + ", " + STR(DZ.w_(i)) + ", " + STR(DZ.h_(i))
      END IF
     
      tekst = DZ.l1_(i) + newl2 + DZ.l3_(i)
      ws = DZ.where2save(i)

      Fl_BrowserSetText(DZ.brw_DESIGN, ws, tekst)
     
   NEXT i
   Fl_WidgetRedraw(DZ.box1) 'draw_it
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB btnMemory_Clicked CDECL (me AS FL_WIDGET PTR)
   DIM txt AS STRING
   DIM AS INTEGER nitems = Fl_BrowserGetSize(DZ.brw_DESIGN)
   IF nItems>0 THEN
      DZ.nLines = -1
      FOR item AS INTEGER = 1 TO nItems
         IF Fl_BrowserSelected(DZ.brw_DESIGN, item) THEN
            txt = *Fl_BrowserGetText(DZ.brw_DESIGN,item)

            FILL_DATA_FROM_LIST_TO_MEMORY txt, item
         END IF
      NEXT item
   END IF 
   IF DZ.nLines > -1 THEN
      DZ.poz_=0
      Fl_ValuatorSetValue(CPTR(Fl_Valuator PTR, DZ.countXPOSITION), DZ.x_(0))
      Fl_ValuatorSetValue(CPTR(Fl_Valuator PTR, DZ.countYPOSITION), DZ.y_(0))
      Fl_ValuatorSetValue(CPTR(Fl_Valuator PTR, DZ.countWIDTH), DZ.w_(0))
      Fl_ValuatorSetValue(CPTR(Fl_Valuator PTR, DZ.countHEIGHT), DZ.h_(0))
      Fl_WindowMakeCurrent Fl_WidgetWindow(DZ.box1)
      Fl_WidgetRedraw(DZ.box1) 'draw_it
   END IF
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB btnSkipToNextWidget_Clicked CDECL (me AS FL_WIDGET PTR)
   DZ.poz_+=1
   IF DZ.poz_ > DZ.nLines THEN DZ.poz_ = 0
   Fl_ValuatorSetValue(CPTR(Fl_Valuator PTR, DZ.countXPOSITION), DZ.x_(DZ.poz_))
   Fl_ValuatorSetValue(CPTR(Fl_Valuator PTR, DZ.countYPOSITION), DZ.y_(DZ.poz_))
   Fl_ValuatorSetValue(CPTR(Fl_Valuator PTR, DZ.countWIDTH), DZ.w_(DZ.poz_))
   Fl_ValuatorSetValue(CPTR(Fl_Valuator PTR, DZ.countHEIGHT), DZ.h_(DZ.poz_))
   Fl_WidgetRedraw(DZ.box1) 'draw_it
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB countXPOSITION_Clicked CDECL (widget AS FL_WIDGET PTR)
   DZ.x_(DZ.poz_) = Fl_ValuatorGetValue(CPTR(Fl_Valuator PTR, DZ.countXPOSITION))
   Fl_WidgetRedraw(DZ.box1) 'draw_it
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB countYPOSITION_Clicked CDECL (widget AS FL_WIDGET PTR)
   DZ.y_(DZ.poz_) = Fl_ValuatorGetValue(CPTR(Fl_Valuator PTR, DZ.countYPOSITION))
   Fl_WidgetRedraw(DZ.box1) 'draw_it
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB countWIDTH_Clicked CDECL (widget AS FL_WIDGET PTR)
   DZ.w_(DZ.poz_) = Fl_ValuatorGetValue(CPTR(Fl_Valuator PTR, DZ.countWIDTH))
   Fl_WidgetRedraw(DZ.box1)  'draw_it
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB countHEIGHT_Clicked CDECL (widget AS FL_WIDGET PTR)
   DZ.h_(DZ.poz_) = Fl_ValuatorGetValue(CPTR(Fl_Valuator PTR, DZ.countHEIGHT))
   Fl_WidgetRedraw(DZ.box1) 'draw_it
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'SUB btnREDRAWCB CDECL (widget AS FL_WIDGET PTR)
'   DRAW_IT
'END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB btnSAVECHCB CDECL (widget AS FL_WIDGET PTR)
   DIM AS STRING fn
   fn = filetoedit

   'Fl_BrowserSave(brw_Design, strptr(fn))
   DIM AS INTEGER nitems = Fl_BrowserGetSize(DZ.brw_Design), item
   OPEN fn FOR OUTPUT AS #1
   
   IF nItems>0 THEN
      FOR item AS INTEGER = 1 TO nItems
         PRINT #1, *Fl_BrowserGetText(DZ.brw_Design, item)
      NEXT item   
   END IF
   CLOSE #1
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB btnRELOADCB CDECL (widget AS FL_WIDGET PTR)
   DIM AS STRING fn
   fn = filetoedit
   Fl_BrowserLoad(DZ.brw_Design, STRPTR(fn))
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB btn22_KL CDECL (widget AS FL_WIDGET PTR)
   DIM AS STRING txt
   DIM AS INTEGER i, item, poz
   Fl_Browser_Deselect (DZ.brw_DESIGN, 0) ' 0 dont do a callback
   FOR i =1 TO Fl_BrowserGetSize(DZ.brw_DESIGN)
      txt = *Fl_BrowserGetText(DZ.brw_DESIGN, i)

      poz= INSTR(1, txt, "ew(")
      IF poz > 0 THEN
         Fl_BrowserSelect DZ.brw_DESIGN, i
         'Fl_BrowserSetValue
      ELSE

      END IF
   NEXT i
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
FUNCTION find_in_browser(a AS STRING) AS INTEGER
   DIM AS INTEGER i, poz
   DIM AS STRING lst, res()
   FOR i =1 TO Fl_BrowserGetSize(DZ.brw_DESIGN)

      lst= *Fl_BrowserGetText(DZ.brw_DESIGN, i)

      IF INSTR(1, lst, a) > 0 THEN
         poz = i
         IF a = "namespace" THEN
            split(lst, " ", res())
            DZ.NMSPC = TRIM(res(1))
         END IF
         EXIT FOR
      END IF 

   NEXT i
   RETURN poz
END FUNCTION
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB btn1_Click CDECL (widget AS FL_WIDGET PTR)       ' create new window
   DIM AS STRING ns = *Fl_Input_GetValue(DZ.in1)
   Fl_BrowserClear DZ.brw_DESIGN
   Fl_BrowserAdd DZ.brw_DESIGN, "namespace " + ns
   Fl_BrowserAdd DZ.brw_DESIGN, "DIM AS Fl_Window PTR win"
   Fl_BrowserAdd DZ.brw_DESIGN, "end namespace"
   Fl_BrowserAdd DZ.brw_DESIGN, !"\'#############################################################"
   Fl_BrowserAdd DZ.brw_DESIGN, !"\'marker01"
   Fl_BrowserAdd DZ.brw_DESIGN, !"\'#############################################################"
   Fl_BrowserAdd DZ.brw_DESIGN, "SUB Form"+ns+"CREATE()"
   Fl_BrowserAdd DZ.brw_DESIGN, "IF " +ns+ ".win THEN RETURN"
   Fl_BrowserAdd DZ.brw_DESIGN, "DIM AS INTEGER xx,yy,ww,hh"
   Fl_BrowserAdd DZ.brw_DESIGN, "Fl_ScreenWorkAreaXYWH xx, yy, ww, hh"
   Fl_BrowserAdd DZ.brw_DESIGN, ns + !".win = Fl_Double_windowExNew2((ww-300)/2, (hh-180)/2, 300, 180, \"Form Caption\")"

   Fl_BrowserAdd DZ.brw_DESIGN, "Fl_WindowSetModal ("+ns+".win)"
   Fl_BrowserAdd DZ.brw_DESIGN, !"\'marker00"
   Fl_BrowserAdd DZ.brw_DESIGN, "Fl_GroupEnd "+ns+".win"
   Fl_BrowserAdd DZ.brw_DESIGN, "END SUB"

   Fl_BrowserAdd DZ.brw_DESIGN, "SUB Form"+ns+"SHOW()"
   Fl_BrowserAdd DZ.brw_DESIGN, "Fl_WindowShow "+ns+".win"
   Fl_BrowserAdd DZ.brw_DESIGN, "END SUB"
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB btn2_Click CDECL (widget AS FL_WIDGET PTR)
   DIM AS STRING ns = *Fl_Input_GetValue(DZ.in1), toins
   DIM AS INTEGER poz
   poz = find_in_browser("namespace")
   Fl_BrowserInsert DZ.brw_DESIGN, poz+1, "DIM AS Fl_Button PTR btn"+ns

   poz = find_in_browser("marker00")
   toins = "Fl_WidgetSetCallback0 "+DZ.NMSPC+".btnHHH, @"+DZ.nmspc+"_btn"+ns+"_cb "
   strreplace(toins, "HHH", ns)
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toins
   toins = DZ.nmspc + !".btnHHH = Fl_ButtonNew(0, 0, 50, 25, \"HHH\") "
   strreplace(toins, "HHH", ns)
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toINS

   poz = find_in_browser("marker01")
   toins = "SUB "+ DZ.nmspc + "_btn"+ns+"_cb" + !" CDECL (widget AS FL_WIDGET PTR)"
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toINS

   poz = find_in_browser("marker01")
   toins = "END SUB "
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toINS

END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB btn7_Click CDECL (widget AS FL_WIDGET PTR)
   DIM AS STRING ns = *Fl_Input_GetValue(DZ.in1), toins
   DIM AS INTEGER poz
   poz = find_in_browser("namespace")
   Fl_BrowserInsert DZ.brw_DESIGN, poz+1, "DIM AS Fl_Radio_Round_Button PTR rr"+ns

   poz = find_in_browser("marker00")
   toins = DZ.nmspc + !".rrHHH = Fl_Radio_Round_ButtonNew(0, 0, 50, 25, \"HHH\") "
   strreplace(toins, "HHH", ns)
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toINS
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB btn8_Click CDECL (widget AS FL_WIDGET PTR)
   DIM AS STRING ns = *Fl_Input_GetValue(DZ.in1), toins
   DIM AS INTEGER poz
   poz = find_in_browser("namespace")
   Fl_BrowserInsert DZ.brw_DESIGN, poz+1, "DIM AS Fl_Radio_Light_Button PTR rl"+ns

   poz = find_in_browser("marker00")
   toins = DZ.nmspc + !".rlHHH = Fl_Radio_Light_ButtonNew(0, 0, 50, 25, \"HHH\") "
   strreplace(toins, "HHH", ns)
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toINS
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB btn9_Click CDECL (widget AS FL_WIDGET PTR)
   DIM AS STRING ns = *Fl_Input_GetValue(DZ.in1), toins, where, res()
   DIM AS INTEGER poz, cnt=0, i, poz1, poz2

     FOR i = 1 TO Fl_BrowserGetSize(DZ.brw_DESIGN)
      IF Fl_BrowserSelected(DZ.brw_DESIGN, i) THEN
         where = where + STR(i) + "|"
         cnt+=1
      END IF
     NEXT i

   IF cnt <> 2 THEN
   flMessage "EXACTLY two items has to be selected"
   RETURN
   END IF

   split(where,"|", res())
   poz1=VALINT(res(0))
   poz2=VALINT(res(1))
   poz = find_in_browser("namespace")
   Fl_BrowserInsert DZ.brw_DESIGN, poz+1, "dim as Fl_Group ptr gr"+ns

   poz = poz2+2
   toins = "Fl_GroupEnd " + DZ.nmspc  + ".gr" +ns
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toINS

   poz = poz1+1
   toins = "Fl_GroupBegin " + DZ.nmspc  + ".gr" +ns
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toINS

   poz = poz1+1
   toins = DZ.nmspc + !".grHHH = Fl_GroupNew(0, 0, 50, 25, \"HHH\") "
   strreplace(toins, "HHH", ns)
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toINS
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB btn3_Click CDECL (widget AS FL_WIDGET PTR)
   DIM AS STRING ns = *Fl_Input_GetValue(DZ.in1), toins
   DIM AS INTEGER poz

   poz = find_in_browser("namespace")
   Fl_BrowserInsert DZ.brw_DESIGN, poz+1, "DIM AS Fl_Input PTR in"+ns

   poz = find_in_browser("marker00")

   toins = "Fl_WidgetSetWhen "+DZ.nmspc+".inHHH, FL_WHEN_CHANGED"
   strreplace(toins, "HHH", ns)
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toins

   toins = "Fl_WidgetSetCallback0 "+DZ.NMSPC+".inHHH, @"+DZ.nmspc+"_in"+ns+"_cb "
   strreplace(toins, "HHH", ns)
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toins
   toins = DZ.nmspc + !".inHHH = Fl_InputNew(0, 0, 50, 25, \"HHH\") "
   strreplace(toins, "HHH", ns)
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toINS

   poz = find_in_browser("marker01")
   toins = "SUB "+ DZ.nmspc + "_in"+ns+"_cb" + !" CDECL (widget AS FL_WIDGET PTR)"
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toINS

   poz = find_in_browser("marker01")
   toins = "END SUB "
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toINS
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB btn4_Click CDECL (widget AS FL_WIDGET PTR)
   DIM AS STRING ns = *Fl_Input_GetValue(DZ.in1), toins
   DIM AS INTEGER poz

   poz = find_in_browser("namespace")
   Fl_BrowserInsert DZ.brw_DESIGN, poz+1, "DIM AS Fl_Browser PTR brw"+ns
   poz = find_in_browser("marker00")

   toins = "Fl_WidgetSetType " + DZ.nmspc+"_brw"+ns +", FL_HOLDBROWSER"
   strreplace(toins, "HHH", ns)
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toins

   toins = "Fl_WidgetSetCallback0 "+DZ.NMSPC+".brwHHH, @"+DZ.nmspc+"_brw"+ns+"_cb "
   strreplace(toins, "HHH", ns)
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toins

   toins = DZ.nmspc + !".brwHHH = Fl_BrowserNew(0, 0, 50, 25) "
   strreplace(toins, "HHH", ns)
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toINS

   poz = find_in_browser("marker01")
   toins = "SUB "+ DZ.nmspc + "_brw"+ns+"_cb" + !" CDECL (widget AS FL_WIDGET PTR)"
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toINS

   poz = find_in_browser("marker01")
   toins = "END SUB "
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toINS
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB btn5_Click CDECL (widget AS FL_WIDGET PTR)
   DIM AS STRING ns = *Fl_Input_GetValue(DZ.in1), toins
   DIM AS INTEGER poz
   poz = find_in_browser("namespace")
   Fl_BrowserInsert DZ.brw_DESIGN, poz+1, "DIM AS Fl_Check_Button PTR chk"+ns

   poz = find_in_browser("marker00")
   toins = DZ.nmspc + !".chkHHH = Fl_Check_ButtonNew(0, 0, 50, 25, \"HHH\") "
   strreplace(toins, "HHH", ns)
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toINS
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB btn6_Click CDECL (widget AS FL_WIDGET PTR)
   DIM AS STRING ns = *Fl_Input_GetValue(DZ.in1), toins
   DIM AS INTEGER poz
   poz = find_in_browser("namespace")
   Fl_BrowserInsert DZ.brw_DESIGN, poz+1, "DIM AS Fl_Radio_Button PTR rd"+ns

   poz = find_in_browser("marker00")
   toins = DZ.nmspc + !".rdHHH = Fl_Radio_ButtonNew(0, 0, 50, 25, \"HHH\") "
   strreplace(toins, "HHH", ns)
   Fl_BrowserInsert DZ.brw_DESIGN, poz, toINS
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
FUNCTION DrawCB1 CDECL(me AS ANY PTR) AS INTEGER
   DIM AS INTEGER x =  Fl_WidgetGetX(me), y =  Fl_WidgetGetY(me), w = Fl_WidgetGetW(me), h = Fl_WidgetGetH(me)
   DrawPushClip x, y, w, h
   DrawRectFillColor x, y, w, h, Fl_BLACK
   DRAW_IT
   DrawPopClip
   RETURN 1
END FUNCTION
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
FUNCTION BoxHandle CDECL (self AS ANY PTR, event AS Fl_Event) AS INTEGER   
   DIM AS INTEGER x,y,i, xx1, xx2, yy1, yy2
   DIM AS INTEGER x1_ = Fl_WidgetGetX(DZ.box1), y1_ = Fl_WidgetGetY(DZ.box1)
   DIM AS INTEGER butt = Fl_EventButtons(), poz=-1

   IF event = Fl_Event.FL_EVENT_PUSH AND (butt = FL_BUTTON1 OR butt = FL_BUTTON3)THEN
   x=Fl_EventX()
   y=Fl_EventY()

   x=x-x1_
   y=y-y1_

   FOR i = 0 TO DZ.numberofwidgets
      IF x > DZ.widgets_(0, i) AND x < DZ.widgets_(2, i) AND y > DZ.widgets_(1, i) AND y < DZ.widgets_(3, i) THEN
      poz = i
      EXIT FOR
      END IF
   NEXT i

   DZ.poz_ = poz

   Fl_ValuatorSetValue(CPTR(Fl_Valuator PTR, DZ.countXPOSITION), DZ.x_(DZ.poz_))
   Fl_ValuatorSetValue(CPTR(Fl_Valuator PTR, DZ.countYPOSITION), DZ.y_(DZ.poz_))
   Fl_ValuatorSetValue(CPTR(Fl_Valuator PTR, DZ.countWIDTH), DZ.w_(DZ.poz_))
   Fl_ValuatorSetValue(CPTR(Fl_Valuator PTR, DZ.countHEIGHT), DZ.h_(DZ.poz_))

   Fl_WidgetRedraw(DZ.box1)
END IF
RETURN 0
END FUNCTION
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB FormDesignShow ()
   Fl_WindowShow DZ.win
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB FRM_DESIGNCREATE()
   IF DZ.win THEN RETURN
   DIM AS INTEGER xx, yy, ww, hh, i
   Fl_ScreenWorkAreaXYWH xx, yy, ww, hh

   DZ.win = Fl_Double_WindowNew2((ww-1000)/2, (hh-800)/2, 1000, 800, "FLTK Form Designer")

   DZ.btnRELOAD = FL_ButtonNew(10,5,90,30,"Reload File")
   Fl_WidgetSetTooltip DZ.btnRELOAD, "Read From File To ListBox"
   Fl_WidgetSetCallback0 DZ.btnRELOAD, @btnReloadCB

   DZ.btn22 = FL_ButtonNew(160,5,90,30,"Select All")
   Fl_WidgetSetTooltip DZ.btn22, "Select All Widgets"
   Fl_WidgetSetCallback0 DZ.btn22, @btn22_KL

   DZ.btnMemory = Fl_ButtonNew(320, 5, 30, 30, "@>>")
   Fl_WidgetSetLabelColor DZ.btnMemory, FL_GREEN
   Fl_WidgetSetTooltip DZ.btnMemory, "Copy From ListBox To Drawing"
   Fl_WidgetSetCallback0 DZ.btnMemory, @btnMemory_Clicked

   DZ.btnList = Fl_ButtonNew(360, 5, 30, 30, "@<<")
   Fl_WidgetSetTooltip DZ.btnList, "Copy From Drawing To ListBox"
   Fl_WidgetSetCallback0 DZ.btnList, @btnList_Clicked
   Fl_WidgetSetLabelColor DZ.btnList, FL_BLUE

   DZ.btnSAVECH = FL_ButtonNew(420,5,80,30,"Save")
   Fl_WidgetSetTooltip DZ.btnSAVECH, "Save To File"
   Fl_WidgetSetCallback0 DZ.btnSAVECH, @btnSAVECHCB

   DZ.brw_DESIGN = Fl_BrowserNew(10,45,510,650)
   Fl_Browser_SetTextFont(DZ.brw_DESIGN, Fl_COURIER)
   Fl_Browser_SetTextsize(DZ.brw_DESIGN, 15)
   Fl_WidgetSetType DZ.brw_DESIGN, FL_MULTIBROWSER

   DZ.scr1 = Fl_ScrollNew(525,45,470,750)
   Fl_ScrollBegin DZ.scr1
   DZ.box1 = Fl_BoxExNew (525,45,2000,1000)
   Fl_BoxExSetDrawCB DZ.box1, @DrawCB1
   Fl_BoxExSetHandleCB DZ.box1, @BoxHandle
   Fl_ScrollEnd DZ.scr1

   DZ.countXPOSITION = Fl_Simple_CounterNew(520, 5, 80, 20, "X")
   Fl_ValuatorRange (CPTR(Fl_Valuator PTR, DZ.countXPOSITION), 0, 10000)
   Fl_CounterNormalStep(DZ.countXPOSITION, 10)
   Fl_WidgetSetCallback0 DZ.countXPOSITION, @countXPOSITION_Clicked

   DZ.countYPOSITION = Fl_Simple_CounterNew(620, 5, 80, 20, "Y")
   Fl_ValuatorRange (CPTR(Fl_Valuator PTR, DZ.countYPOSITION), 0, 10000)
   Fl_CounterNormalStep(DZ.countYPOSITION, 10)
   Fl_WidgetSetCallback0 DZ.countYPOSITION, @countYPOSITION_Clicked

   DZ.countWIDTH = Fl_Simple_CounterNew(720, 5, 80, 20, "W")
   Fl_ValuatorRange (CPTR(Fl_Valuator PTR, DZ.countWIDTH), 0, 10000)
   Fl_CounterNormalStep(DZ.countWIDTH, 10)
   Fl_WidgetSetCallback0 DZ.countWIDTH, @countWIDTH_Clicked

   DZ.countHEIGHT = Fl_Simple_CounterNew(820, 5, 80, 20, "H")
   Fl_ValuatorRange (CPTR(Fl_Valuator PTR, DZ.countHEIGHT), 0, 10000)
   Fl_CounterNormalStep(DZ.countHEIGHT, 10)
   Fl_WidgetSetCallback0 DZ.countHEIGHT, @countHEIGHT_Clicked

   DZ.btnSkipToNextWidget = Fl_ButtonNew(960, 5, 30, 30, "@->")
   Fl_WidgetSetCallback0 DZ.btnSkipToNextWidget, @btnSkipToNextWidget_Clicked
   Fl_WidgetSetLabelColor DZ.btnSkipToNextWidget, FL_RED

   DZ.btn1 = Fl_ButtonNew(10, 700, 70, 20, "FORM")
   Fl_WidgetSetCallback0 DZ.btn1, @btn1_Click

   DZ.in1 = Fl_InputNew(90, 700, 50, 20)
   Fl_Input_SetValue (DZ.in1, "T")
   Fl_WidgetSetColor DZ.in1, FL_MAGENTA

   DZ.btn2 = Fl_ButtonNew(150, 700, 70, 20, "BTN")
   Fl_WidgetSetCallback0 DZ.btn2, @btn2_Click

   DZ.btn3 = Fl_ButtonNew(250, 700, 70, 20, "IN")
   Fl_WidgetSetCallback0 DZ.btn3, @btn3_Click

   DZ.btn4 = Fl_ButtonNew(330, 700, 70, 20, "BRW")
   Fl_WidgetSetCallback0 DZ.btn4, @btn4_Click

   DZ.btn5 = Fl_ButtonNew(10, 730, 70, 20, "CHK")
   Fl_WidgetSetCallback0 DZ.btn5, @btn5_Click

   DZ.btn6 = Fl_ButtonNew(90, 730, 70, 20, "RAD")
   Fl_WidgetSetCallback0 DZ.btn6, @btn6_Click

   DZ.btn7 = Fl_ButtonNew(170, 730, 70, 20, "RDR")
   Fl_WidgetSetCallback0 DZ.btn7, @btn7_Click

   DZ.btn8 = Fl_ButtonNew(250, 730, 70, 20, "RDL")
   Fl_WidgetSetCallback0 DZ.btn8, @btn8_Click

   DZ.btn9 = Fl_ButtonNew(330, 730, 70, 20, "GRP")
   Fl_WidgetSetCallback0 DZ.btn9, @btn9_Click

   Fl_GroupEnd DZ.win

   Fl_GroupSetResizable (DZ.win, DZ.scr1)
END SUB
Last edited by ike on May 29, 2015 15:34, edited 1 time in total.
ike
Posts: 387
Joined: Jan 17, 2011 18:59

Re: FLTK Form Designer (very basic)

Postby ike » May 29, 2015 3:57

Always copy EXE to the folder where is form to edit

On main screen you have 2 input box: green and yellow

enter test1.bi into green input box and click "Create new form"

then click:

1. Reload File
2. Form



3. enter widget name "NEW" into pink input box and click BTN
4. enter widget name "SAVE" into pink input box and click BTN

5. enter widget name "SURNAME" into pink input box and click IN (input box)
6. enter widget name "NAME" into pink input box and click IN (input box)

7. enter widget name "BROWSER1" into pink input box and click BRW

=============================
CLICK SELECT ALL

CLICK GREEN ARROW to copy it to drawing area

EDIT SIZE and pozitions using XYWH sliders

CLICK BLUE ARROW TO SAVE IT BACK TO LIST BOX

Save it to file
tinycla
Posts: 121
Joined: Jan 07, 2006 12:51

Re: FLTK Form Designer (very basic)

Postby tinycla » May 29, 2015 14:01

I'm trying to compile the designer, but I get an error on Form1.bi:

Code: Select all

C:\FreeBASIC\fltk-c-1.3.3\FlDesigner\form1.bi(483) error 41: Variable not declared, Fl_Event in 'IF event = Fl_Event.FL_EVENT_PUSH AND (butt = FL_BUTTON1 OR butt = FL_BUTTON3) THEN'


What's wrong with the code? I'm using the last fbc (1.0.2.1), last fltk-c.dll. I'm compiling on Win7.
ike
Posts: 387
Joined: Jan 17, 2011 18:59

Re: FLTK Form Designer (very basic)

Postby ike » May 29, 2015 14:18

see your fltk-c.bi

at line 357



enum Fl_Event
FL_NO_EVENT = 0
FL_EVENT_PUSH
FL_EVENT_RELEASE
FL_EVENT_ENTER
FL_EVENT_LEAVE
FL_EVENT_DRAG
tinycla
Posts: 121
Joined: Jan 07, 2006 12:51

Re: FLTK Form Designer (very basic)

Postby tinycla » May 29, 2015 14:43

Very strange. I'm using the last version of fltk-c.bi, with the date of 4/13/2015, and there isn't such a line, nor an ENUM Fl_Event, but in line 350 there is:

Code: Select all

type Fl_Event as ulong


so I think you are using an old version of the library. It needs to make some changes for compiling with the current version, I suppose.
tinycla
Posts: 121
Joined: Jan 07, 2006 12:51

Re: FLTK Form Designer (very basic)

Postby tinycla » May 29, 2015 14:48

I've found the solution. You have to change the line:

Code: Select all

IF event = Fl_Event.FL_EVENT_PUSH AND (butt = FL_BUTTON1 OR butt = FL_BUTTON3) THEN

in

Code: Select all

IF event = FL_EVENT_PUSH AND (butt = FL_BUTTON1 OR butt = FL_BUTTON3) THEN

Fl_Event is no more an enumerator, but a type.
ike
Posts: 387
Joined: Jan 17, 2011 18:59

Re: FLTK Form Designer (very basic)

Postby ike » May 29, 2015 15:34

You can edit dialogs-forms that you did before, but to be able to insert new element, form has to be created with this program
That is because you need marker00, marker01 inside code so program will know where to insert


https://youtu.be/S56D1fg23xw

If you edit old be sure to have backup

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 5 guests