ScriptBasic

Extension Modules => Extension Modules => DLLC => Topic started by: Support on April 11, 2013, 10:28:11 AM

Title: ScriptBasic IUP Windows (DLLC)
Post by: Support on April 11, 2013, 10:28:11 AM
I wanted to give DLLC a good workout and selected the IUP cbox.c example to convert to ScriptBasic. Not only does it use about every control, it shows fixed positioning which was the purpose of the example. This example is dynamically scripted at run time using DLLC and the IUP DLLs.

(http://files.allbasic.info/ScriptBasic/cboxw.png)

cbox.sb
Code: [Select]
' IupCbox Example - fixed positioning

INCLUDE "iupinc.sb"

img_bits1 = """
 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1
,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1
,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1
,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1
,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1
,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1
,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1
,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1
,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,2,2,0,2,2,2,2,2,2,2,2,2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3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
"""

FUNCTION create_mat
  mat = dllcall(IupMatrix, "")
  dllcall(IupSetAttribute, mat, "NUMCOL", "1")
  dllcall(IupSetAttribute, mat, "NUMLIN", "3")
  dllcall(IupSetAttribute, mat, "NUMCOL_VISIBLE", "1")
  dllcall(IupSetAttribute, mat, "NUMLIN_VISIBLE", "3")
  dllcall(IupSetAttribute, mat, "EXPAND", "NO")
  dllcall(IupSetAttribute, mat, "SCROLLBAR", "NO")

  dllcall(IupSetAttribute, mat, "0:0", "Inflation")
  dllcall(IupSetAttribute, mat, "1:0", "Medicine ")
  dllcall(IupSetAttribute, mat, "2:0", "Food")
  dllcall(IupSetAttribute, mat, "3:0", "Energy")
  dllcall(IupSetAttribute, mat, "0:1", "January 2000")
  dllcall(IupSetAttribute, mat, "1:1", "5.6")
  dllcall(IupSetAttribute, mat, "2:1", "2.2")
  dllcall(IupSetAttribute, mat, "3:1", "7.2")

  dllcall(IupSetAttribute, mat, "BGCOLOR", "255 255 255")
  dllcall(IupSetAttribute, mat, "BGCOLOR1:0", "255 128 0")
  dllcall(IupSetAttribute, mat, "BGCOLOR2:1", "255 128 0")
  dllcall(IupSetAttribute, mat, "FGCOLOR2:0", "255 0 128")
  dllcall(IupSetAttribute, mat, "FGCOLOR1:1", "255 0 128")

  dllcall(IupSetAttribute, mat, "CX", "600")
  dllcall(IupSetAttribute, mat, "CY", "250")

  create_mat = mat

END FUNCTION

FUNCTION createtree
  tree = dllcall(IupTree)
  dllcall(IupSetAttributes, tree, "FONT=COURIER_NORMAL_10, " & _
                         "NAME=Figures, " & _
                         "ADDBRANCH=3D, " & _
                         "ADDBRANCH=2D, " & _
                         "ADDLEAF1=trapeze, " & _
                         "ADDBRANCH1=parallelogram, " & _
                         "ADDLEAF2=diamond, " & _
                         "ADDLEAF2=square, " & _
                         "ADDBRANCH4=triangle, " & _
                         "ADDLEAF5=scalenus, " & _
                         "ADDLEAF5=isosceles, " & _
                         "ADDLEAF5=equilateral, " & _
                         "RASTERSIZE=180x180, " & _
                         "VALUE=6, " & _
                         "CTRL=ON, " & _
                         "SHIFT=ON, " & _
                         "CX=600, " & _
                         "CY=10, " & _
                         "ADDEXPANDED=NO")
  createtree = tree
END FUNCTION

SUB func_1
  img_1 = dllcall(IupImage, 32, 32, SB_CreateImg(img_bits1))
  dllcall(IupSetHandle, "img1", img_1)
  dllcall(IupSetAttribute, img_1, "0", "0 0 0")
  dllcall(IupSetAttribute, img_1, "1", "BGCOLOR")
  dllcall(IupSetAttribute, img_1, "2", "255 0 0")

  img_2 = dllcall(IupImage, 32, 32, SB_CreateImg(img_bits2))
  dllcall(IupSetHandle, "img2", img_2)
  dllcall(IupSetAttribute, img_2, "0", "0 0 0")
  dllcall(IupSetAttribute, img_2, "1", "0 255 0")
  dllcall(IupSetAttribute, img_2, "2", "BGCOLOR")
  dllcall(IupSetAttribute, img_2, "3", "255 0 0")

  _frm_1 = dllcall(IupFrame, _
    dllcall(IupVbox, _
      dllcall(IupSetAttributes, dllcall(IupButton, "Button Text", ""), "CINDEX=1"), _
      dllcall(IupSetAttributes, dllcall(IupButton, "", ""), "IMAGE=img1,CINDEX=2"), _
      dllcall(IupSetAttributes, dllcall(IupButton, "", ""), "IMAGE=img1,IMPRESS=img2,CINDEX=3"),0))
  dllcall(IupSetAttribute, _frm_1, "TITLE", "IupButton")
  dllcall(IupSetAttribute, _frm_1, "CX", "10")
  dllcall(IupSetAttribute, _frm_1, "CY", "180")

  _frm_2 = dllcall(IupFrame, _
    dllcall(IupVbox, _
      dllcall(IupSetAttributes, dllcall(IupLabel, "Label Text"), "CINDEX=1"), _
      dllcall(IupSetAttributes, dllcall(IupLabel, ""), "SEPARATOR=HORIZONTAL,CINDEX=2"), _
      dllcall(IupSetAttributes, dllcall(IupLabel, ""), "IMAGE=img1,CINDEX=3"), 0))
  dllcall(IupSetAttribute, _frm_2, "TITLE", "IupLabel")
  dllcall(IupSetAttribute, _frm_2, "CX", "200")
  dllcall(IupSetAttribute, _frm_2, "CY", "250")

  _frm_3 = dllcall(IupFrame, _
    dllcall(IupVbox, _
      dllcall(IupSetAttributes, dllcall(IupToggle, "Toggle Text", ""), "VALUE=ON,CINDEX=1"), _
      dllcall(IupSetAttributes, dllcall(IupToggle, "", ""), "IMAGE=img1,IMPRESS=img2,CINDEX=2"), _
      dllcall(IupSetAttributes, dllcall(IupFrame, dllcall(IupRadio, dllcall(IupVbox, _
        dllcall(IupSetAttributes, dllcall(IupToggle, "Toggle Text", ""), "CINDEX=3"), _
        dllcall(IupSetAttributes, dllcall(IupToggle, "Toggle Text", ""), "CINDEX=4"), 0))), "TITLE=IupRadio"), 0))
  dllcall(IupSetAttribute, _frm_3, "TITLE", "IupToggle")
  dllcall(IupSetAttribute, _frm_3, "CX", "400")
  dllcall(IupSetAttribute, _frm_3, "CY", "250")

  _text_1 = dllcall(IupText, "")
  dllcall(IupSetAttribute, _text_1, "VALUE", "IupText Text")
  dllcall(IupSetAttribute, _text_1, "SIZE", "80x")
  dllcall(IupSetAttribute, _text_1, "CINDEX", "1")
  dllcall(IupSetAttribute, _text_1, "CX", "10")
  dllcall(IupSetAttribute, _text_1, "CY", "100")

  _ml_1 = dllcall(IupMultiLine, "")
  dllcall(IupSetAttribute, _ml_1, "VALUE", "IupMultiline Text\nSecond Line\nThird Line")
  dllcall(IupSetAttribute, _ml_1, "SIZE", "80x60")
  dllcall(IupSetAttribute, _ml_1, "CINDEX", "1")
  dllcall(IupSetAttribute, _ml_1, "CX", "200")
  dllcall(IupSetAttribute, _ml_1, "CY", "100")

  _list_1 = dllcall(IupList, "")
  dllcall(IupSetAttribute, _list_1, "VALUE", "1")
  dllcall(IupSetAttribute, _list_1, "1", "Item 1 Text")
  dllcall(IupSetAttribute, _list_1, "2", "Item 2 Text")
  dllcall(IupSetAttribute, _list_1, "3", "Item 3 Text")
  dllcall(IupSetAttribute, _list_1, "CINDEX", "1")
  dllcall(IupSetAttribute, _list_1, "CX", "10")
  dllcall(IupSetAttribute, _list_1, "CY", "10")

  _list_2 = dllcall(IupList, "")
  dllcall(IupSetAttribute, _list_2, "DROPDOWN", "YES")
  dllcall(IupSetAttribute, _list_2, "VALUE", "2")
  dllcall(IupSetAttribute, _list_2, "1", "Item 1 Text")
  dllcall(IupSetAttribute, _list_2, "2", "Item 2 Text")
  dllcall(IupSetAttribute, _list_2, "3", "Item 3 Text")
  dllcall(IupSetAttribute, _list_2, "CINDEX", "2")
  dllcall(IupSetAttribute, _list_2, "CX", "200")
  dllcall(IupSetAttribute, _list_2, "CY", "10")

  _list_3 = dllcall(IupList, "")
  dllcall(IupSetAttribute, _list_3, "EDITBOX", "YES")
  dllcall(IupSetAttribute, _list_3, "VALUE", "3")
  dllcall(IupSetAttribute, _list_3, "1", "Item 1 Text")
  dllcall(IupSetAttribute, _list_3, "2", "Item 2 Text")
  dllcall(IupSetAttribute, _list_3, "3", "Item 3 Text")
  dllcall(IupSetAttribute, _list_3, "CINDEX", "3")
  dllcall(IupSetAttribute, _list_3, "CX", "400")
  dllcall(IupSetAttribute, _list_3, "CY", "10")

  _cnv_1 = dllcall(IupCanvas, "")
  dllcall(IupSetAttribute, _cnv_1, "RASTERSIZE", "100x100")
  dllcall(IupSetAttribute, _cnv_1, "POSX", "0")
  dllcall(IupSetAttribute, _cnv_1, "POSY", "0")
  dllcall(IupSetAttribute, _cnv_1, "BGCOLOR", "128 255 0")
  dllcall(IupSetAttribute, _cnv_1, "CX", "400")
  dllcall(IupSetAttribute, _cnv_1, "CY", "150")

  _ctrl_1 = dllcall(IupVal, "")
  dllcall(IupSetAttribute, _ctrl_1, "CX", "600")
  dllcall(IupSetAttribute, _ctrl_1, "CY", "200")

  _cbox = dllcall(IupCbox, _
                  _text_1, _
                    _ml_1, _
                  _list_1, _
                  _list_2, _
                  _list_3, _
                   _cnv_1, _
                  _ctrl_1, _
             createtree(), _
             create_mat(), _
                   _frm_1, _
                   _frm_2, _
                   _frm_3, _
                        0)
  dllcall(IupSetAttribute, _cbox, "SIZE", "480x200")

  hbox = dllcall(IupSetAttributes, dllcall(IupHbox, _cbox, 0), "MARGIN=10x10")

  dlg = dllcall(IupDialog, hbox)
  dllcall(IupSetHandle, "dlg", dlg)
  dllcall(IupSetAttribute, dlg, "TITLE", "Cbox Test")
END SUB


FUNCTION main(pProg)
  dllcall(IupOpen, 0, 0)
  dllcall(IupControlsOpen)
  func_1()
  dllcall(IupShowXY, dllcall(IupGetHandle, "dlg"), IUP_CENTER, IUP_CENTER)
  dllcall(IupMainLoop)
  dllcall(IupClose)
  main = TRUE
END FUNCTION

(http://files.allbasic.info/ScriptBasic/cbox_u64.png)

cbox.c (http://www.tecgraf.puc-rio.br/iup/examples/C/cbox.c)