Extension Modules > IUP

IUP Linux and Windows

<< < (5/10) > >>

Support:
Here is the button.c example converted to ScriptBasic.

C Version


--- Code: ---'"""**************************************************************************
 *                             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                     *
 **************************************************************************"""

IMPORT iup.bas

' Defines released button's image
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
"""

' Defines pressed button's image
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
"""

' Defines inactive button's image
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
"""

GLOBAL CONST IUP_BUTTON1 = "1"
GLOBAL CONST IUP_CENTER = 65535


'"""***************************************************************************
 * 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                                                                *
 ***************************************************************************"""
SUB btn_on_off_cb

  ' Recovers "btn_image" handle
  btn_image = Iup::GetHandle( "btn_image" )

  ' If the button with with image is active...
  IF Iup::GetAttribute( btn_image, "ACTIVE" ) = "YES" THEN

    ' Deactivates the button with image
    Iup::SetAttribute( btn_image, "ACTIVE","NO" )

  ' else it is inactive
  ELSE
    ' Activates the button with image
    Iup::SetAttribute( btn_image, "ACTIVE", "YES" )
  END IF

  ' Executed function successfully
END SUB


'"""***************************************************************************
 * 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                                                                *
 ***************************************************************************"""
SUB btn_image_button_cb

  ' If the left button changed its state...
  IF CHR(Iup::GetBtnPressed()) = IUP_BUTTON1 THEN

    ' Recovers "text" handle
    text = Iup::GetHandle( "text" )

    ' If the button was pressed...
    IF Iup::GetBtnState() = 1 THEN

      ' Sets text's value
      Iup::SetAttribute( text, "VALUE", "Red button pressed" )

    ' else the button was released
    ELSE

      ' Sets text's value
      Iup::SetAttribute( text, "VALUE", "Red button released" )
    END IF
  END IF

' Executed function successfully
END SUB


'"""***************************************************************************
 * Function:                                                                  *
 * Exit button callback                                                       *
 *                                                                            *
 * Description:                                                               *
 * Callback called when exit button is activated. Exits the program           *
 *                                                                            *
 * Parameters received:                                                       *
 * self - element identifier                                                  *
 *                                                                            *
 * Value returned:                                                            *
 * IUP_DEFAULT                                                                *
 ***************************************************************************"""
SUB btn_exit_cb

  ' Exits the program
  Iup::ExitLoop = TRUE

END SUB

'"""***************************************************************************
 * Main function                                                              *
 ***************************************************************************"""

  ' Initializes IUP
  Iup::Open()

  ' Creates a text
  text = Iup::Text()
  Iup::SetAttribute(text,"SIZE","100x")

  ' Turns on read-only mode
  Iup::SetAttribute( text, "READONLY", "YES")

  ' Associates text with handle "text"
  Iup::SetHandle ( "text", text )

  ' Defines released button's image size
  img_release = Iup::Image(16, 16, Iup::CreateImg(pixmap_release))

  ' Defines released button's image colors
  Iup::SetAttribute( img_release, "1", "215 215 215" )
  Iup::SetAttribute( img_release, "2", "40 40 40" )
  Iup::SetAttribute( img_release, "3", "30 50 210" )
  Iup::SetAttribute( img_release, "4", "240 0 0" )

  ' Associates img_release with handle "img_release"
  Iup::SetHandle( "img_release", img_release)

  ' Defines pressed button's image size
  img_press = Iup::Image( 16, 16, Iup::CreateImg(pixmap_press))

  ' Defines pressed button's image colors
  Iup::SetAttribute( img_press, "1", "40 40 40" )
  Iup::SetAttribute( img_press, "2", "215 215 215" )
  Iup::SetAttribute( img_press, "3", "0 20 180" )
  Iup::SetAttribute( img_press, "4", "210 0 0" )

  ' Associates img_press with handle "img_press"
  Iup::SetHandle ( "img_press", img_press )

  ' Defines inactive button's image size
  img_inactive = Iup::Image( 16, 16, Iup::CreateImg(pixmap_inactive))

  ' Defines inactive button's image colors
  Iup::SetAttribute( img_inactive, "1", "215 215 215" )
  Iup::SetAttribute( img_inactive, "2", "40 40 40" )
  Iup::SetAttribute( img_inactive, "3", "100 100 100" )
  Iup::SetAttribute( img_inactive, "4", "200 200 200" )

  ' Associates img_inactive with handle "img_inactive"
  Iup::SetHandle ("img_inactive", img_inactive )

  ' Creates a button
  btn_image = Iup::Button( "Button with image", "btn_image")

  ' Sets released, pressed and inactive button images
  Iup::SetAttribute( btn_image, "IMAGE", "img_release" )
  Iup::SetAttribute( btn_image, "IMPRESS", "img_press" )
  Iup::SetAttribute( btn_image, "IMINACTIVE", "img_inactive" )

  ' Associates button callback with action bti_button_act
  Iup::SetAttribute( btn_image, "BUTTON_CB", "btn_image_button")

  ' Associates btn_image with handle "btn_image"
  Iup::SetHandle( "btn_image", btn_image )

  ' Creates a button
  btn_big = Iup::Button( "Big useless button" )

  ' Sets big button size
  Iup::SetAttribute( btn_big, "SIZE", "EIGHTHxEIGHTH" )

  ' Creates a button entitled Exit associated with action exit_act
  btn_exit = Iup::Button( "Exit", "btn_exit")

  ' Creates a button entitled on/off associated with action onoff_act
  btn_on_off = Iup::Button( "on/off", "btn_on_off")

  ' Creates dialog with the four buttons and the text
  dlg = Iup::Dialog _
        ( _
          Iup::Vbox _
          ( _
            Iup::Hbox _
            ( _
              btn_image, _
              btn_on_off, _
              btn_exit), _
            text, _
            btn_big))


  ' Sets dialogs title to IupButton turns resize, maximize, minimize and menubox off
  Iup::SetAttributes( dlg, "EXPAND = YES, TITLE = IupButton, RESIZE = YES" )
  Iup::SetAttributes( dlg, "MENUBOX = NO, MAXBOX = NO, MINBOX = NO" )

  ' Registers callbacks
  Iup::SetCallback( btn_exit, "ACTION", ADDRESS( btn_exit_cb() ))
  Iup::SetCallback( btn_on_off, "ACTION", ADDRESS( btn_on_off_cb() ))
  Iup::SetCallback( btn_image, "BUTTON_CB", ADDRESS( btn_image_button_cb() ))

  ' Shows dialog on the center of the screen
  Iup::ShowXY( dlg, IUP_CENTER, IUP_CENTER )


  ' Initializes IUP main loop
  Iup::MainLoop()

  ' Finishes IUP
  Iup::Close()

' Program finished successfully
END

--- End code ---

Support:
Here is the filedlg.c example in ScriptBasic.

C Version


--- Code: ---' IupFileDlg Example in ScriptBasic
' Shows a typical file-saving dialog.

IMPORT iup.bas

GLOBAL CONST IUP_CENTER = 0xFFFF

Iup::Open()
Iup::SetLanguage("ENGLISH")

filedlg = Iup::FileDlg()

Iup::SetAttributes(filedlg, "DIALOGTYPE = SAVE, TITLE = \"File Save\"")
Iup::SetAttributes(filedlg, "FILTER = \"*.sb\", FILTERINFO = \"ScriptBasic Files\"")

Iup::Popup(filedlg, IUP_CENTER, IUP_CENTER)

response = Iup::GetInt(filedlg, "STATUS")
IF response = 1 THEN Iup::Message("New file",Iup::GetAttribute(filedlg, "VALUE"))
IF response = 0 THEN Iup::Message("File already exists",Iup::GetAttribute(filedlg, "VALUE"))
IF response = -1 THEN Iup::Message("IupFileDlg","Operation Canceled")

Iup::Destroy(filedlg)
Iup::Close()
END

--- End code ---

Support:
Icon, menu and a cursor change to show with this dialog1.c example.

C Version


--- Code: ---' IupDialog: Example in ScriptBasic
' Creates a dialog showing an icon, the "DEFAULTESC" attribute and a simple menu

IMPORT iup.bas

GLOBAL CONST IUP_CENTER = 0xFFFF

' defines icon's image
img = """
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,1,
1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,
1,3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,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5,6,6,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,2,
1,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,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
"""

SUB quit_cb
  Iup::ExitLoop = TRUE
END SUB

Iup::Open()

' Creating dialog's icon
icon = Iup::Image(32, 32, Iup::CreateImg(img))
Iup::SetAttribute(icon, "1", "255 255 255")
Iup::SetAttribute(icon, "2", "000 000 000")
Iup::SetAttribute(icon, "3", "226 226 226")
Iup::SetAttribute(icon, "4", "128 128 128")
Iup::SetAttribute(icon, "5", "192 192 192")
Iup::SetAttribute(icon, "6", "000 000 255")
Iup::SetHandle("icon", icon)

' Creating dialog's content
quit_bt = Iup::Button("Quit")
Iup::SetCallback(quit_bt, "ACTION", ADDRESS(quit_cb()))
Iup::SetHandle("quit", quit_bt)

' Creating dialog's menu
options = Iup::Menu(Iup::Item("Exit","quit_cb"))
submenu = Iup::Submenu("File", options)
menu = Iup::Menu(submenu)
Iup::SetHandle("menu", menu)

' Creating main dialog
dialog = Iup::Dialog(Iup::Vbox(quit_bt))
Iup::SetAttribute(dialog, "TITLE", "IupDialog")
Iup::SetAttribute(dialog, "MENU", "menu")
Iup::SetAttribute(dialog, "CURSOR", "CROSS")
Iup::SetAttribute(dialog, "ICON", "icon")
Iup::SetAttribute(dialog, "DEFAULTESC", "quit")

Iup::ShowXY(dialog, IUP_CENTER, IUP_CENTER)
Iup::MainLoop()
Iup::Close()
END

--- End code ---

Support:
BUILD 8

This fixes a couple things with Iup::Image and a fix to integers in the argument passing macro. (thanks Armando)





Support:
BUILD 9

This release allows assigning multiple callback functions to a single control.

Sure would be nice to hear some feedback from others that have given the ScriptBasic IUP environment a try.

I don't see the point of adding the extended IUP API (OpenGL, Matrix, Drawing, Embedded Browser, ...) binding to the project if no one is going to use the core IUP features.

This will be the last release of the core IUP extension module unless someone finds a problem with it.

Enjoy!


Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version