Author Topic: O2 IUP  (Read 6552 times)

0 Members and 1 Guest are viewing this topic.

JRS

  • Guest
O2 IUP
« on: December 05, 2012, 07:04:10 PM »
Hi Charles,

I'm trying to get a Hello World example in IUP. with O2. This is what I have but doesn't work.

Code: OxygenBasic
  1. extern lib "iup.dll"
  2.   declare function IupOpen(sys arg1, sys* arg2) as sys
  3.   declare function IupShow(sys arg1) as sys
  4.   declare function IupDialog(sys* arg1) as *sys
  5.   declare function IupLabel(char* arg1) as *sys
  6.   declare function IupMainLoop() as sys
  7.   declare function IupClose()
  8. end extern
  9.  
  10. IupOpen(0,0)
  11. IupShow(IupDialog(IupLabel("Hello World!")))
  12. IupMainLoop()
  13. IupClose()
  14.  

I though we could use C .h include files with O2.

I'm just getting started with O2 so be kind.  ;)
« Last Edit: December 05, 2012, 07:15:26 PM by JRS »

JRS

  • Guest
Re: O2 IUP
« Reply #1 on: December 05, 2012, 08:47:47 PM »
Code: OxygenBasic
  1. declare function lib "iup.dll" IupOpen(Byval arg1 as long, Byval arg2 as sys) as long
  2. declare function lib "iup.dll" IupShow(Byval ih as sys) as long
  3. declare function lib "iup.dll" IupDialog(Byval ih as sys) as sys
  4. declare function lib "iup.dll" IupLabel(Byval title as string) as sys
  5. declare function lib "iup.dll" IupMainLoop() as long
  6. declare function lib "iup.dll" IupClose()
  7.  
  8. IupOpen(0,0)
  9. IupShow(IupDialog(IupLabel("Hello World!")))
  10. IupMainLoop()
  11. IupClose()
  12.  

No luck with this attempt either.  :'(

Charles Pegge

  • Guest
Re: O2 IUP
« Reply #2 on: December 06, 2012, 12:49:05 AM »
Hi John,

We had trouble with different versions of iup.dll

http://www.oxygenbasic.org/forum/index.php?topic=545.30

Quote
The problem was the IupOpen.
This compiles and runs fine.
I used
http://sourceforge.net/projects/iup/files/3.6/Windows%20Libraries/Dynamic/iup-3.6_Win32_dllw4_lib.zip/download
...
James Fuller

Try removing the params from IupOpen()

« Last Edit: December 06, 2012, 12:54:24 AM by Charles Pegge »

JRS

  • Guest
Re: O2 IUP
« Reply #3 on: December 06, 2012, 01:28:46 AM »
No luck using the 3.7 MinGW iup.dll set.

Can you post a fixed Hello World so I at least know the O2 code is right?

I'm using your latest WIP O2 set.

JRS

  • Guest
Re: O2 IUP
« Reply #4 on: December 06, 2012, 01:47:57 AM »
I was able to get James's O2 IUP example to compile and run.



