Author Topic: O2 / IUP  (Read 8539 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
O2 / IUP
« on: January 11, 2013, 06:31:20 AM »
Peter from the OxygenBasic forum created an include file for IUP that makes using the library easy.



iup_hello.o2bas
Code: [Select]
include "iup.inc"

IupOpen(0,0)
IupShow(IupDialog(IupLabel("Hello World!")))
IupMainLoop()
IupClose()

iup.inc (work-in-process)
Code: [Select]
#define IUP_TITLE  "TITLE"

% IUP_CENTERPARENT = 65530
% IUP_CENTER  = 65535
% IUP_LEFT    = 65534
% IUP_RIGHT   = 65533
% IUP_MOUSEPOS= 65532
% IUP_CURRENT = 65531
% IUP_TOP     = IUP_LEFT
% IUP_BOTTOM  = IUP_RIGHT

% IUP_CLOSE   =-3  
% IUP_ERROR   = 1
% IUP_NOERROR = 0
% IUP_OPENED  =-1
% IUP_INVALID =-1
% IUP_IGNORE  =-1
% IUP_DEFAULT =-2
% IUP_CLOSE   =-3
% IUP_CONTINUE=-4

% IUP_BUTTON1 = 1
% IUP_BUTTON2 = 2
% IUP_BUTTON3 = 3
% IUP_BUTTON4 = 4
% IUP_BUTTON5 = 5

enum {IUP_SBUP,   IUP_SBDN,    IUP_SBPGUP,   IUP_SBPGDN,   IUP_SBPOSV, IUP_SBDRAGV,
     IUP_SBLEFT, IUP_SBRIGHT, IUP_SBPGLEFT, IUP_SBPGRIGHT, IUP_SBPOSH, IUP_SBDRAGH}

enum {IUP_DRAW_FILL, IUP_DRAW_STROKE, IUP_DRAW_STROKE_DASH}
enum {IUP_SHOW,IUP_RESTORE,IUP_MINIMIZE,IUP_MAXIMIZE,IUP_HIDE}

typedef struct Ihandle_ {}
Ihandle_ Ihandle

typedef int (*Icallback)(Ihandle*)

typedef struct _IdrawCanvas {}
_IdrawCanvas IdrawCanvas

! IupOpen             Lib "iup.dll" (sys argc,argv) as sys  
! IupCreate           Lib "iup.dll" (string cname) as sys  
! IupDialog           Lib "iup.dll" (sys ih) as sys
! IupLabel            Lib "iup.dll" (char *title) as sys
! IupImageLibOpen     Lib "iup.dll" ()
! IupMainLoop         Lib "iup.dll" () as sys
! IupLoopStep         Lib "iup.dll" () as sys
! IupLoopStepWait     Lib "iup.dll" () as sys
! IupMainLoopLevel    Lib "iup.dll" () as sys
! IupFlush            Lib "iup.dll" ()
! IupExitLoop         Lib "iup.dll" ()

! IupRecordInput      Lib "iup.dll" (char *filename, sys mode) as sys
! IupPlayInput        Lib "iup.dll" (char *filename) as sys
! IupUpdate           Lib "iup.dll" (sys ih)
! IupUpdateChildren   Lib "iup.dll" (sys ih)
! IupRedraw           Lib "iup.dll" (sys ih, children)
! IupRefresh          Lib "iup.dll" (sys ih)
! IupRefreshChildren  Lib "iup.dll" (sys ih)  

! IupMapFont          Lib "iup.dll" (char *iupfont) as string
! IupUnMapFont        Lib "iup.dll" (char *driverfont) as string
! IupHelp             Lib "iup.dll" (string url) as sys
! IupLoad             Lib "iup.dll" (char *filename) as string
! IupLoadBuffer       Lib "iup.dll" (char *buffer) as string
! IupVersion          Lib "iup.dll" () as string
! IupVersionDate      Lib "iup.dll" () as string
! IupVersionNumber    Lib "iup.dll" () as sys
! IupSetLanguage      Lib "iup.dll" (char *lng)
! IupGetLanguage      Lib "iup.dll" () as string

! IupDestroy          Lib "iup.dll" (sys ih)
! IupDetach           Lib "iup.dll" (sys child)
! IupAppend           Lib "iup.dll" (sys ih, child) as sys
! IupInsert           Lib "iup.dll" (sys ih, ref_child, child) as sys
! IupGetChild         Lib "iup.dll" (sys ih, sys pos) as sys
! IupGetChildPos      Lib "iup.dll" (sys ih, child) as sys
! IupGetChildCount    Lib "iup.dll" (sys ih) as sys
! IupGetNextChild     Lib "iup.dll" (sys ih, child) as sys
! IupGetBrother       Lib "iup.dll" (sys ih) as sys
! IupGetParent        Lib "iup.dll" (sys ih) as sys
! IupGetDialog        Lib "iup.dll" (sys ih) as sys
! IupGetDialogChild   Lib "iup.dll" (sys ih, char *name) as sys
! IupReparent         Lib "iup.dll" (sys ih, new_parent, ref_child) as sys

! IupPopup            Lib "iup.dll" (sys ih, x, y) as sys
! IupShow             Lib "iup.dll" (sys ih) as sys
! IupShowXY           Lib "iup.dll" (sys ih, x, y) as sys
! IupHide             Lib "iup.dll" (sys ih) as sys
! IupMap              Lib "iup.dll" (sys ih) as sys
! IupUnmap            Lib "iup.dll" (sys ih)

! IupSetAttribute     Lib "iup.dll"  (sys ih, char *name, char *value)
! IupSetAttributes    Lib "iup.dll" (sys ih,string strz) as sys  
! IupAppend           Lib "iup.dll" (sys ih, child) as sys  
! IupRefresh          Lib "iup.dll" (sys ih)  
! IupSetCallback      Lib "iup.dll" (sys ih, char *sname, sys func) as sys callback
! IupSetFocus         Lib "iup.dll" (sys ih) as sys  
! IupImageLibOpen     Lib "iup.dll" () as sys
! IupClose            Lib "iup.dll" ()
! IupGetColor         Lib "iup.dll" (sys x, y, char *r, *g, *b) as sys
! IupSetFocus         Lib "iup.dll" (sys ih) as sys
! IupGetFocus         Lib "iup.dll" () as sys
! IupPreviousField    Lib "iup.dll" (sys ih) as sys  
! IupNextField        Lib "iup.dll" (sys ih) as sys
! IupGetFunction      Lib "iup.dll" (char *name) as sys
! IupSetFunction      Lib "iup.dll" (char *name, sys func) as sys callback
! IupGetActionName    Lib "iup.dll" () as string

! IupFill             Lib "iup.dll" () as sys
! IupRadio            Lib "iup.dll" (sys child) as sys
! IupVbox             Lib "iup.dll" (sys child) as sys
! IupVboxv            Lib "iup.dll" (sys *children) as sys
! IupZbox             Lib "iup.dll" (sys child) as sys
! IupZboxv            Lib "iup.dll" (sys *children) as sys
! IupHbox             Lib "iup.dll" (sys child) as sys
! IupHboxv            Lib "iup.dll" (sys *children) as sys
! IupNormalizer       Lib "iup.dll" (sys ih_first) as sys
! IupNormalizerv      Lib "iup.dll" (sys *ih_list) as sys
! IupCbox             Lib "iup.dll" (sys child) as sys
! IupCboxv            Lib "iup.dll" (sys *children) as sys
! IupSbox             Lib "iup.dll" (sys child) as sys
! IupSplit            Lib "iup.dll" (sys child1, child2) as sys
! IupFrame            Lib "iup.dll" (sys child) as sys
! IupImage            Lib "iup.dll" (sys width, height, char *pixmap) as sys
! IupImageRGB         Lib "iup.dll" (sys width, height, char *pixmap) as sys
! IupImageRGBA        Lib "iup.dll" (sys width, height, char *pixmap) as sys
! IupItem             Lib "iup.dll" (char *title, char *action) as sys
! IupSubmenu          Lib "iup.dll" (char *title, sys child) as sys
! IupSeparator        Lib "iup.dll" () as sys
! IupMenu             Lib "iup.dll" (sys child) as sys
! IupMenuv            Lib "iup.dll" (sys *children) as sys
! IupButton           Lib "iup.dll" (char *title, char *action) as sys
! IupCanvas           Lib "iup.dll" (char *action) as sys
! IupUser             Lib "iup.dll" () as sys
! IupLabel            Lib "iup.dll" (char *title) as sys
! IupList             Lib "iup.dll" (char *action) as sys
! IupText             Lib "iup.dll" (char *action) as sys
! IupMultiLine        Lib "iup.dll" (char *action) as sys
! IupToggle           Lib "iup.dll" (char *title, char *action) as sys
! IupTimer            Lib "iup.dll" () as sys
! IupClipboard        Lib "iup.dll" () as sys
! IupProgressBar      Lib "iup.dll" () as sys
! IupVal              Lib "iup.dll" (char *type) as sys
! IupTabs             Lib "iup.dll" (sys child) as sys
! IupTabsv            Lib "iup.dll" (sys *children) as sys
! IupTree             Lib "iup.dll" () as sys
! IupGetFile          Lib "iup.dll" (char *arq) as sys
! IupMessage          Lib "iup.dll" (char *title, *msg)
! IupMessagef         Lib "iup.dll" (char *title, *format)
! IupAlarm            Lib "iup.dll" (char *title, *msg, *b1, *b2, *b3) as sys

! iupDrawCreateCanvas Lib "iup.dll" (Ihandle *ih) as sys
! iupDrawKillCanvas   Lib "iup.dll" (sys *dc)
! iupDrawFlush        Lib "iup.dll" (sys *dc)
! iupDrawUpdateSize   Lib "iup.dll" (sys *dc)
! iupDrawGetSize      Lib "iup.dll" (sys *dc, *w, *h)
! iupDrawLine         Lib "iup.dll" (sys *dc, x1, y1, x2, y2, byte r, g, b, sys style)
! iupDrawRectangle    Lib "iup.dll" (sys *dc, x1, y1, x2, y2, byte r, g, b, sys style)
! iupDrawArc          Lib "iup.dll" (sys *dc, x1, y1, x2, y2, double a1, a2, byte r, g, b, sys style)
! iupDrawPolygon      Lib "iup.dll" (sys *dc, *points, count, byte r, g, b, sys style)
! iupDrawText         Lib "iup.dll" (sys *dc, char *text, sys len, x, y, byte r, g, b, char *font)
! iupDrawImage        Lib "iup.dll" (sys *dc, char *name, sys make_inactive, x, y, *img_w, *img_h)
! iupDrawSetClipRect  Lib "iup.dll" (sys *dc, x1, y1, x2, y2)
! iupDrawResetClip    Lib "iup.dll" (sys *dc)

! iupDrawRectangleInvert  Lib "iup.dll" (sys *dc, x1, y1, x2, y2)
! iupDrawParentBackground Lib "iup.dll" (sys *dc)

/* NOT COMPLETE YET  */
« Last Edit: January 11, 2013, 07:26:41 AM by JRS »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: O2 / IUP
« Reply #1 on: January 13, 2013, 04:28:03 PM »
The OxygenBasic IUP team is making progress and we solved our callback and resource embedding issues. Peter Wirbelauer has teken the IUP lead for the O2 project and is building an include set of IUP definitions to make using the GUI toolkit easier.





Code: [Select]
include "iup.inc"
sys win

Sub Btn1_clicked() callback
  static sys a
  a +=1
  PRINT "BUTTON 1 Event  " + a "x pressed"
End Sub

Sub Btn2_clicked() callback
  static sys a
  a +=1
  PRINT "BUTTON 2 Event  " + a "x pressed"
End Sub

Sub Btn3_clicked() callback
  static sys a
  a +=1
  PRINT "BUTTON 3 Event  " + a "x pressed"
End Sub

IupOpen(0,0)
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", @Btn1_clicked)    
IupSetCallback(btn2,"ACTION", @Btn2_clicked)  
IupSetCallback(btn3,"ACTION", @Btn3_clicked)  
IupShow(win)
IupMainLoop()
IupClose()

This is an example using the CD (Canvas Draw) features of the toolkit.



Code: [Select]
include "iup.inc"
sys win,cvas

Sub Text() callback
    iupDrawText *cvas,"APPLES ARE FUNNY",16, 150,10, 200,200,248,""
    iupDrawRectangle *cvas, 144,8, 148+140,20+8, 255,255,255, 1
    iupDrawRectangle *cvas, 100,80, 100+210,64+80, 255,0,255, 0
    iupDrawText *cvas,"IUP BANANAS ARE DELICIOUS",26, 105,100, 255,255,255, ""
    iupDrawImage *cvas,"iup.bmp",1,180,200,102,100
    iupDrawFlush *cvas
End Sub

IupOpen(0,0)
win=iupCreate "dialog"
IupSetAttributes win,"TITLE=OXYGENBASIC, SIZE=320x240"
IupShow win  
cvas=IupDrawCreateCanvas (win)
IupSetCallback cvas,"ACTION", Text

IupMainLoop()  
IupDrawKillCanvas *cvas
IupClose()  

At this point I'm leaning towards OxygenBasic as my Windows IUP development environment. (ScriptBasic has already been embedded in O2 some time ago so both of my bases are covered)

« Last Edit: January 13, 2013, 05:28:38 PM by JRS »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: O2 / IUP
« Reply #2 on: January 14, 2013, 08:54:53 AM »
Charles is making great progress with using standard C headers (.h) with OxygenBasic.

Code: [Select]
includepath "C:\iup\include\"    
extern lib "iup.dll" cdecl    
include "iup.h"
end extern      
  
sys win, horzbox, btn1, btn2, btn3  

extern cdecl


FUNCTION Btn1_clicked(iHandle* h) as sys  
  static sys a  
  a +=1  
  PRINT "BUTTON 1 Event  " + a "x pressed"  
  RETURN IUP_DEFAULT  
END FUNCTION
  
FUNCTION Btn2_clicked(iHandle* h) as sys  
  static sys a  
  a +=1  
  PRINT "BUTTON 2 Event  " + a "x pressed"  
  RETURN IUP_DEFAULT  
END FUNCTION  
  
FUNCTION Btn3_clicked(iHandle* h) as sys
  static sys a  
  a +=1  
  PRINT "BUTTON 3 Event  " + a "x pressed"  
  RETURN IUP_DEFAULT  
END FUNCTION

end extern
 
  
IupOpen(0,0)  
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", @Btn1_clicked)      
IupSetCallback(btn2,"ACTION", @Btn2_clicked)    
IupSetCallback(btn3,"ACTION", @Btn3_clicked)    
IupShow(win)  
IupMainLoop()  
IupClose()  

Note You need to use the latest A39 Oxygen.dll to follow along with the IUP examples posted.

Other O2 News:
Quote
This new version of Oxygen also supports dead code removal. It can take out all unused functions,subs and methods when the #compact directive is used. (Warning! If any Basic procedure is called exclusively from assembler, it will not be tagged as used, and will be thrown out!)

This allows programmers to work with large source code libraries, and still produce small binaries.

I have also extended the addr pseudo-instruction to resolve addresses of labels and string literals as well as variables.

.here
addr ecx,here

addr eax, "Hello World" '(must use eax for strings)

sys a,b,c
addr ecx,a

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: O2 / IUP
« Reply #3 on: January 16, 2013, 06:58:49 AM »
Just in case you need to define more than one dll and a .h include file.

Code: [Select]
extern cdecl
library "lib1.dll"
include "lib1.h"
library "lib2.dll"
include "lib2.h"
library "lib3.dll"
include "lib3.h"
end extern

Both OxygenBasic and BaCon are making working with C libraries, structures and definitions a natural extension to Basic.