Author Topic: BaCon/IUP  (Read 12510 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
BaCon/IUP
« on: January 01, 2013, 03:26:00 PM »
I started this thread for those BaCon users that wish to use the IUP GUI toolkit rather than the HUG Gtk wrapper Peter wrote. I'm going to transfer some of the posts I made on the BaCon forum here to get things rolling. You will need the beta 29 build of BaCon to following along with this thread.

BaCon Project Site

IUP (Portable User Interface) Project Site

CD - Canvas Draw, A 2D Graphics Library

IM - Image Management Toolkit

IUP MathGLPlot



Code: [Select]
PRAGMA OPTIONS -I/usr/include/iup
PRAGMA LDFLAGS iup
PRAGMA INCLUDE iup.h
PROTO IupOpen, IupShow, IupDialog, IupLabel, IupMainLoop, IupClose

IupOpen(NULL,NULL)
IupShow(IupDialog(IupLabel("Hello World!")))
IupMainLoop()
IupClose()
« Last Edit: January 09, 2013, 03:34:03 PM by JRS »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BaCon/IUP
« Reply #1 on: January 01, 2013, 03:37:34 PM »


Code: [Select]
PRAGMA OPTIONS -I/usr/include/iup
PRAGMA LDFLAGS iup
PRAGMA INCLUDE iup.h
PROTO IupOpen IupSetAttributes IupAppend IupSetCallback IupShow IupMainLoop IupClose

DECLARE win TYPE Ihandle *
DECLARE horzbox TYPE Ihandle *
DECLARE btn1 TYPE Ihandle *
DECLARE btn2 TYPE Ihandle *
DECLARE btn3 TYPE Ihandle *

SUB Btn1_clicked
  PRINT "BUTTON 1 Event"
END SUB

SUB Btn2_clicked
  PRINT "BUTTON 2 Event"
END SUB

SUB Btn3_clicked
  PRINT "BUTTON 3 Event"
END SUB

IupOpen(NULL,NULL)
win = IupCreate("dialog")
IupSetAttributes(win, "TITLE=\"Test Dialog\", SIZE=300x")
horzbox = IupCreate("hbox")
IupSetAttributes(horzbox, "GAP=5")
btn1 = IupCreate("button")
IupSetAttributes(btn1, "TITLE=Button1, EXPAND=HORIZONTAL")
btn2 = IupCreate("button")
IupSetAttributes(btn2, "TITLE=Button2, EXPAND=HORIZONTAL")
btn3 = IupCreate("button")
IupSetAttributes(btn3, "TITLE=Button3, EXPAND=HORIZONTAL")
IupAppend(horzbox, btn1)
IupAppend(horzbox, btn2)
IupAppend(horzbox, btn3)
IupAppend(win, horzbox)
IupSetCallback(btn1, "ACTION", (Icallback)Btn1_clicked)
IupSetCallback(btn2, "ACTION", (Icallback)Btn2_clicked)
IupSetCallback(btn3, "ACTION", (Icallback)Btn3_clicked)
IupShow(win)
IupMainLoop()
IupClose()

jrs@laptop:~/BaCon/B29$ ./bacon buttons.bac
Converting 'buttons.bac'... done.
Compiling 'buttons.bac'... done.
Program 'buttons' ready.
jrs@laptop:~/BaCon/B29$ ./buttons
BUTTON 1 Event
BUTTON 2 Event
BUTTON 3 Event
jrs@laptop:~/BaCon/B29$


Change this:
IupShow(win)

To this:
IupShow(IupLayoutDialog(win))

if you want to include the IUP Dialog Layout Tool to debug or enhance your application.


What the sdbg remote debugger internal preprocessor is to ScriptBasic, the IupLayoutDialog() dialog layout tool is to IUP.
« Last Edit: January 01, 2013, 05:25:19 PM by JRS »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BaCon/IUP
« Reply #2 on: January 02, 2013, 01:33:04 PM »
This IUP button example I converted to BaCon expands on the previous SB button example in the following ways.

  • Use of FUNCTION with extended callback arguments
  • Changing the active state of a button
  • Toggling an image on a button
  • Printing to the console the button pressed and up/down state
  • Create the dialog, a vbox, a hbox and attach the controls in one multi-function statement
  • Create images from strings
  • Change the color of the image with change in state
  • Updating the teextbox with the up/down status of the image button
  • Disabling system menu options (resize, maximize, minimize and menubox off)



Code: [Select]
' *****************************************************************************
' *                             IupButton example                             *
' *   Description : Creates four buttons. The first uses images, the second   *
' *                 turns the first on and off, the third exits the           *
' *                 application and the last does nothing                     *
' *****************************************************************************

PRAGMA OPTIONS -I/usr/include/iup
PRAGMA LDFLAGS iup
PRAGMA INCLUDE iup.h

PROTO IupOpen IupSetAttribute IupSetAttributes IupSetHandle IupSetFunction IupSetCallback IupAppend IupShowXY IupMainLoop IupClose

DECLARE dlg TYPE Ihandle *
DECLARE btn_image TYPE Ihandle *
DECLARE btn_exit TYPE Ihandle *
DECLARE btn_big TYPE Ihandle *
DECLARE btn_on_off TYPE Ihandle *
DECLARE img_release TYPE Ihandle *
DECLARE img_press TYPE Ihandle *
DECLARE img_inactive TYPE Ihandle *
DECLARE text TYPE Ihandle *

' Defines released button's image
DECLARE pixmap_release[] = { \
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, \
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,4,4,3,3,3,3,2,2, \
1,1,3,3,3,3,3,4,4,4,4,3,3,3,2,2, \
1,1,3,3,3,3,3,4,4,4,4,3,3,3,2,2, \
1,1,3,3,3,3,3,3,4,4,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
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 \
} TYPE static unsigned char

' Defines pressed button's image
DECLARE pixmap_press[] = { \
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, \
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,4,4,3,3,3,3,3,2,2, \
1,1,3,3,3,3,4,4,4,4,3,3,3,3,2,2, \
1,1,3,3,3,3,4,4,4,4,3,3,3,3,2,2, \
1,1,3,3,3,3,3,4,4,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
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 \
} TYPE static unsigned char

' Defines inactive button's image
DECLARE pixmap_inactive[] = { \
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, \
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,4,4,3,3,3,3,2,2, \
1,1,3,3,3,3,3,4,4,4,4,3,3,3,2,2, \
1,1,3,3,3,3,3,4,4,4,4,3,3,3,2,2, \
1,1,3,3,3,3,3,3,4,4,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2, \
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 \
} TYPE static unsigned char

' ******************************************************************************
' * Function:                                                                  *
' * On off button callback                                                     *
' *                                                                            *
' * Description:                                                               *
' * Callback called when the on/off button is activated. Turns the button with *
' * image on and off                                                           *
' *                                                                            *
' * Parameters received:                                                       *
' * self - element identifier                                                  *
' *                                                                            *
' * Value returned:                                                            *
' * IUP_DEFAULT                                                                *
' ******************************************************************************
FUNCTION btn_on_off_cb(Ihandle *self)
  ' Recovers "btn_image" handle
  btn_image = IupGetHandle("btn_image")
  ' If the button with with image is active...
  but_state$ = IupGetAttribute(btn_image, "ACTIVE")
  IF but_state$ = "YES" THEN
    ' Deactivates the button with image
    IupSetAttribute(btn_image, "ACTIVE","NO")
  ' else it is inactive
  ELSE
    ' Activates the button with image
    IupSetAttribute(btn_image, "ACTIVE", "YES")
  END IF
  ' Executed function successfully
  RETURN IUP_DEFAULT
END FUNCTION

' ******************************************************************************
' * Function:                                                                  *
' * Button with image button callback                                          *
' *                                                                            *
' * Description:                                                               *
' * Callback called when the image button is pressed or released. Shows a      *
' * message saying if the button was pressed or released                       *
' *                                                                            *
' * Parameters received:                                                       *
' * self - identifies the canvas that activated the function’s execution.      *
' * b    - identifies the activated mouse button:                              *
' *                                                                            *
' * IUP_BUTTON1 left mouse button (button 1)                                   *
' * IUP_BUTTON2 middle mouse button (button 2)                                 *
' * IUP_BUTTON3 right mouse button (button 3)                                  *
' *                                                                            *
' * e     - indicates the state of the button:                                 *
' *                                                                            *
' * 0 mouse button was released                                                *
' * 1 mouse button was pressed                                                 *
' *                                                                            *
' * Value returned:                                                            *
' * IUP_DEFAULT                                                                *
' ******************************************************************************
FUNCTION btn_image_button_cb(Ihandle *self, NUMBER b , NUMBER e)
  ' If the left button changed its state...
  IF b = IUP_BUTTON1 THEN
    ' Recovers "text" handle
    text = IupGetHandle("text")
    ' If the button was pressed...
    IF e = 1 THEN
      ' Sets text's value
      IupSetAttribute(text, "VALUE", "Red button pressed")
    ' else the button was released
    ELSE
      ' Sets text's value
      IupSetAttribute( text, "VALUE", "Red button released" )
    END IF
  END IF
  ' Executed function successfully
  RETURN IUP_DEFAULT
END FUNCTION

' ******************************************************************************
' * Function:                                                                  *
' * Show mouse button activity                                                 *
' ******************************************************************************
FUNCTION btn_big_button_cb(Ihandle *self, NUMBER button, NUMBER press)
  PRINT "BUTTON_CB(button=", CHR$(button), ", press=", press
  RETURN IUP_DEFAULT
END FUNCTION

' ******************************************************************************
' * Function:                                                                  *
' * Exit button callback                                                       *
' *                                                                            *
' * Description:                                                               *
' * Callback called when exit button is activated. Exits the program           *
' *                                                                            *
' * Parameters received:                                                       *
' * self - element identifier                                                  *
' *                                                                            *
' * Value returned:                                                            *
' * IUP_DEFAULT                                                                *
' ******************************************************************************
FUNCTION btn_exit_cb(Ihandle *self)
  ' Exits the program
  RETURN IUP_CLOSE
END FUNCTION

' ******************************************************************************
' * Main function                                                              *
' ******************************************************************************
  ' Initializes IUP
  IupOpen(NULL,NULL)
  ' Creates a text
  text = IupText(NULL)
  IupSetAttribute(text,"SIZE","100x")
  ' Turns on read-only mode
  IupSetAttribute(text, "READONLY", "YES")
  ' Associates text with handle "text"
  IupSetHandle ("text", text)
  ' Defines released button's image size
  img_release = IupImage(16, 16, pixmap_release)
  ' Defines released button's image colors
  IupSetAttribute(img_release, "1", "215 215 215")
  IupSetAttribute(img_release, "2", "40 40 40")
  IupSetAttribute(img_release, "3", "30 50 210")
  IupSetAttribute(img_release, "4", "240 0 0")
  ' Associates img_release with handle "img_release"
  IupSetHandle("img_release", img_release)
  ' Defines pressed button's image size
  img_press = IupImage( 16, 16, pixmap_press)
  ' Defines pressed button's image colors
  IupSetAttribute( img_press, "1", "40 40 40" )
  IupSetAttribute( img_press, "2", "215 215 215" )
  IupSetAttribute( img_press, "3", "0 20 180" )
  IupSetAttribute( img_press, "4", "210 0 0" )
  ' Associates img_press with handle "img_press"
  IupSetHandle ("img_press", img_press)
  ' Defines inactive button's image size
  img_inactive = IupImage(16, 16, pixmap_inactive)
  ' Defines inactive button's image colors
  IupSetAttribute(img_inactive, "1", "215 215 215")
  IupSetAttribute(img_inactive, "2", "40 40 40")
  IupSetAttribute(img_inactive, "3", "100 100 100")
  IupSetAttribute(img_inactive, "4", "200 200 200")
  ' Associates img_inactive with handle "img_inactive"
  IupSetHandle ("img_inactive", img_inactive)
  ' Creates a button
  btn_image = IupButton("Button with image", "btn_image")
  ' Sets released, pressed and inactive button images
  IupSetAttribute(btn_image, "IMAGE", "img_release")
  IupSetAttribute(btn_image, "IMPRESS", "img_press")
  IupSetAttribute(btn_image, "IMINACTIVE", "img_inactive")
  ' Associates button callback with action bti_button_act
  IupSetAttribute(btn_image, "BUTTON_CB", "btn_image_button")
  ' Associates btn_image with handle "btn_image"
  IupSetHandle( "btn_image", btn_image )
  ' Creates a button
  btn_big = IupButton("Big useless button",NULL)
  ' Sets big button size
  IupSetAttribute(btn_big, "SIZE", "EIGHTHxEIGHTH")
  ' Creates a button entitled Exit associated with action exit_act
  btn_exit = IupButton("Exit", "btn_exit")
  ' Creates a button entitled on/off associated with action onoff_act
  btn_on_off = IupButton( "on/off", "btn_on_off_cb")
  dlg = IupDialog(IupVbox(IupHbox(btn_image,btn_on_off,btn_exit,NULL),text,btn_big,NULL))
  ' Sets dialogs title to IupButton turns resize, maximize, minimize and menubox off
  IupSetAttributes(dlg, "EXPAND=YES, TITLE=IupButton, RESIZE=YES")
  IupSetAttributes(dlg, "MENUBOX=NO, MAXBOX=NO, MINBOX=NO")
  ' Registers callbacks
  IupSetCallback(btn_exit, "ACTION", (Icallback)btn_exit_cb)
  IupSetCallback(btn_on_off, "ACTION", (Icallback)btn_on_off_cb)
  IupSetCallback(btn_image, "BUTTON_CB", (Icallback)btn_image_button_cb)
  IupSetAttribute(btn_big, "BUTTON_CB", "bigtest");
  IupSetFunction("bigtest", (Icallback)btn_big_button_cb);
  IupSetCallback(btn_big, "BUTTON_CB", (Icallback)btn_big_button_cb);
  ' Shows dialog on the center of the screen
  IupShowXY(dlg, IUP_CENTER, IUP_CENTER)
  ' Initializes IUP main loop
  IupMainLoop()
  ' Finishes IUP
  IupClose()
  ' Program finished successfully

jrs@laptop:~/BaCon/B29$ ./bacon iup_button.bac
Converting 'iup_button.bac'... done.
Compiling 'iup_button.bac'... done.
Program 'iup_button' ready.
jrs@laptop:~/BaCon/B29$ ./iup_button
BUTTON_CB(button=1, press=1
BUTTON_CB(button=1, press=0
BUTTON_CB(button=2, press=1
BUTTON_CB(button=2, press=0
BUTTON_CB(button=3, press=1
BUTTON_CB(button=3, press=0
jrs@laptop:~/BaCon/B29$
« Last Edit: January 02, 2013, 03:11:13 PM by JRS »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BaCon/IUP
« Reply #3 on: January 02, 2013, 09:13:13 PM »
This is an example of working with the IupTabs control. It seems easier to use than directly using the Gtk NoteBook control.



Code: [Select]
' IupTabs Example in BaCon

PRAGMA OPTIONS -I/usr/include/iup
PRAGMA LDFLAGS iup
PRAGMA INCLUDE iup.h

PROTO IupOpen IupSetAttribute IupShowXY IupMainLoop IupClose

DECLARE dlg TYPE Ihandle *
DECLARE vbox1 TYPE Ihandle *
DECLARE vbox2 TYPE Ihandle *
DECLARE tabs1 TYPE Ihandle *
DECLARE tabs2 TYPE Ihandle *
DECLARE box TYPE Ihandle *

IupOpen(NULL, NULL)
vbox1 = IupVbox(IupLabel("Inside Tab A"), IupButton("Button A", ""), NULL)
vbox2 = IupVbox(IupLabel("Inside Tab B"), IupButton("Button B", ""), NULL)
IupSetAttribute(vbox1, "TABTITLE", "Tab A")
IupSetAttribute(vbox2, "TABTITLE", "Tab B")
tabs1 = IupTabs(vbox1, vbox2, NULL)
vbox1 = IupVbox(IupLabel("Inside Tab C"), IupButton("Button C", ""), NULL)
vbox2 = IupVbox(IupLabel("Inside Tab D"), IupButton("Button D", ""), NULL)
IupSetAttribute(vbox1, "TABTITLE", "Tab C")
IupSetAttribute(vbox2, "TABTITLE", "Tab D")
tabs2 = IupTabs(vbox1, vbox2, NULL)
IupSetAttribute(tabs2, "TABTYPE", "LEFT")
box = IupHbox(tabs1, tabs2, NULL)
IupSetAttribute(box, "MARGIN", "10x10")
IupSetAttribute(box, "GAP", "10")
dlg = IupDialog(box)
IupSetAttribute(dlg, "TITLE", "IupTabs")
IupSetAttribute(dlg, "SIZE", "200x80")
IupShowXY(dlg, IUP_CENTER, IUP_CENTER)
IupMainLoop()
IupClose()

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BaCon/IUP
« Reply #4 on: January 03, 2013, 01:36:58 PM »
I have been fighting with trying to get the IupWeb (WebKit 1.0) C example to compile and found out I discovered a bug in the libiupweb.so code.

Quote from: Antonio Scuri - IUP author
I'm sorry. This is a bug.

  Please replace iupgtkBaseAddToParent by iupgtkAddToParent. Just fixed and commited to CVS.



Code: [Select]
' IupWebBrowser sample

PRAGMA OPTIONS -I/usr/include/iup
PRAGMA LDFLAGS iup iupweb
PRAGMA INCLUDE iup.h iupweb.h

PROTO IupOpen IupWebBrowserOpen IupSetAttribute IupSetAttributeHandle IupSetCallback IupShow IupMainLoop IupClose

DECLARE web TYPE Ihandle*
DECLARE txt TYPE Ihandle*
DECLARE dlg TYPE Ihandle*
DECLARE btLoad TYPE Ihandle*
DECLARE btReload TYPE Ihandle*
DECLARE btBack TYPE Ihandle*
DECLARE btForward TYPE Ihandle*
DECLARE btStop TYPE Ihandle*
DECLARE self TYPE Ihandle*
DECLARE url TYPE STRING

FUNCTION navigate_cb(Ihandle* self, STRING url)
  PRINT "NAVIGATE_CB: ", url
  self = NULL
  IF INSTR(url, "download") THEN
    RETURN IUP_IGNORE
  ELSE
    RETURN IUP_DEFAULT
  END IF
END FUNCTION

FUNCTION error_cb(Ihandle* self, STRING url)
  PRINT "ERROR_CB: ", url
  self = NULL
  RETURN IUP_DEFAULT
END FUNCTION

FUNCTION completed_cb(Ihandle* self, STRING url)
  PRINT "COMPLETED_CB: ", url
  self = NULL
  RETURN IUP_DEFAULT
END FUNCTION

FUNCTION newwindow_cb(Ihandle* self, STRING url)
  PRINT "NEWWINDOW_CB: ", url
  IupSetAttribute(self, "VALUE", url)
  RETURN IUP_DEFAULT
END FUNCTION

FUNCTION back_cb(Ihandle* self)
  web  = (Ihandle*)IupGetAttribute(self, "MY_WEB")
  IupSetAttribute(web, "BACKFORWARD", "-1")
  RETURN IUP_DEFAULT
END FUNCTION

FUNCTION forward_cb(Ihandle* self)
  web  = (Ihandle*)IupGetAttribute(self, "MY_WEB")
  IupSetAttribute(web, "BACKFORWARD", "1")
  RETURN IUP_DEFAULT
END FUNCTION

FUNCTION stop_cb(Ihandle* self)
  web  = (Ihandle*)IupGetAttribute(self, "MY_WEB")
  IupSetAttribute(web, "STOP", NULL)
  RETURN IUP_DEFAULT
END FUNCTION

FUNCTION reload_cb(Ihandle* self)
  web  = (Ihandle*)IupGetAttribute(self, "MY_WEB")
  IupSetAttribute(web, "RELOAD", NULL)
  ' TEST:
  ' PRINT "STATUS=", IupGetAttribute(web, "STATUS")
  RETURN IUP_DEFAULT
END FUNCTION

FUNCTION load_cb(Ihandle* self)
  txt  = (Ihandle*)IupGetAttribute(self, "MY_TEXT")
  web  = (Ihandle*)IupGetAttribute(self, "MY_WEB")
  IupSetAttribute(web, "VALUE", IupGetAttribute(txt, "VALUE"))
  ' TESTS:
  ' IupSetAttribute(txt, "VALUE", IupGetAttribute(web, "VALUE"))
  ' IupSetAttribute(web, "HTML", "<html><body><b>Hello</b>, World!</body></html>")
  ' IupSetAttribute(web, "VALUE", "http://www.microsoft.com")
  RETURN IUP_DEFAULT
END FUNCTION

IupOpen(NULL, NULL)
IupWebBrowserOpen()             
' Creates an instance of the WebBrowser control
web = IupWebBrowser()
' Creates a dialog containing the control
dlg = IupDialog(IupVbox(IupHbox(btBack = IupButton("Back", NULL), \
                                btForward = IupButton("Forward", NULL), \
                                txt = IupText(""), \
                                btLoad = IupButton("Load", NULL), \
                                btReload = IupButton("Reload", NULL), \
                                btStop = IupButton("Stop", NULL), \
                                NULL), \
                                web, NULL))
IupSetAttribute(dlg, "TITLE", "IupWebBrowser")
IupSetAttribute(dlg, "MY_TEXT", (STRING)txt)
IupSetAttribute(dlg, "MY_WEB", (STRING)web)
IupSetAttribute(dlg, "RASTERSIZE", "800x600")
IupSetAttribute(dlg, "MARGIN", "10x10")
IupSetAttribute(dlg, "GAP", "10")
' IupSetAttribute(web, "HTML", "<html><body><b>Hello</b>World!</body></html>")
' IupSetAttribute(txt, "VALUE", "My HTML")
' IupSetAttribute(txt, "VALUE", "file:///D:/tecgraf/iup/html/index.html")
IupSetAttribute(txt, "VALUE", "http://www.basic-converter.org/")
IupSetAttribute(web, "VALUE", IupGetAttribute(txt, "VALUE"))
IupSetAttributeHandle(dlg, "DEFAULTENTER", btLoad)
IupSetAttribute(txt, "EXPAND", "HORIZONTAL")
IupSetCallback(btLoad, "ACTION", (Icallback)load_cb)
IupSetCallback(btReload, "ACTION", (Icallback)reload_cb)
IupSetCallback(btBack, "ACTION", (Icallback)back_cb)
IupSetCallback(btForward, "ACTION", (Icallback)forward_cb)
IupSetCallback(btStop, "ACTION", (Icallback)stop_cb)
IupSetCallback(web, "NEWWINDOW_CB", (Icallback)newwindow_cb)
IupSetCallback(web, "NAVIGATE_CB", (Icallback)navigate_cb)
IupSetCallback(web, "ERROR_CB", (Icallback)error_cb)
IupSetCallback(web, "COMPLETED_CB", (Icallback)completed_cb)
IupShow(dlg)
IupMainLoop()
IupClose()

jrs@laptop:~/BaCon/B29$ ./iup_web
NAVIGATE_CB: http://www.basic-converter.org/
COMPLETED_CB: http://www.basic-converter.org/
NAVIGATE_CB: http://www.basic-converter.org/
COMPLETED_CB: http://www.basic-converter.org/
NAVIGATE_CB: http://www.basic-converter.org/
COMPLETED_CB: http://www.basic-converter.org/
NAVIGATE_CB: http://www.basic-converter.org/stable/CHANGES
COMPLETED_CB: http://www.basic-converter.org/stable/CHANGES
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.5) (6b24-1.11.5-0ubuntu1~12.04.1)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
NAVIGATE_CB: http://www.basic-converter.org/
COMPLETED_CB: http://www.basic-converter.org/
jrs@laptop:~/BaCon/B29$

« Last Edit: January 03, 2013, 11:54:52 PM by JRS »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BaCon/IUP
« Reply #5 on: January 04, 2013, 10:25:04 PM »
This example could be used as a reference without having to convert it to BaCon. The point of my effort was to make sure the example compiled and worked. I doesn't look like there is much interest in IUP from the BaCon users so this is about as far as I'm willing to go with this at this point.

Comparing CD with Other Graphics Libraries



I have attached the source to the CDTest and Simple Draw CD examples that come with source distribution.
« Last Edit: January 06, 2013, 09:55:29 AM by JRS »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BaCon/IUP
« Reply #6 on: January 06, 2013, 11:50:42 AM »
Here is an example of using the IM - Image Management library.

Quote
Support for several data types, i.e. scientific images and different color spaces. Support for input and output of image sequences. Support for generic image attributes (metadata), which includes several standard TIFF tags, GeoTIFF tags and Exif tags. Image storage and capture data can be accessed using an image structure or with raw data. Internal implementation in C++ but with a simple C API. Code is portable for Windows and UNIX. Many image processing operations.



Code: [Select]
' IM example that shows an image.

INCLUDE "im_view.inc"

disable_repaint = 0

SUB PrintError(int ierror)
  SELECT ierror
  CASE IM_ERR_OPEN
    IupMessage("IM", "Error Opening File.")
  CASE IM_ERR_MEM
    IupMessage("IM", "Insuficient memory.")
  CASE IM_ERR_ACCESS
    IupMessage("IM", "Error Accessing File.")
  CASE IM_ERR_DATA
    IupMessage("IM", "Image type not Suported.")
  CASE IM_ERR_FORMAT
    IupMessage("IM", "Invalid Format.");
  CASE IM_ERR_COMPRESS
    IupMessage("IM", "Invalid or unsupported compression.")
  DEFAULT
    IupMessage("IM", "Unknown Error.")
  END SELECT
END SUB

FUNCTION cbRepaint(Ihandle* iup_canvas)
  cd_canvas = (cdCanvas*)IupGetAttribute(iup_canvas, "cdCanvas")
  image = (imImage*)IupGetAttribute(iup_canvas, "imImage")
  IF NOT(cd_canvas) OR disable_repaint THEN RETURN IUP_DEFAULT  
  cdCanvasActivate(cd_canvas)
  cdCanvasClear(cd_canvas)
  IF NOT(image) THEN RETURN IUP_DEFAULT
  imcdCanvasPutImage(cd_canvas, image, 0, 0, image->width, image->height, 0, 0, 0, 0)
  cdCanvasFlush(cd_canvas)
  RETURN IUP_DEFAULT
END FUNCTION

SUB ShowImage(char* file_name, Ihandle* iup_dialog)
  image = (imImage*)IupGetAttribute(iup_dialog, "imImage")
  IF image THEN imImageDestroy(image)
  IupSetAttribute(iup_dialog, "imImage", NULL)
  image = imFileImageLoadBitmap(file_name, 0, &ierror)
  IF ierror THEN PrintError(ierror)
  IF NOT(image) THEN EXIT SUB
  IupSetAttribute(iup_dialog, "imImage", (STRING)image)
  IupStoreAttribute(iup_dialog, "TITLE", file_name);
  cbRepaint(iup_dialog)
END SUB

FUNCTION cbButton(Ihandle* iup_canvas, NUMBER but, NUMBER pressed)
  char file_name[200] = "*.*"
  IF (but <> IUP_BUTTON1 OR NOT(pressed)) THEN RETURN IUP_DEFAULT
  disable_repaint = 1
  IF IupGetFile(file_name) <> 0 THEN
    disable_repaint = 0
    RETURN IUP_DEFAULT
  END IF
  disable_repaint = 0
  ShowImage(file_name, IupGetDialog(iup_canvas))
  RETURN IUP_DEFAULT
END FUNCTION

FUNCTION cbClose(Ihandle* iup_dialog)
  cd_canvas = (cdCanvas*)IupGetAttribute(iup_dialog, "cdCanvas")
  image = (imImage*)IupGetAttribute(iup_dialog, "imImage")
  IF cd_canvas THEN cdKillCanvas(cd_canvas)
  IF image THEN imImageDestroy(image)
  IupSetAttribute(iup_dialog, "cdCanvas", NULL)
  IupSetAttribute(iup_dialog, "imImage", NULL)
  RETURN IUP_CLOSE
END FUNCTION

' MAIN

IupOpen(NULL,NULL)
iup_canvas = IupCanvas("do_nothing")
IupSetAttribute(iup_canvas, IUP_BUTTON_CB, "cbButton")
IupSetAttribute(iup_canvas, IUP_ACTION, "cbRepaint")
iup_dialog = IupDialog(iup_canvas)
IupSetAttribute(iup_dialog, IUP_CLOSE_CB, "cbClose")
IupSetAttribute(iup_dialog, IUP_SIZE, "HALFxHALF")
IupSetFunction("cbRepaint", (Icallback)cbRepaint)
IupSetFunction("cbButton", (Icallback)cbButton)
IupSetFunction("cbClose", (Icallback)cbClose)
IupMap(iup_dialog)
cd_canvas = cdCreateCanvas(CD_IUP, iup_canvas)
IupSetAttribute(iup_dialog, "cdCanvas", (STRING)cd_canvas)
IupShow(iup_dialog)

cmdln$ = ARGUMENT$
SPLIT cmdln$ BY " " TO opts$ SIZE cnt
IF cnt = 2 THEN
  ShowImage(opts$[1], iup_dialog)
ELSE  
  char file_name[1024] = "*.*"
  IF IupGetFile(file_name) = 0 THEN
    ShowImage(file_name, iup_dialog)
  END IF
END IF
                                  
IupMainLoop()
IupDestroy(iup_dialog)
IupClose()

im_view.inc
Code: [Select]
PRAGMA OPTIONS -I/usr/include/iup -I/usr/include/cd -I/usr/include/im
PRAGMA LDFLAGS iup cd iupcd im
PRAGMA INCLUDE iup.h cd.h cdiup.h im.h im_image.h

PROTO IupGetAttribute, cdCanvasActivate, cdCanvasClear, imcdCanvasPutImage, cdCanvasFlush, imImageDestroy, imFileImageLoadBitmap
PROTO IupSetAttribute, IupStoreAttribute, IupGetFile, IupGetDialog, cdKillCanvas, imImageDestroy, IupMessage
PROTO IupOpen, CreateDialog, IupCanvas, IupDialog, IupSetFunction, IupMap, cdCreateCanvas, IupShow, IupMainLoop, IupDestroy, IupClose

DECLARE *iup_dialog, *iup_canvas TYPE Ihandle
DECLARE *cd_canvas TYPE cdCanvas
DECLARE *image TYPE imImage
DECLARE ierror TYPE int
« Last Edit: January 08, 2013, 10:28:58 PM by JRS »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BaCon/IUP
« Reply #7 on: January 08, 2013, 08:57:48 PM »
This is an example of IUP and OpenGL.



Code: [Select]
' Example of using of 3D OpenGL and IUP

INCLUDE "iup_3dgl.inc"

SUB polygon(NUMBER a, NUMBER b, NUMBER c, NUMBER d)
  DECLARE vertices[][3] = {{-1,-1, 1}, {-1,1,1}, {1,1,1}, {1,-1,1}, \
                          {-1,-1,-1}, {-1,1,-1}, {1,1,-1}, {1,-1,-1}} TYPE double
  glBegin(GL_POLYGON)
    glVertex3dv(vertices[a])
    glVertex3dv(vertices[b])
    glVertex3dv(vertices[c])
    glVertex3dv(vertices[d])
  glEnd()
END SUB

SUB colorCube
  glColor3f(1,0,0)
  glNormal3f(1,0,0)
  polygon(2,3,7,6)

  glColor3f(0,1,0)
  glNormal3f(0,1,0)
  polygon(1,2,6,5)

  glColor3f(0,0,1)
  glNormal3f(0,0,1)
  polygon(0,3,2,1)

  glColor3f(1,0,1)
  glNormal3f(0,-1,0)
  polygon(3,0,4,7)

  glColor3f(1,1,0)
  glNormal3f(0,0,-1)
  polygon(4,5,6,7)

  glColor3f(0,1,1)
  glNormal3f(-1,0,0)
  polygon(5,4,0,1)
END SUB

FUNCTION repaint_cb(Ihandle *self)
  IupGLMakeCurrent(self)
  glClearColor(0.3f, 0.3f, 0.3f, 1.0f)
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
  glEnable(GL_DEPTH_TEST)
  glMatrixMode(GL_MODELVIEW)
  glPushMatrix()
    glTranslatef(0.0f, 0.0f , 0.0f)
    glScalef(1.0f, 1.0f, 1.0f)
    glRotatef(t, 0, 0, 1)
    colorCube()
  glPopMatrix()
  IupGLSwapBuffers(self)
  RETURN IUP_DEFAULT
END FUNCTION

FUNCTION resize_cb(Ihandle *self, NUMBER new_width, NUMBER new_height)
  IupGLMakeCurrent(self)
  glViewport(0, 0, new_width, new_height)
  glMatrixMode(GL_MODELVIEW)
  glLoadIdentity()
  glMatrixMode(GL_PROJECTION)
  glLoadIdentity()
  gluPerspective(60, 4./3., 1., 15)
  gluLookAt(3, 3, 3, 0, 0, 0, 0, 0, 1)
  width = new_width
  height = new_height
  repaint_cb(canvas)
  RETURN IUP_DEFAULT
END FUNCTION

FUNCTION idle_cb
  INCR t
  repaint_cb(canvas)
  RETURN IUP_DEFAULT
END FUNCTION

FUNCTION exit_cb
  RETURN IUP_CLOSE
END FUNCTION

' MAIN

IupOpen(NULL, NULL)
IupGLCanvasOpen()
canvas = IupGLCanvas("repaint_cb")
IupSetFunction("repaint_cb", (Icallback)repaint_cb)  
IupSetAttribute(canvas, IUP_RASTERSIZE, "640x480")
IupSetAttribute(canvas, IUP_BUFFER, IUP_DOUBLE)
IupSetCallback(canvas, "RESIZE_CB", (Icallback)resize_cb)
dialog = IupDialog(canvas)
IupSetAttribute(dialog, "TITLE", "IUP_3D_OpenGL")
IupSetCallback(dialog, "CLOSE_CB", (Icallback)exit_cb)
IupSetFunction (IUP_IDLE_ACTION, (Icallback)idle_cb)
IupShowXY(dialog, IUP_CENTER, IUP_CENTER)
IupMainLoop()
IupClose()

iup_3dgl.inc
Code: [Select]
CONST _CRT_SECURE_NO_WARNINGS

PRAGMA OPTIONS -I/usr/include/iup
PRAGMA LDFLAGS iup iupgl GL GLU
PRAGMA INCLUDE iup.h iupgl.h GL/gl.h GL/glu.h

PROTO IupOpen, IupGLCanvasOpen, IupShowXY, IupMainLoop, IupClose
PROTO IupSetFunction, IupSetAttribute, IupSetCallback, IupDialog
PROTO IupGLMakeCurrent, IupGLSwapBuffers
PROTO glBegin, glVertex3dv, glEnd, glColor3f, glNormal3f
PROTO glClearColor, glClear, glEnable, glMatrixMode
PROTO glPushMatrix, glTranslatef, glScalef, glRotatef, glPopMatrix
PROTO glViewport, glLoadIdentity, gluPerspective, gluLookAt

DECLARE *dialog, *canvas TYPE Ihandle
DECLARE width = 640, height = 480 TYPE int
DECLARE t = 0 TYPE float

To compile the original C version use the following command.

gcc iup_3dgl.c -I/usr/include/iup -liup -liupgl -lGL -lGLU -o cube
« Last Edit: January 09, 2013, 02:27:49 PM by JRS »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BaCon/IUP
« Reply #8 on: January 09, 2013, 02:58:10 PM »
IUP also has a Math GL library that is pretty cool. This demo is too much for me to convert to BaCon. I included a PDF of the C source (syntax highlighted) if you want to have a peek under the covers.



Source (PDF)
« Last Edit: January 09, 2013, 03:32:41 PM by JRS »