Code: OxygenBasic
  1.  
  2. %IUP_CLOSE = -3
  3. %IUP_ERROR = 1
  4.  
  5.  
  6. extern lib "iup.dll" cdecl
  7. ! IupOpen()
  8. ! IupCreate(string cname) as sys
  9. ! IupClose         ()
  10. ! IupSetAttributes (sys ih,string strz) as sys
  11. ! IupAppend        (sys ih, child) as sys
  12. ! IupRefresh       (sys ih)
  13. ! IupSetCallback   (sys ih,string sname, sys func) as sys
  14. ! IupShow          (sys ih) as sys
  15. ! IupSetFocus      (sys ih) as sys
  16. ! IupMainLoop      ()
  17.  
  18. end extern
  19.  
  20. extern cdecl
  21.  
  22. 'Exit Button Callback
  23. function quit_cb() as sys
  24.   function = %IUP_CLOSE
  25. end function
  26.  
  27.  
  28. 'Helper functions
  29. '================
  30.  
  31.  
  32.  
  33. sub AddChild(sys *parent, *child)
  34.   IupAppend parent,child
  35.   IupRefresh parent
  36. end sub
  37.  
  38.  
  39. function Create ( string Value ,Attr ,sys parent) as sys
  40.   sys hWnd
  41.   hWnd = IupCreate(Value)
  42.   If hWnd Then
  43.     If Len(Attr)
  44.       IupSetAttributes(hWnd,Attr)
  45.     End If
  46.     If parent
  47.       AddChild parent,hWnd
  48.     End If    
  49.     Function = hWnd
  50.   End If    
  51. end function
  52.  
  53. function main () as sys
  54.   long rv As long
  55.   sys  win,vbox,topBox,serverFrame,serverBox,serverCombo,btnFetch,controlFrame,
  56.        controlBox,btnAbout,btnClear,btnExit,dictFrame,serverList,transFrame,
  57.        text,bottomBox,label,entry,btnSearch,chkAll,chkUTF
  58.   'Initialize IUP      
  59.  IupOpen()
  60.  
  61.    
  62.   'Create Main Window
  63.  win = Create("dialog","TITLE=Thesaurus, SIZE=500x300",0)
  64.   'create container to house ALL GUI objects
  65.  vbox = Create("vbox","MARGIN=10x10",0)
  66.   'Create Server panel
  67.  topBox = Create("hbox", " GAP=10", vbox)
  68.   serverFrame = Create("frame", "TITLE=Servers, EXPAND=YES", topBox)
  69.   serverBox= Create("hbox", "GAP=5", serverFrame)
  70.   serverCombo = Create("list", "DROPDOWN=YES, SIZE=120x, EXPAND=HORIZONTAL, VALUE=1", serverBox)
  71.   btnFetch = Create("button", "TITLE=Fetch, SIZE = 50x", serverBox)
  72.   'Create control panel
  73.  controlFrame = Create("frame", "TITLE=Controls", topBox)
  74.   controlBox = Create("hbox", "Margin=6x6, GAP=5", controlFrame)
  75.   btnAbout = Create("button", "TITLE=About, SIZE = 50x", controlBox)
  76.   btnClear = Create("button", "TITLE=Clear, SIZE = 50x", controlBox)
  77.   btnExit = Create("button", "TITLE=Exit, SIZE = 50x", controlBox)
  78.   'SETUP CALLBACK FOR EXIT BUTTON
  79.  IupSetCallback(btnExit, "ACTION", @quit_cb)
  80.   'Create dictionary panel
  81.  dictFrame = Create("frame", "TITLE=Dictionaries", vbox)
  82.   serverList = Create("list", "EXPAND=YES, VISIBLELINES=1", dictFrame)
  83.   'Create text part
  84.  transFrame = Create("frame", "TITLE=Translation", vbox)
  85.   text = Create("text", "MULTILINE=YES, EXPAND=YES", transFrame)
  86.   'Create entry and search button
  87.  bottomBox = Create("hbox", "GAP=10", vbox)
  88.   label = Create("label", "TITLE=Enter Word to Search For: , SIZE=x12", bottomBox)
  89.   entry = Create("text", " EXPAND=HORIZONTAL",bottomBox)
  90.   btnSearch = Create("button","TITLE=Search, SIZE=50x", bottomBox)
  91.   chkAll = Create("toggle", "TITLE=ALL, VALUE=ON,SIZE=x12", bottomBox)
  92.   chkUTF = Create("toggle", "TITLE=UTF-8, SIZE=x12", bottomBox)
  93.   '        
  94.  'Add the main GUI container to the Window
  95.  AddChild(win, vbox)
  96.   'Show the Window
  97.  IupShow(win)
  98.   IupSetFocus(btnFetch)
  99.   IupMainLoop()
  100.   IupClose()
  101. end function
  102.  
  103. main
  104.  
« Last Edit: December 06, 2012, 01:54:55 AM by JRS »

Charles Pegge

  • Guest
Re: O2 IUP
« Reply #5 on: December 06, 2012, 03:22:35 AM »
Try this:

Code: OxygenBasic
  1. extern lib "iup.dll"  cdecl
  2.   declare function IupOpen(sys argc,argv) as sys  
  3.   declare function IupShow(sys arg1) as sys  
  4.   declare function IupDialog(sys arg1) as sys
  5.   declare function IupLabel(char* arg1) as sys
  6.   declare function IupMainLoop() as sys  
  7.   declare function IupClose()  
  8. end extern  
  9.  
  10. IupOpen(null,null)  
  11. IupShow(IupDialog(IupLabel("Hello World!")))  
  12. IupMainLoop()  
  13. IupClose()  
  14.  

I interpret IHandle* as sys

Charles
« Last Edit: December 06, 2012, 08:07:33 AM by Charles Pegge »

Peter

  • Guest
Re: O2 IUP
« Reply #6 on: December 06, 2012, 05:56:37 AM »
Another IUP demo.
Code: [Select]
#define IUP_TITLE  "TITLE"

%IUP_CLOSE = -3 
%IUP_ERROR = 1 

enum { IUP_DRAW_FILL, IUP_DRAW_STROKE, IUP_DRAW_STROKE_DASH }

typedef struct Ihandle_ {}
Ihandle_ Ihandle
typedef int (*Icallback)(Ihandle*)
typedef struct _IdrawCanvas {}
_IdrawCanvas IdrawCanvas

extern Lib"iup.dll" 'cdecl
! IupOpen                 (sys argc,argv) as sys 
! IupCreate               (string cname) as sys 
! IupSetAttributes        (sys ih,string strz) as sys 
! IupAppend               (sys ih, child) as sys 
! IupRefresh              (sys ih) 
! IupSetCallback          (sys ih,string sname, sys func) as sys 
! IupShow                 (sys ih) as sys 
! IupShowXY               (Ihandle *ih, sys x, sys y) as sys
! IupSetFocus             (sys ih) as sys 
! IupRecordInput          (string *filename, sys mode) as sys
! IupPlayInput            (string *filename) as sys
! IupMainLoop             () as sys
! IupImageLibOpen         () as sys
! IupLoopStep             () as sys
! IupLoopStepWait         () as sys
! IupMainLoopLevel        () as sys
! IupClose                () as sys
! IupFlush                () as sys
! IupExitLoop             () as sys
! IupUpdate               (Ihandle *ih)
! IupUpdateChildren       (Ihandle *ih)
! IupRedraw               (Ihandle *ih, sys children)
! IupRefresh              (Ihandle *ih)
! IupRefreshChildren      (Ihandle *ih) 
! IupMapFont              (string *iupfont) as string
! IupUnMapFont            (string *driverfont) as string
! IupHelp                 (string url) as sys
! IupLoad                 (string *filename) as string
! IupLoadBuffer           (string *buffer) as string
! IupVersion              () as string
! IupVersionDate          () as string
! IupVersionNumber        () as sys
! IupSetLanguage          (string *lng)
! IupGetLanguage          () as string

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

! iupDrawRectangleInvert  (sys *dc, x1, y1, x2, y2)
! iupDrawParentBackground (sys *dc)
end extern

'variables
sys canvas, width, height,w=128

'mainsetting
IupOpen(0,0)
win=iupCreate "dialog"
IupSetAttributes win,"TITLE= NATURAL-SCIENCE, SIZE=320x240"
iupShow win 
canvas=IupDrawCreateCanvas *win
iupDrawGetSize *canvas, *width, *height 
iupDrawRectangle *canvas, 0, 0, 640, 480, 255, 255, 255, 0
iupDrawRectangle *canvas, 10, 10, 40, 40, 255, 0, 0, 0
iupDrawRectangle *canvas, 50, 10, 90, 40, 0,0,0, 1
iupDrawRectangle *canvas, 100,10, 140,40, 255,0,255, 2
iupDrawLine *canvas, 0, 100, &width, 100, 0,255,200, 2 
iupDrawText *canvas, "HUHU", 4, 50,50, 0,0,0, "arial"
iupDrawImage *canvas, "alarm1.bmp",1,120,120, &w, &w
iupDrawFlush *canvas
iupMainLoop 
iupDrawKillCanvas *canvas
iupClose 


X

Charles Pegge

  • Guest
Re: O2 IUP
« Reply #7 on: December 06, 2012, 08:20:23 AM »
Thanks Peter.

Looking at your IUP demo header, the IUP functions that return strings: These should return char* not string. They are null terminated C strings with no length field.

But char* parameters can be translated to string since strings have both a hidden length field and a null terminator.

Examples:
Code: [Select]
! IupMapFont              (string iupfont) as char*
! IupUnMapFont            (string driverfont) as char*
! IupLoad                 (string filename) as char*
! IupLoadBuffer           (string buffer) as char*
! IupVersion              () as char*
! IupVersionDate          () as char*

Charles

« Last Edit: December 06, 2012, 08:26:15 AM by Charles Pegge »

JRS

  • Guest
Re: O2 IUP
« Reply #8 on: December 06, 2012, 09:52:33 AM »
Thanks Charles. The IUP Hello World in OxygenBasic now works.



Code: OxygenBasic
  1. extern lib "iup.dll"  cdecl  
  2. declare function IupOpen(sys argc,argv) as sys    
  3. declare function IupShow(sys arg1) as sys    
  4. declare function IupDialog(sys arg1) as sys  
  5. declare function IupLabel(char* arg1) as sys  
  6. declare function IupMainLoop() as sys    
  7. declare function IupClose()    
  8. end extern    
  9.        
  10. IupOpen(null,null)    
  11. IupShow(IupDialog(IupLabel("Hello World!")))    
  12. IupMainLoop()    
  13. IupClose()    
  14.  

How many different ways does O2 allow defining external interfaces/libraries? I have seen at least four different methods so far.

JRS

  • Guest
Re: O2 IUP
« Reply #9 on: December 06, 2012, 10:15:52 AM »
@Peter - I tried your example (screen scrape) without Charles changes and it worked. What I did notice is that if you minimize the screen and restore it, your canvas is blank. I ran into this with my IUP CD Mandelbrot demo in SB. (I was just happy to see anything on the screen back then)


Aurel

  • Guest
Re: O2 IUP
« Reply #10 on: December 06, 2012, 02:22:45 PM »
John ...
I know that you insist on Iup because is crossplatform ...
but did you ever try use native win32 api for GUI interface with script basic?

JRS

  • Guest
Re: O2 IUP
« Reply #11 on: December 06, 2012, 04:57:18 PM »
You can't be serious. I can't even get the MS VC10 compiler to work reliably and you want me to write a callback based interface to an interpreter with the Win32 API?

Maybe you can change my mind. Here is your chance. Recreate the IUP Hello World example above using the Win32API and O2 and lets compare the benefits of each approach. (top down, no includes)

My plan is to use OxygenBasic and IUP as the Windows SB IDE. Charles has already invested a lot of time getting the SB embedding interface working with O2. I will use BaCon and IUP on the Linux side for the IDE. This will allow SB to run interactively with the user and execute Basic expressions from the IDE prompt. (like Business Basic, old QB 1.1 and other spin offs) SB will retain it's command line and console(less) versions with the IDE as a new SB enhancement.

« Last Edit: December 06, 2012, 07:01:47 PM by JRS »

Aurel

  • Guest
Re: O2 IUP
« Reply #12 on: December 06, 2012, 10:20:41 PM »
Quote
My plan is to use OxygenBasic and IUP as the Windows SB IDE.

Of course i understand your point....but on this way you still need iup.dll ,right?
But with Oxygen Basic and win32 api you can build IDE without external dll,right?

JRS

  • Guest
Re: O2 IUP
« Reply #13 on: December 06, 2012, 10:31:25 PM »
Quote
Of course i understand your point....but on this way you still need iup.dll ,right?
But with Oxygen Basic and win32 api you can build IDE without external dll,right

IUP can be linked dynamically or statically or a combination of both like the SB IUP extension module. (DLL -  static linked IUP)

JRS

  • Guest
Re: O2 IUP
« Reply #14 on: December 07, 2012, 09:36:53 PM »
How would I define a function that has a variable number of arguments in O2? (terminated with a null argument)