Menu

Agar GUI toolkit

GnuCOBOL
2017-10-07
2023-06-16
1 2 3 .. 7 > >> (Page 1 of 7)
  • Brian Tiffin

    Brian Tiffin - 2017-10-07

    Found another promising GUI kit

    http://www.libagar.org/index.html

    https://github.com/JulNadeauCA/libagar

    Feature complete, C, C++ and Ada

    Pat, you might like to check out the Ada bindings.

    Plots. ;-)

    Haven't read much yet, so the styling is default. Did change the Hello world to set a window size as it was sized too small to properly show the label for the screen capture. That's about as far as I got in the docs. This is the 15 minute in trial. There is a lot to Agar, a Matrix math and plotting sample will be posted up shortly.

          *>-<*
          *> Author: Brian Tiffin
          *> Dedicated to the public domain
          *>
          *> Date started: October 2017
          *> Modified: 2017-10-07/09:49-0400 btiffin
          *>+<*
          *>
          *> callagar.cob
          *> Tectonics:
          *>   cobc -xj callagar.cob $(agar-config --libs)
          *>
           >>SOURCE FORMAT IS FREE
           identification division.
           program-id. sample.
    
           environment division.
           configuration section.
           repository.
               function all intrinsic.
    
           data division.
           working-storage section.
           01 rc usage binary-long.
           01 win usage pointer.
           01 extraneous-pointer usage pointer.
    
           procedure division.
           sample-main.
           call "AG_InitCore" using null by value 0 returning rc
               on exception display "error: no libagar" upon syserr
           end-call
           if rc = -1 then
               display "error: AG_InitCore failure" upon syserr
               goback
           end-if
           call "AG_InitGraphics" using by value 0 returning rc
           if rc = -1 then
               display "error: AG_InitGraphics failure" upon syserr
               goback
           end-if
    
           call "AG_WindowNew" using by value 0 returning win
           call "AG_WindowSetGeometryAligned" using by value win 2 200 100
               returning omitted
           call "AG_LabelNew" using
               by value win 0
               by reference "Hello, world"
           returning extraneous-pointer
           call "AG_WindowShow" using by value win returning omitted
           call "AG_EventLoop" returning rc
    
           display "Agar rc = " rc
           goback.
           end program sample.
    
          *> #include <agar/core.h>
          *> #include <agar/gui.h>
          *> 
          *> int
          *> main(int argc, char *argv)
          *> {
          *>         AG_Window *win;
          *>         
          *>         if (AG_InitCore(NULL, 0) == -1 ||
          *>             AG_InitGraphics(0) == -1) {
          *>        fprintf(stderr, "Init failed: %s\n", AG_GetError());
          *>        return (1);
          *>     }
          *>         win = AG_WindowNew(0);
          *>         AG_LabelNew(win, 0, "Hello, world!");
          *>         AG_WindowShow(win);
          *>         AG_EventLoop();
          *>         return (0);
          *> }
          *> $ cc -o hello `agar-config --cflags` hello.c `agar-config --libs`
    

    callagar.cob

    prompt$ cobc -xj callagar.cob $(agar-config --libs)
    

    verification pass (doesn't have an event connected to close up shop in this intro sample, so that's kinda borked, ^C to end after using a sysmenu close).

    gnucobol-agar-1.png
    Verfication window from COBOL

    agartest-main-1.png
    Agar test program (which properly closes, event attached it seems - more reading to do). Over 30 test samples in the list.

    agartest-widgets-1.png
    Picked the widgets test.

    agartest-plotting-1.png
    Then the plotting test (had to, because charts and graphs, charts and graphs)

    Have gooey,
    Brian

     

    Last edit: Brian Tiffin 2017-10-07
    • Patrick McCavery

      This is interesting, thanks Brian :)

      I will give it a test run and then I will post to the Ada list too, just
      in case it could help someone there.

      -Pat

       
  • Paulo Reis

    Paulo Reis - 2017-10-07

    Seems interesting!!!

     
  • Brian Tiffin

    Brian Tiffin - 2017-10-08

    Oh, one thing I needed to do here to avoid a warning that borked Agar ./configure.

    Load up configure and edit -D_BSD_SOURCE to be -D_DEFAULT_SOURCE.

    Another tweak was ensuring AG_Config could find test files. I plopped everything in a default ~/.agartest. So create ~/.agartest, and from tests/ just cp *.bmp *.jpg *.png ~/.agartest and cp loss.txt ~/.agartest. There may be other files to copy but I haven't encountered those yet. In test/ the ./agartest program runs all kinds of nifty tests (and a benchmark for the AG_Math utilities).

    And here is a better Hello. Baby step two. To be useful this toolkit will need a hefty copylib (or two, or nine).

          *>-<*
          *> Author: Brian Tiffin
          *> Dedicated to the public domain
          *>
          *> Date started: October 2017
          *> Modified: 2017-10-07/23:38-0400 btiffin
          *>+<*
          *>
          *> callagar.cob
          *> Tectonics:
          *>   cobc -xj callagar.cob $(agar-config --libs)
          *>
           >>SOURCE FORMAT IS FREE
           identification division.
           program-id. sample.
    
           environment division.
           configuration section.
           repository.
               function all intrinsic.
    
           data division.
           working-storage section.
           01 rc usage binary-long.
           01 win usage pointer.
           01 extraneous-pointer usage pointer.
           01 pid usage binary-long.
           01 argv usage pointer.
           01 win-down usage program-pointer.
    
           procedure division.
           sample-main.
           call "AG_InitCore" using null by value 1 returning rc
               on exception display "error: no libagar" upon syserr
           end-call
           if rc = -1 then
               display "error: AG_InitCore failure" upon syserr
               goback
           end-if
           call "AG_InitGraphics" using by reference null returning rc
           if rc = -1 then
               display "error: AG_InitGraphics failure" upon syserr
               goback
           end-if
    
          *> Execute a command (argv taken from command line (cheating))
           call "CBL_GC_HOSTED" using argv "argv"
           call "AG_Execute" using "/usr/bin/ls" by value argv returning pid
           display "Pid: " pid
    
          *> Create a window
           call "AG_WindowNew" using by value 0 returning win
    
          *> Attach a run down
           set win-down to entry "windown"
           if win-down equal null then
               display "no window rundown" upon syserr
           else
               call "AG_SetEvent" using
                   by value win by reference  "window-detached"
                   by value win-down by reference null
           end-if
    
          *> Set the size, aligned to top center (2)
           call "AG_WindowSetGeometryAligned" using by value win 2 200 100
               returning omitted
    
          *> Simple label
           call "AG_LabelNew" using
               by value win 0
               by reference "Hello, world"
               returning extraneous-pointer
    
          *> display the window
           call "AG_WindowShow" using by value win returning omitted
    
          *> run the event loop (run down with sysmenu close)
           call "AG_EventLoop" returning rc
           display "Agar rc = " rc
    
          *> clean up
           call "AG_DestroyGraphics" returning omitted
           call "AG_Destroy" returning omitted
           goback.
           end program sample.
    
          *> **************************************************************
           identification division.
           program-id. windown.
    
          *> This is a callback from C, and needs an extern call-convention
           environment division.
           configuration section.
           special-names.
               call-convention 0 is extern.
    
          *> passed an event
           data division.
           working-storage section.
           01 agar-event based.
              05 event-name pic x(32).
              05 event-flags usage binary-long unsigned.
              *> more stuff...
              05 filler pic x(8192).
              *> 05 event-function pic x(16). *> or 8?, conditional on long double
              *> 05 event-argc usage binary-long.
              *> 05 event-argc0 usage binary-long.
              *> 05 event-args occurs 16 times.
              *>      10 *> lots of AG_Variable stuff
              *> 05 event-events *> and a queue, just to make things harder 
    
          *> /* Event handler / virtual function */
          *> typedef struct ag_event {
          *>        char name[AG_EVENT_NAME_MAX];           /* String identifier */
          *>        Uint flags;
          *> #define        AG_EVENT_ASYNC     0x01                 /* Service in separate thread */
          *> #define AG_EVENT_PROPAGATE 0x02                        /* Forward to child objs */
          *>        union ag_function fn;                   /* Callback function */
          *>        int argc, argc0;                        /* Argument count & offset */
          *>        AG_Variable argv[AG_EVENT_ARGS_MAX];    /* Argument values */
          *>        AG_TAILQ_ENTRY(ag_event) events;        /* Entry in Object */
          *> } AG_Event, AG_Function;
    
           linkage section.
           01 event usage pointer.
    
           procedure division extern using by value event returning omitted.
           display "windown: " with no advancing
    
           if event not equal null then
               set address of agar-event to event
               display event-name
           else
               display space
           end-if
    
          *> window detached, end the event loop
           call "AG_Terminate" using by value 0 returning omitted
           goback.
           end program windown.
    
          *> test code from http://www.libagar.org/docs/inst/linux.html
    
          *> #include <agar/core.h>
          *> #include <agar/gui.h>
          *>
          *> int
          *> main(int argc, char *argv)
          *> {
          *>         AG_Window *win;
          *>
          *>         if (AG_InitCore(NULL, 0) == -1 ||
          *>             AG_InitGraphics(0) == -1) {
          *>                 fprintf(stderr, "Init failed: %s\n", AG_GetError());
          *>                 return (1);
          *>         }
          *>         win = AG_WindowNew(0);
          *>         AG_LabelNew(win, 0, "Hello, world!");
          *>         AG_WindowShow(win);
          *>         AG_EventLoop();
          *>         return (0);
          *> }
          *> $ cc -o hello `agar-config --cflags` hello.c `agar-config --libs`
          *>  AG_SetEvent(win, "window-detached", ConsoleWindowDetached, NULL);
    

    callagar.cob

    $ cobc -x -j='-gocart' -debug callagar.cob $(agar-config --libs)
    Pid: +0000008546
    total 68
    -rw-rw-r--.  1  5444 Oct  7 23:49 callagar.cob
    -rw-rw-r--.  1   506 Oct  7 23:49 agar-hello.c
    -rwxrwxr-x.  1  8944 Oct  7 23:49 agar-hello
    drwxr-xr-x. 38 12288 Oct  7 23:49 ..
    drwxrwxr-x.  2  4096 Oct  8 00:15 .
    -rwxrwxr-x.  1 24280 Oct  8 00:15 callagar
    windown: window-detached
    Agar rc = +0000000000
    

    Sample. Properly handles the sysmenu close now with a windown event handler.

    gnucobol-agar-1.png
    Verfication window from COBOL

    Exercises the AG_Execute function just for fun, which takes a pathname and an argv array; I just cheated and take argv from the main command line, (or in this case the -j= job parameters). Command is /usr/bin/ls and the options end up being -gocart (no group, no owner, ctime, all, reverse (sort), time sort). Easy to remember, shows the last modified files at the bottom, a handy form of ls when working in fatter directories and when your mind is like a sieve of unremembered things, hence the gocart mnemonic.

    AG_Event data needs to be expanded on, as does AG_Variable. The structs are kinda hairy but will get a copybook. (Another cheat in this trial, I just gave the event a big bag of empty space, all to get at the first field, the event name).

    Cheers,
    Brian

     

    Last edit: Brian Tiffin 2017-10-08
  • Brian Tiffin

    Brian Tiffin - 2017-10-08

    vedge (Julian Nadeau) Canadian, so, smart and handsome, by default added a whole suite of non GUI related core materials to Agar with version 1.5

    Here is a cross-platform directory listing...

          *>-<*
          *> Author: Brian Tiffin
          *> Dedicated to the public domain
          *>
          *> Date started: October 2017
          *> Modified: 2017-10-08/04:12-0400 btiffin
          *>+<*
          *>
          *> agar-dirlist.cob
          *> Tectonics:
          *>   cobc -xj agar-dirlist.cob $(agar-core-config --libs)
          *>
           >>SOURCE FORMAT IS FREE
           identification division.
           program-id. sample.
    
           environment division.
           configuration section.
           repository.
               function all intrinsic.
    
           data division.
           working-storage section.
           01 rc                           usage binary-long.
    
           01 AG-EXEC-WAIT-INFINITE        constant as 1.
           01 pid                          usage binary-long.
           01 argv                         usage pointer.
    
           01 agar-dir-entries based.
              05 entries                   usage pointer.
              05 num-entries               usage binary-long.
    
           01 agar-dir                     usage pointer.
           01 agar-deref                   usage pointer based.
           01 agar-derefed                 usage pointer.
    
          *> Required when CONTENTS-OF not built in
           01 agar-buffer-name             pic x(128) based.
           01 agar-filename                pic x(128).
    
           procedure division.
           sample-main.
           call "AG_InitCore" using null by value 1 returning rc
               on exception display "error: no libagar" upon syserr
           end-call
           if rc = -1 then
               display "error: AG_InitCore failure" upon syserr
               goback
           end-if
    
          *> snag a directory
           call "AG_OpenDir" using "." returning agar-dir
           set address of agar-dir-entries to agar-dir
           display num-entries " entries in directory ."
    
           set address of agar-deref to entries
           perform varying tally from 1 by 1 until tally > num-entries
               set agar-derefed to agar-deref
    
               *> display contents-of(agar-derefed)
               *> or, without contents-of, do the buffer dance
               set address of agar-buffer-name to agar-derefed
               move spaces to agar-filename
               string agar-buffer-name delimited by low-value
                 into agar-filename
               display trim(agar-filename)
    
               set address of agar-deref up by 8
           end-perform
           display space
    
          *> Execute a command (argv taken from command line (cheating))
           call "CBL_GC_HOSTED" using argv "argv"
           call "AG_Execute" using "/usr/bin/ls" by value argv returning pid
    
           display "Awaiting pid: " pid
           call "AG_WaitOnProcess" using by value pid AG-EXEC-WAIT-INFINITE
    
           goback.
           end program sample.
    

    agar-dirlist.cob

    prompt$ cobc -x -j='-f1' -debug agar-dirlist.cob $(agar-core-config --libs)
    +0000000008 entries in directory .
    .
    agar-dirlist
    agar-hello.c
    agar-dirlist.cob
    callagar.cob
    callagar
    ..
    agar-hello
    
    Awaiting pid: +0000007881
    .
    agar-dirlist
    agar-hello.c
    agar-dirlist.cob
    callagar.cob
    callagar
    ..
    agar-hello
    

    Pull in (a cross-platform) directory list and display the entries. With an unsorted one per line version of ls to verify.

    And here's what it can look like once everyone gets CONTENTS-OF in GnuCOBOL 2.3

    (Took out the cruft of the verification pass).

           identification division.
           program-id. sample.
    
           environment division.
           configuration section.
           repository.
               function all intrinsic.
    
           data division.
           working-storage section.
           01 rc                           usage binary-long.
    
           01 agar-dir-entries based.
              05 entries                   usage pointer.
              05 num-entries               usage binary-long.
    
           01 agar-dir                     usage pointer.
           01 agar-deref                   usage pointer based.
    
           procedure division.
           sample-main.
           call "AG_InitCore" using null by value 1 returning rc
               on exception display "error: no libagar" upon syserr
           end-call
           if rc = -1 then
               display "error: AG_InitCore failure" upon syserr
               goback
           end-if
    
          *> snag a directory
           call "AG_OpenDir" using "." returning agar-dir
           set address of agar-dir-entries to agar-dir
           display num-entries " entries in directory ."
    
           set address of agar-deref to entries
           perform until agar-deref equal null
               display contents-of(agar-deref)
               set address of agar-deref up by length(agar-deref)
           end-perform
    
           goback.
           end program sample.
    

    agar-just-dirlist.cob (instead of sliding by 8, this slides by a more appropriate length of a pointer field. Any pointer field will do for the set up by calculation, (seeing as this is aiming for cross-platform)). And by cross-platform, vedge means; X11, Windows, Mac OS/X, SDL and or OpenGL. SDL gives you audio features.

    It also just looks for an end of list null while scanning through the char ** array of pointers to names instead of using tally.

    prompt$ cobc -xj agar-just-dirlist.cob $(agar-core-config --libs)
    +0000000010 entries in directory .
    .
    agar-just-dirlist
    agar-dirlist
    agar-hello.c
    agar-dirlist.cob
    callagar.cob
    callagar
    ..
    agar-hello
    agar-just-dirlist.cob
    

    Note the agar-core-config, it'll only pull in Agar Core library needs, sans GUI.

    Lots more to explore...

    Have good, make core, hard core,
    Brian

     
    • Patrick McCavery

      On 10/08/2017 04:38 AM, Brian Tiffin wrote:

      vedge (Julian Nadeau) Canadian, so, smart and handsome, by default
      Yes of course, Canadian men are known to be handsome, world wide. These
      are the men that put us on the map and started the trend:

      https://www.youtube.com/watch?v=w1RN3cYnY9k

      -Pat

       
      • Brian Tiffin

        Brian Tiffin - 2017-10-09

        :-) Handsome, and oh so smart. Coo roo coo coo, coo coo coo coo

        Aside: I don't really miss drinking, but I do miss stubbies. Urban myth I heard back in the day was that stubbies were less prone to being used as weapons during bar fights. The new standard long neck bottles seem too easy to grab on to as you drunkenly bash a competitor over the head for the broken glass effect.

        More aside: In grade 13 there were enough of us of age that we snuck a Bob and Doug beer tree into the seniour lounge, Principle had to ask us to remove it, but being named O'Keefe and seeing as the tree had many a O'Keefe cap and bottle decoration, the order was delayed for a few days so everyone could admire the art.

        Cheers,
        Brian

         
        • Patrick McCavery

          I had my last drink in 2002. Still these these role models so many
          qualities :)

          My Dad is from Ireland and there are even better role models there:

          https://www.youtube.com/watch?v=rECB4u3VOAs

          P.S I am old enough to remember when Ontario had grade 13 :)

           
  • Brian Tiffin

    Brian Tiffin - 2017-10-08

    I'm really starting to think that Agar might be a very appropriate library suite to build into GnuCOBOL for optional graphical SCREEN SECTION. Plus all the other goodies that comes with the kit.

    I'd appreciate someone(s) on Windows and Mac giving it a trial, and reporting back.

    License is BSD, so friendly, (with the caveat that if you build Agar with AG_Db features you'll be linking to BDB) and you'll have to promise to release sources or pony up with Oracle if you normally build with VBISAM. Releasing source is way better anyway, so... :-)

    Cheers,
    Brian

     
  • Brian Tiffin

    Brian Tiffin - 2017-10-09

    How would everyone prefer the tectonics of User Defined Function repository are handled and/or documented?

    Link editors can be a pain. cobc can be a breeze or bit of a hassle when putting UDF DSO files to use.

    For instance, the upcoming cobweb-agar.cob file is meant to be used as a Dynamic Shared Objects file, so it really should be called libcobweb-agar.cob and produce libcobweb-agar.so, which includes instructions on placing the lib file somewhere in the link search path. (/usr/local/lib for instance). That usually requires root permissions.

    Or, a more complex tectonics can be described. For GNU/Linux that would be something like

    prompt$ cobc -m cobweb-agar.cob $(agar-config --libs)
    

    building the DSO. That part is easy to describe.

    The next part, not so much.

    prompt$ LD_RUN_PATH=. cobc -xj cobweb-agar-demo.cob -L. -l:cobweb-agar.so
    

    Linking to a name without a lib prefix in a personal working direcory.

    Or, easier, but harder on compile time (which for cobc is pretty fast)

    prompt$ cobc -xj cobweb-agar-demo.cob cobweb-agar.cob
    

    Just build the library into the executable using the source form

    Or, more "standard" POSIX

    prompt$ cobc -m libcobweb-agar.cob $(agar-config --libs)
    prompt$ sudo cp libcobweb-agar.so /usr/local/lib/
    prompt$ sudo ldconfig
    prompt$ cobc -xj cobweb-agar-demo -lcobweb-agar
    

    Note the lib prefix isn't used for the little minus ell option, it's implied in POSIX link rules, but is required in the name of the DSO moved into /usr/local/lib (or where ever you put it).

    Just curious on what people think about the issue.

    • Follow standard trends and assumptions? (lib prefix and ldconfig, ala ./configure)
    • Make it easy (using the power of cobc and source form builds).
    • Make it "tricky" and allow personal working dirs and no root powers to explore.
    • Or, rely on GnuCOBOL environment variables with COB_PRE_LOAD and COB_LIBRARY_PATH?
    prompt$ cobc -m cobweb-agar.cob $(agar-config --libs)
    prompt$ COB_PRE_LOAD=cobweb-agar cobc -xj cobweb-agar-demo.cob
    generic: Attach to driver (glx2)
    AG_WindowNew: 0x000000a6225554b0
    AG_Label #0: Attach to window (generic)
    

    A trial, (current version of libagar built with ./configure --without-db4 --enable-debug so it logs some messages to stderr (and has no BDB linkage).

    gnucobol-agar-1.png

    Here is the procedure division for that demo

           procedure division.
           move AG-WINDOW-LOWER-RIGHT to pos
           move agar-window(pos, wid, hgt) to agar-record
    
           goback.
    

    cobweb-agar will be fairly concise COBOL.

    And there is always the nifty power of building a program-id into UDF repositories that can be used by cobcrun

    prompt$ cobc -m cobweb-agar.cob $(agar-config --libs)
    prompt$ cobcrun cobweb-agar test
    generic: Attach to driver (glx2)
    AG_WindowNew: 0x00000000023904a0
    AG_Label #0: Attach to window (generic)
    agar-win: 0x00000000023904a0
    agar-status: 000000256
    

    (Same hello GUI - agar-status is just an internal low-value high-value init completed value in the upcoming cobweb-agar UDF repo (or maybe libcobweb-agar depending on how many people answer this query post)). test is just a command line option read in by the main program-id inside the .so (or .dll what have you for DSO libraries on your platform).

    But that cobcrun sequence is more for the author of the DSO and not so much for consumers of the features in a DSO, aside from being an easy way to verify minimal working state and to perhaps get at built in documentation and demos that ship with libraries.

    Just asking. I use all of the above methods depending on the wind and phase of moon, but I'd like opinions on what "the one true way" is preferred.

    Cheers,
    Brian

     

    Last edit: Brian Tiffin 2017-11-07
    • Simon Sobisch

      Simon Sobisch - 2017-10-09

      Despite some first tests I wouldn't recompile the library each time from source but compile it once to an object file and add this on the command line.

      Personal oppinion:

      During test phase: rely on GnuCOBOL environment variables with COB_PRE_LOAD and COB_LIBRARY_PATH (you can very easy change these at any time).
      After test phase: mostly unchanged.

      For a production version of an external library one may use the standard installation path and add -lname + static calls which has the benefit of verifying during compilation (actual linking) that there are no typos and no functions used that aren't included in the available production library + some minimal speedup on run time.

       
      • Brian Tiffin

        Brian Tiffin - 2017-10-09

        Thanks, Simon. That does seem like the right way, using COB_PRE_LOAD, but I must admit to being a fan of LD_RUN_PATH builds.

        Beyond that, should work out some small skeletons of GnuCOBOL related autotools scripts so we can train ourselves to ship these contributions following the ./configure; make paradigm. Perhaps with an eye to having a defacto default gnucobol desktop directory (say ~/.gnucobol) and then set a default install prefix of ~/.gnucobol/ ?? For those times when sudo doesn't feel appropriate.

        Autoconf is oh so friendly to work with. <sarc>

        Cheers,
        Brian

         
  • Brian Tiffin

    Brian Tiffin - 2017-10-09

    Plotting; there are two main kinds in Agar, FixedPlotter and M_Plotter. This is FixedPlotter. M_Plotter is part of the Agar Matrix subsystem.

    prompt$ make test
    cobcrun cobweb-agar test
    generic: Attach to driver (glx2)
    AG_WindowNew: 0x00000000008685c0
    AG_Label #0: Attach to window (generic)
    AG_FixedPlotter #0: Attach to window (generic)
    0x000000000089b0b0
    :plot-1:
    0x00000000008685c0
    

    Building up the DSO

    cobweb-agar-fixedplotter-1.png

           procedure division.
           accept cli from command-line
           if helping then display "help" end-if
           if testing then
               move agar-window(AG-WINDOW-CENTER,
                                default-width,
                                default-height)
                 to agar-win-record
               move agar-fixedplotter(agar-win,
                                      AG-PLOTTER-LINES,
                                      plotter-flags)
                 to agar-plotter-record
               move agar-fixedplottercurve(agar-plotter-widget,
                                           z"plot-1",
                                           agar-red-value,
                                           agar-green-value,
                                           agar-blue-value,
                                           agar-plotter-limit)
                 to agar-curve-record
    
               perform varying looper from 0 by 0.1
                       until looper > 9.3
                   compute agar-16bits = sin(looper) * 50
                   move agar-fixedplotterdatum(agar-curve-widget,
                                               agar-16bits) to extraneous
               end-perform
    
          *> display the window
               display agar-win
               call "AG_WindowShow" using
                   by value agar-win
                   returning omitted
    
          *> run the event loop until (run down with sysmenu close)
               call "AG_EventLoop" returning rc
    
          *> clean up
               call "AG_DestroyGraphics" returning omitted
               call "AG_Destroy" returning omitted
    
               display "agar-win: " agar-win
               display "agar-status: " ord(agar-status)
           end-if
           if versioning then
               display "cobweb-agar version 0.1 " when-compiled
           end-if
           goback.
           end program cobweb-agar.
    

    cobweb-agar.cob, starting in on a more full featured UDF DSO.

    A neat thing about FixedPlotter, is they are live scrolling widgets that you can drag around. Baby step, this cut uses the default y-range of 100. FixedPlotterDatum is 16-bit signed integer y values, accumulated x vals just by adding points (which can be drawn as lines, shown here).

    Lots more to try. The last few calls listed here will be control functions shorty. And the Label will get pulled out of agar-window as a separate feature. Although libagar is "old school" for look and feel, there is a custom style sheet processor too, might try that next. Along with the single and multiline text widgets and some buttons.

    Cheers,
    Brian

     

    Last edit: Brian Tiffin 2017-10-09
  • Brian Tiffin

    Brian Tiffin - 2017-10-10

    Here's a semi usable alpha cut of cobweb-agar.cob, if not only barely minimal.

          *>-<*
          *> Copyright 2017 Brian Tiffin
          *> Licensed for use under the GNU GPL 3+
          *> https://www.gnu.org/licenses/gpl-3.0.en.html
          *> Date:     October 2017
          *> Modified: 2017-10-09/22:16-0400 btiffin
          *>+<*
          *>
          *> cobweb-agar.cob:  libagar user defined functions
          *> Tectonics:
          *>   cobc -m cobweb-agar.cob $(agar-config --libs)
          *>
           >>SOURCE FORMAT IS FIXED
    
           identification division.
           program-id. cobweb-agar.
    
           environment division.
           configuration section.
           repository.
               function agar-window
               function agar-windowshow
               function agar-eventloop
               function agar-box
               function agar-label
               function agar-button
               function agar-fixedplotter
               function agar-fixedplottercurve
               function agar-fixedplotterdatum
               function all intrinsic.
    
           data division.
           REPLACE ==:AGAR-SHARED:== BY
           ==
           01 agar-status              pic x external.
              88 agar-ready                  value high-value.
           01 rc                       usage binary-long.
           01 extraneous               usage binary-long.
           01 extraneous-pointer       usage binary-long.
           01 win-down                 usage program-pointer.
           ==
    
           ==:AGAR-WIDGET-RECORD:== BY
           ==
           01 agar-widget-record.
              05 agar-widget           usage pointer.
           ==.
    
           working-storage section.
           01 cli-command              pic x(16).
              88 helping               values "help", "--help", "-h".
              88 versioning            values "version", "--version", "-v".
              88 testing               values "test", "--test", "-t".
              88 repoing               values "repository", "--repo", "-r".
           01 cli-subtext              pic x(16).
    
           01 window-positions.
              05 AG-WINDOW-UPPER-LEFT    usage binary-long value 1.
              05 AG-WINDOW-UPPER-CENTER  usage binary-long value 2.
              05 AG-WINDOW-UPPER-RIGHT   usage binary-long value 3.
              05 AG-WINDOW-MIDDLE-LEFT   usage binary-long value 4.
              05 AG-WINDOW-CENTER        usage binary-long value 5.
              05 AG-WINDOW-MIDDLE-RIGHT  usage binary-long value 6.
              05 AG-WINDOW-LOWER-LEFT    usage binary-long value 7.
              05 AG-WINDOW-LOWER-CENTER  usage binary-long value 8.
              05 AG-WINDOW-LOWER-RIGHT   usage binary-long value 9.
    
           01 box-types.
              05 AG-BOX-HORIZ            usage binary-long value 0.
              05 AG-BOX-VERT             usage binary-long value 1.
    
           01 box-flags.
              05 AG-BOX-HOMOGENOUS       usage binary-long value 1.
              05 AG-BOX-HFILL            usage binary-long value 2.
              05 AG-BOX-VFILL            usage binary-long value 4.
              05 AG-BOX-FRAME            usage binary-long value 8.
              05 AG-BOX-EXPAND           usage binary-long value 6.
    
           01 label-flags.
              05 AG-LABEL-HFILL          usage binary-long value h'01'.
              05 AG-LABEL-VFILL          usage binary-long value h'02'.
              05 AG-LABEL-NOMINSIZE      usage binary-long value h'04'.
              05 AG-LABEL-PARTIAL        usage binary-long value h'10'.
              05 AG-LABEL-REGEN          usage binary-long value h'20'.
              05 AG-LABEL-FRAME          usage binary-long value h'80'.
              05 AG-LABEL-EXPAND         usage binary-long value h'03'.
    
           01 plotter-types.
              05 AG-PLOTTER-POINTS     usage binary-long value 0.
              05 AG-PLOTTER-LINES      usage binary-long value 1.
    
           01 plotter-flags.
              05 AG-FIXED-PLOTTER-SCROLL usage binary-long value 1.
              05 AG-FIXED-PLOTTER-XAXIS  usage binary-long value 2.
              05 AG-FIXED-PLOTTER-HFILL  usage binary-long value 4.
              05 AG-FIXED-PLOTTER-VFILL  usage binary-long value 8.
              05 AG-FIXED-PLOTTER-EXPAND usage binary-long value 12.
    
           01 agar-16bits              usage binary-short.
           01 looper                   usage float-short.
    
           01 agar-win-record.
              05 agar-win              usage pointer.
    
           01 agar-box-record.
              05 agar-box-widget       usage pointer.
    
           01 agar-label-record.
              05 agar-label-widget     usage pointer.
    
           01 agar-button-record.
              05 agar-button-widget    usage pointer.
    
           01 agar-plotter-record.
              05 agar-plotter-widget   usage pointer.
    
           01 agar-curve-record.
              05 agar-curve-widget   usage pointer.
    
           :AGAR-SHARED:
    
           procedure division.
           accept cli-command from argument-value
    
           if versioning then perform show-version end-if
           if helping then perform show-version perform show-help end-if
           if repoing then perform show-repository end-if
           if testing then perform run-tests end-if
    
           goback.
    
           show-version.
           display "cobweb-agar version 0.1 " when-compiled
           .
    
           show-help.
           accept cli-subtext from argument-value
    
           call "SYSTEM" using concatenate(
               "sed -n '/\[helpstart-" trim(cli-subtext) "\]/,"
                       "/\[helpend-" trim(cli-subtext) "\]/p' "
               module-source
               "| sed '1d' | sed '$d' | sed 's/\s*\*>\s//'")
    
          *> [helpstart-help]
          *> cobweb-agar help [topic]
          *>   display help on the given topic
          *> [helpend-help]
           .
    
           show-repository.
           display "repository."
           call "SYSTEM" using concatenate(
               "grep function-id\\. "
               module-source
               " | sed 's/function-id\. /function /'"
               " | tr '.' ' '")
           .
    
           run-tests.
           move agar-window(AG-WINDOW-CENTER, numval(200), numval(100))
             to agar-win-record
                                        *> AG-BOX-HFILL + AG-BOX-HOMOGENOUS
           move agar-box(agar-win, AG-BOX-HORIZ, numval(3))
             to agar-box-record
    
           move agar-label(agar-box-widget, numval(0), z"Hello, world")
             to agar-label-record
    
           move agar-button(agar-box-widget, numval(0), z"Goodbye",
                            "windown") to agar-button-record
    
           move agar-fixedplotter(agar-win, AG-PLOTTER-LINES, numval(15))
             to agar-plotter-record
    
           move agar-fixedplottercurve(agar-plotter-widget, z"plot-1",
                                       numval(0),             *> red
                                       numval(255),           *> green
                                       numval(0),             *> blue
                                       numval(2000))          *> limit
             to agar-curve-record
    
           perform varying looper from 0 by 0.1 until looper > 9.3
               compute agar-16bits = sin(looper) * 50
               move agar-fixedplotterdatum(agar-curve-widget, agar-16bits)
                 to extraneous
           end-perform
    
          *> display the window
           move agar-windowshow(agar-win) to extraneous
    
          *> run the event loop until run down (close with sysmenu)
           move agar-eventloop() to rc
           if rc not equal 0 then
               display "warning: eventloop non-zero " rc upon syserr
           end-if
    
          *> clean up
           call "AG_DestroyGraphics" returning omitted
           call "AG_Destroy" returning omitted
           .
    
           end program cobweb-agar.
          *> ***************************************************************
    
           identification division.
           program-id. windown.
    
          *> This is a callback from C, and needs an extern call-convention
           environment division.
           configuration section.
           special-names.
               call-convention 0 is extern.
    
          *> passed an event
           data division.
           working-storage section.
           01 agar-event based.
              05 event-name            pic x(32).
              05 event-flags           usage binary-long unsigned.
              *> more stuff...
              05 filler                pic x(8192).
              *> 05 event-function pic x(16). *> or 8?, conditional on long double
              *> 05 event-argc usage binary-long.
              *> 05 event-argc0 usage binary-long.
              *> 05 event-args occurs 16 times.
              *>      10 *> lots of AG_Variable stuff
              *> 04 event-events *> and a queue, just to make things harder
    
           linkage section.
           01 event usage pointer.
    
           procedure division extern using by value event returning omitted.
    
          *> window detached, end the event loop
           call "AG_Terminate" using by value 0 returning omitted
    
           goback.
           end program windown.
          *> ***************************************************************
    
          *> [helpstart-window]
          *> [helpstart-agar-window]
          *> agar-window(position, width, height)
          *>   create a new top level Agar window
          *>   returning an agar-win-record containing a single pointer
          *> [helpend-agar-window]
          *> [helpend-window]
           identification division.
           function-id. agar-window.
    
           data division.
           working-storage section.
           :AGAR-SHARED:
    
           linkage section.
           01 window-position          usage binary-long.
           01 window-width             usage binary-long.
           01 window-height            usage binary-long.
           01 agar-win-record.
              05 agar-win              usage pointer.          
    
           procedure division using
               window-position window-width window-height
               returning agar-win-record.
    
           if not agar-ready then
               call "AG_InitCore" using null by value 1 returning rc
                   on exception display "error: no libagar" upon syserr
                   goback
               end-call
               if rc not equal zero then
                   display "error: AG_InitCore failure" upon syserr
                   goback
               end-if
               call "AG_InitGraphics" using by reference null returning rc
               if rc not equal zero then
                   display "error: AG_InitGraphics failure" upon syserr
                   goback
               end-if
           end-if
           set agar-ready to true
    
          *> Create a window
           call "AG_WindowNew" using by value 0 returning agar-win
    
          *> Attach a run down
           set win-down to entry "windown"
           if win-down equal null then
               display "error: windown entry not found" upon syserr
           else
               call "AG_SetEvent" using
                   by value agar-win by reference  "window-detached"
                   by value win-down by reference null
           end-if
    
          *> Set the size, aligned to given position
           call "AG_WindowSetGeometryAligned" using
               by value agar-win
               by value window-position
               by value window-width
               by value window-height
               returning omitted
           end-call
    
           goback.
           end function agar-window.
          *> ***************************************************************
    
           identification division.
           function-id. agar-windowshow.
    
           data division.
           linkage section.
           01 agar-parent                  usage pointer.
           01 extraneous                   usage binary-long.
    
           procedure division using agar-parent returning extraneous.
    
          *> Display Window
           call "AG_WindowShow" using
               by value agar-parent
               returning omitted
           move 0 to extraneous
    
           goback.
           end function agar-windowshow.
          *> ***************************************************************
    
           identification division.
           function-id. agar-eventloop.
    
           data division.
           linkage section.
           01 result-code                  usage binary-long.
    
           procedure division returning result-code.
    
          *> Run the event loop
           call "AG_EventLoop" returning result-code
    
           goback.
           end function agar-eventloop.
          *> ***************************************************************
    
           identification division.
           function-id. agar-box.
    
           data division.
           working-storage section.
           :AGAR-SHARED:
    
           linkage section.
           01 agar-parent                  usage pointer.
           01 agar-type                    usage binary-long.
           01 agar-flags                   usage binary-long unsigned.
           :AGAR-WIDGET-RECORD:
    
           procedure division using
               agar-parent
               agar-type
               agar-flags
               returning agar-widget-record.
    
          *> Simple label
           call "AG_BoxNew" using
               by value agar-parent
               by value agar-type
               by value agar-flags
               returning agar-widget
    
           goback.
           end function agar-box.
          *> ***************************************************************
    
           identification division.
           function-id. agar-label.
    
           data division.
           working-storage section.
           :AGAR-SHARED:
    
           linkage section.
           01 agar-parent                  usage pointer.
           01 agar-flags                   usage binary-long unsigned.
           01 agar-text                    pic x any length.
           :AGAR-WIDGET-RECORD:
    
           procedure division using
               agar-parent
               agar-flags
               agar-text
               returning agar-widget-record.
    
          *> Simple label
           call "AG_LabelNewS" using
               by value agar-parent
               by value agar-flags
               by reference agar-text
               returning agar-widget
    
           goback.
           end function agar-label.
          *> ***************************************************************
    
           identification division.
           function-id. agar-button.
    
           data division.
           working-storage section.
           :AGAR-SHARED:
           01 event-handler usage program-pointer.
    
           linkage section.
           01 agar-parent                  usage pointer.
           01 agar-flags                   usage binary-long unsigned.
           01 agar-text                    pic x any length.
           01 eventer-name                 pic x any length.
           :AGAR-WIDGET-RECORD:
    
           procedure division using
               agar-parent
               agar-flags
               agar-text
               eventer-name
               returning agar-widget-record.
    
          *> Simple button
           call "AG_ButtonNewS" using
               by value agar-parent
               by value agar-flags
               by reference agar-text
               returning agar-widget
    
          *> Attach an click handler
    
           set event-handler to entry eventer-name
           if event-handler equal null then
               display "error: " eventer-name " not found" upon syserr
           else
               call "AG_SetEvent" using
                   by value agar-widget by reference  "button-pushed"
                   by value event-handler by reference null
           end-if
    
           goback.
           end function agar-button.
          *> ***************************************************************
    
           identification division.
           function-id. agar-fixedplotter.
    
           data division.
           working-storage section.
           :AGAR-SHARED:
    
           linkage section.
           01 agar-parent                  usage pointer.
           01 agar-fixed-plotter-type      usage binary-long.
           01 agar-fixed-plotter-flags     usage binary-char unsigned.
           :AGAR-WIDGET-RECORD:
    
           procedure division using
               agar-parent
               agar-fixed-plotter-type
               agar-fixed-plotter-flags
               returning agar-widget-record.
    
          *> Create a fixed plotter
           call "AG_FixedPlotterNew" using
               by value agar-parent
               by value agar-fixed-plotter-type
               by value agar-fixed-plotter-flags
               returning agar-widget
    
           goback.
           end function agar-fixedplotter.
          *> ***************************************************************
    
           identification division.
           function-id. agar-fixedplottercurve.
    
           data division.
           working-storage section.
           :AGAR-SHARED:
    
           linkage section.
           01 agar-parent                  usage pointer.
           01 agar-name                    pic x any length.
           01 agar-red                     usage binary-char unsigned.
           01 agar-green                   usage binary-char unsigned.
           01 agar-blue                    usage binary-char unsigned.
           01 agar-limit                   usage binary-long unsigned.
           :AGAR-WIDGET-RECORD:
    
           procedure division using
               agar-parent
               agar-name
               agar-red
               agar-green
               agar-blue
               agar-limit
               returning agar-widget-record.
    
          *> Create a fixed plotter curve
           call "AG_FixedPlotterCurve" using
               by value agar-parent
               by reference agar-name
               by value agar-red
               by value agar-green
               by value agar-blue
               by value agar-limit
               returning agar-widget
    
           goback.
           end function agar-fixedplottercurve.
          *> ***************************************************************
    
           identification division.
           function-id. agar-fixedplotterdatum.
    
           data division.
           working-storage section.
           :AGAR-SHARED:
    
           linkage section.
           01 agar-parent                  usage pointer.
           01 agar-val                     usage binary-short.
           01 unused                       usage binary-long.
    
           procedure division using
               agar-parent
               agar-val
               returning unused.
    
          *> Add a point to a plotter curve
           call "AG_FixedPlotterDatum" using
               by value agar-parent
               by value agar-val
               returning omitted
           move 0 to unused
    
           goback.
           end function agar-fixedplotterdatum.
          *> ***************************************************************
    

    cobweb-agar.cob

    prompt$ make test
    cobc -debug -m cobweb-agar.cob `agar-config --libs`
    cobcrun cobweb-agar test
    
    generic: Attach to driver (glx2)
    AG_Box #0: Attach to window (generic)
    AG_Label #0: Attach to widget (AG_Box #0 in generic)
    AG_Label #0: Attach to widget ( in NULL)
    AG_Button #0: Attach to widget (AG_Box #0 in generic)
    AG_FixedPlotter #0: Attach to window (generic)
    

    build and run a test

    cobweb-agar-test-1.png

    prompt$ cobcrun cobweb-agar help agar-window
    cobweb-agar version 0.2 2017100922163456-0400
    
    agar-window(position, width, height)
      create a new top level Agar window
      returning an agar-win-record containing a single pointer
    

    Experimenting with a new embedded help system.

    This cut displays a range of lines from the source file (MODULE-SOURCE) given
    [helpstart-thing] ... [helpend-thing] markers (behind COBOL comment lines), when cobcrun cobweb-agar help thing is given.

    In the trial I've wrapped help agar-window inside help window, so you get a reminder of what the real help is (the marker lines) when you use an alias. The short help will likely just mention what man page to look at for the actual Agar manual pages, with a little blurb on the arguments and returns. (Or this kind of embedded help will be dumped for being a useless hassle). Never fear a failed experiment, well, unless you work with explosive chemicals or whatnot.

    prompt$ cobcrun cobweb-agar help window
    cobweb-agar version 0.2 2017100922321062-0400
    
    [helpstart-agar-window]
    agar-window(position, width, height)
      create a new top level Agar window
      returning an agar-win-record containing a single pointer
    [helpend-agar-window]
    

    This help feature may not survive past rev 0.3 of the library, but it's kinda handy. Real ReStructuredText processed output is prettier. ;-)

    Does the same kind of extract to get the list of supported functions with

    prompt$ cobcrun cobweb-agar repository
    repository.
           function agar-window 
           function agar-windowshow 
           function agar-eventloop 
           function agar-box 
           function agar-label 
           function agar-button 
           function agar-fixedplotter 
           function agar-fixedplottercurve 
           function agar-fixedplotterdatum
    

    repository list taken from scanning the source code.

    Cheers,
    Brian

     
  • Brian Tiffin

    Brian Tiffin - 2017-10-10

    And things just got real. :-( ;-)

    AG_Textbox is a thing. Based on another thing, an AG_Editable.

    Yeah, C structures inside C structures with a few wrinkles with C preprocessor macros.

    API looks like, hey just bind a string to your textbox and go. But wait, macros.

    Ok, you bind to the editable. And the pointer to that is in the textbox structure just past the ag_widget. Well, what's an ag_widget? Cheated and found out it's an 832 byte area of stuff. So, skip that many bytes and squirrel in to get the editable for binding.

    Woohoo. <sarc>

    This will all smooth out once the proper copybooks are in place and the structures are coded into workable COBOL, but for the now.

           01 inner-textbox based.
              05 filler pic x(832).
              05 agar-editable usage pointer.
    ...
          *> *** Temporary workaround until complete struct definition ***
           set address of inner-textbox to agar-widget
    

    workaround

    cobweb-agar-test-2.png

    prompt$ make test
    cobc -debug -m cobweb-agar.cob `agar-config --libs`
    cobcrun cobweb-agar test
    
    ...removed Agar debug lines...
    
    work-buffer :This is the ending data               :
    

    ending text, after editing the starting text (shown in the screen capture above)

    cobweb-agar-test-3.png

    And now it gets real-er.

    Events are textbox-return (hit return in a single line text), textbox-prechg (cursoring around), and textbox-postchg (data changed).

    The events are posted, and handled like the windown rundown and button-pressed examples; been there, down that, but ... need to figure out how to get at the textbox that triggered the event, then the editable embedded in that textbox and then report that all back for easy use from COBOL while in a subprogram that is called via callback from C.

    Not quite there yet; more reading and a pause for station identification. ;-)
    Will need to fill in some of the copybooks that these initial trials have been ignoring.

    Have good, make deep,
    Brian

     
  • Robert W.Mills

    Robert W.Mills - 2017-10-10

    This help feature may not survive past rev 0.3 of the library, but it's kinda handy. Real ReStructuredText processed output is prettier. ;-)

    I thought it was a good idea and was planning to include it in CobolSQLite3 as an addition to the User Guide.

     
    • Brian Tiffin

      Brian Tiffin - 2017-10-10

      Well then, Robert, perhaps it will be improved and more thought through instead of being dumped. That first cut relies on POSIX utilities so it won't work cross platform.

      At the moment it also relies on having access to the source at runtime; might be able to setup a build time tool that extracts pertinent bits and builds the help sections right into the library. Then another step to avoid duplicating effort regarding argument signatures (which always stales rapidly and gets out of whack, which is usually worse than just not being there in the first place).

      I've been looking for a reason to put libarchive to more use. Or perhaps assembly files and .incbin and/or objcopy --add-section.

      Or, simple, and just pull lines out of source code at runtime. ;-)

      Here's an an example using .incbin and symbols included in the DSO library.

      prompt$ make
      gcc -c helpdata.s
      cobc -debug -b cobweb-agar.cob helpdata.o `agar-config --libs`
      

      Changes the make rule from -m to -b to create a build all module.

      Assembler is fairly short (and could be automated along with creation of the text files). I used CamelCase for the symbol names due to lack of hyphen, but could be underscores, as long as there isn't a conflict with any of the actual names generated by cobc for the program at hand.

      /* cobweb-agar help sections experiment */
      .section ".rodata"
      .globl agarWindowHelp
      .type agarWindowHelp, STT_OBJECT
      agarWindowHelp:
      .incbin "agar-window-help.txt"
      .byte 0
      .size agarWindowHelp, .-agarWindowHelp
      

      helpdata.s, could pull in all kinds of *-*-help.txt files.

      COBOL gets at the symbol data with a fairly simple:

            *> Experiment with embedding .incbin files and symbols in assembly
            *>  see helpdata.s and Makefile
             if cli-subtext equal "embedded" then
                 set helptext-entry to entry "agarWindowHelp"
                 if helptext-entry not equal null then
                     set helptext to helptext-entry 
                     display contents-of(helptext)
                 end-if
             end-if
      

      cobweb-agar.cob, help embedded test. (The upcoming contents-of intrinsic won't let you peek at program-pointer data, which is needed for the symbol lookup, so you need a program-pointer and pointer pointer). Without contents-of you need to do the based item / linkage section buffer dance, which isn't too bad. You could also assign a size global symbol in the object code and avoid needing the C string null byte.

      prompt$ cobcrun cobweb-agar help embedded
      cobweb-agar version 0.2 2017101006305011-0400
      
      agar-window(position, width, height): agar-win-record
        creates a new top level Agar window aligned as per position type,
        width pixels wide by height pixels high.
      
      Agar man page at "man 3 AG_Window" has more details.
      

      Sample run of embedded text inside object files.

      Oh, and I added a help list trial for the source file [helpstart- version, scans through the MODULE-SOURCE file using a grep and sed pipeline.

      prompt$ cobcrun cobweb-agar help list
      cobweb-agar version 0.2 2017101006420733-0400
      
      List of cobweb-agar help topics:
      help
      window
      agar-window
      

      help list trial.

      Have good, make good,
      Brian

       

      Last edit: Brian Tiffin 2017-10-10
      • Brian Tiffin

        Brian Tiffin - 2017-10-11

        Is this horrible? Trying to save some redundant docs

               identification division.
               function-id. agar-combo.
        
               data division.
               working-storage section.
               :AGAR-SHARED:
        
               linkage section.
              *> [helpstart-agar-combo]
              *> function agar-combo(
               01 agar-parent                  usage pointer.
               01 agar-flags                   usage binary-long unsigned.
               01 agar-text                    pic x any length.
               :AGAR-WIDGET-RECORD:
              *> )
              *>
              *> Create a new combo box. A combo is a high level Agar widget
              *> that packs a Textbox left of a Button which causes a Tlist
              *> to popup when pressed.  The Tlist disappears when an option
              *> is selected.
              *>
              *> See 'man 3 AG_Combo' for more details.
              *> [helpend-agar-combo]
        
               procedure division using
               ...
        

        in source help

        Shows up like

        prompt$ cobcrun cobweb-agar help agar-combo
        cobweb-agar [version 0.2] 2017101109384483-0400
        
        function agar-combo(
               01 agar-parent                  usage pointer.
               01 agar-flags                   usage binary-long unsigned.
               01 agar-text                    pic x any length.
               :AGAR-WIDGET-RECORD:
        )
        
        Create a new combo box. A combo is a high level Agar widget
        that packs a Textbox left of a Button which causes a Tlist
        to popup when pressed.  The Tlist disappears when an option
        is selected.
        
        See 'man 3 AG_Combo' for more details.
        

        Might be worth the effort to just add the prototype docs by hand, but this way, even though it looks dorky and is kinda wrong, with the return value inside the parens, it will always be current and the datatypes will be correct.

        cobweb-agar-test-4.png

        Could do the same thing a little further down in the procedure division using, but then there are no datatypes shown.

        Curious on what people think.

        Have good, make lazy,
        Brian

         

        Last edit: Brian Tiffin 2017-10-11
        • Simon Sobisch

          Simon Sobisch - 2017-10-11

          Looks only horrible concerning the likely REPLACEd :AGAR-..._:. otherwise fine.
          But you know how it is "beauty is specific to the person seeing something" :-)

           

          Last edit: Simon Sobisch 2017-10-11
          • Brian Tiffin

            Brian Tiffin - 2017-10-11

            Agree on the REPLACE shortcut, these records aren't long enough to warrant the laze.

            Already changed to

                   linkage section.
                  *> [helpstart-agar-combo]
                  *> function agar-combo(
                   01 agar-parent                  usage pointer.
                   01 agar-flags                   usage binary-long unsigned.
                   01 agar-label                   pic x any length.
                  *> ) to
                   01 agar-widget-record.
                      05 agar-widget               usage pointer.
                  *>
                  *> Create a new combo box. A combo is a high level Agar widget
                  *> that packs a Textbox left of a Button which causes a Tlist
                  *> to popup when pressed.  The Tlist disappears when an option
                  *> is selected.
                  *>
                  *> Add items to the combo list with function agar-tlist-add.
                  *>
                  *> See 'man 3 AG_Combo' and 'man 3 AG_Tlist' for more details.
                  *> [helpend-agar-combo]
            

            in source help

            prompt$ cobcrun cobweb-agar help agar-combo
            cobweb-agar [version 0.2] 2017101110160357-0400
            
            function agar-combo(
                   01 agar-parent                  usage pointer.
                   01 agar-flags                   usage binary-long unsigned.
                   01 agar-label                   pic x any length.
            ) to
                   01 agar-widget-record.
                      05 agar-widget               usage pointer.
            
            Create a new combo box. A combo is a high level Agar widget
            that packs a Textbox left of a Button which causes a Tlist
            to popup when pressed.  The Tlist disappears when an option
            is selected.
            
            Add items to the combo list with function agar-tlist-add.
            
            See 'man 3 AG_Combo' and 'man 3 AG_Tlist' for more details.
            

            sample run (still apt to change on way to cobweb-agar [version 0.3]).

            The run time help will eventually be embedded in the binary from an automatically generated .incbin assembly file, with a small human readable name to valid symbol name routine. If the few hundred extra K of library size seems burdensome (there will be documentation, but there won't be that much documentation) GnuCOBOL already has a zlib compression module, and source extracted text should compress very well for use from inside the DSO.

            Once that works out, then it'll likely be split into two forms of help display based on subcommand. Plain console text and a libagar based graphical help page viewer from a scrollable, with the builtin Ctrl+ Ctrl- zoom features and whatnot (AG_Console is the next up widget). Maybe. This whole experiment could still end up as fail.

            Cheers,
            Brian

             
  • Brian Tiffin

    Brian Tiffin - 2017-10-11

    Just a note for anyone that may be following along.

    Until further notice, all the code samples posted in this thread will be 64-bit only. I'm cheating on a few of the hairier libagar structure definitions and the utilities I'm using (C programs with judicious use of sizeof and offsetof) are reporting filler numbers appropriate for 64-bit machines. I'll make note of the few spots where this is in the code, but until I test some things in a 32-bit VM, I'm just going to assume a 64-bit target.

    This will be corrected before cobweb-agar makes it to contributions, with complete structure definitions, and the odd conditional compile sequence, but for now...

    When/if Agar is used for internal codegen for graphical SCREEN SECTION none of this warning will apply, as ./configure; make will just do the right thing on the platform at hand. It's just the pure COBOL used while building up a user defined FUNCTION repository that would ever have problems.

    There are ways to remove that risk, but more work has to be done first. For now, I'd rather add shiny new widgets to cobweb-agar than fix the plumbing that eventually has to be made cross-platform.

    Whinge, whine, excuses excuses. :-)

    Cheers,
    Brian

     

    Last edit: Brian Tiffin 2017-10-11
    • Simon Sobisch

      Simon Sobisch - 2017-10-11

      The easiest "fix" for this is to check P64 via CDF. As long as you don't fix it (possibly by using FILLER USAGE POINTER) you can just add a CDF DISPLAY message there and create a hard error - this ensures that nobody can compile this with 32bit and gets a message why.

       
      • Brian Tiffin

        Brian Tiffin - 2017-10-11

        Will.

        I was just whinging and whining. Most some of the structs are in now, sync does its job. cobweb-agar will be 32-bit and 64-bit sane after a few more reads and copy-n-pastes from the C headers.

        Getting lot's done, going through the widget list alphabetically now. Already up to the "C"s. That's like third from the list of nearly forty ... just flying. :-)

        But smart idea on the abort until things are ready. Added, but I did it at runtime along with a mesage during compile.

               >>IF P64 NOT SET
               >>DISPLAY "64bit only code at the moment"
               STOP "Sorry, this codebase currently only supports 64bit, please
              -     "stay tuned.  Press Enter to NOT continue."
               STOP RUN
               >>END-IF
        

        Code will should compile, but it won't run and risk giving libagar or GnuCOBOL a bad rep.

        On that, can we let Edward add the ASSERT verb like he wanted to when he was first coming to grips with the code base? It'd be a handy extension. Plus, I think it'll expose a programmatic way to get at displaying the current source line number for other runtime error and warning messaging.

        Or if adding things to the core word set is still not to liking, maybe a >>IMP ASSERT expression?

        Cheers,
        Brian

         

        Last edit: Brian Tiffin 2017-10-11
  • Brian Tiffin

    Brian Tiffin - 2017-10-11

    libagar is definitely well designed. Events have a big bag of associated data, including a vararg of "variable" data with lots of supported types. "variable" is in quotes, as these are named variables, not just variable data. Common event handlers can query what object raised the event along with named variables which can hold a variety of data types. cobweb-agar will limit that to one integer or one pointer. Buttons can have names and numbers, any widget can have associated events with names and pointers to whatever data you need to pass around. So far. The cobweb-agar API is definitely at risk of changing considerably.

    Getting to be over 1,000 lines of code now, so no more full listings here, but current is attached.

    prompt$ make helplist
    cobc -debug -b cobweb-agar.cob helpdata.o `agar-config --libs`
    cobcrun cobweb-agar help list
    cobweb-agar [version 0.2] 2017101100175315-0400
    
    List of cobweb-agar help topics:
    agar-box
    agar-button
    agar-label
    agar-setevent
    agar-setevent-with-field
    agar-textbox
    agar-window
    embedded
    help
    license
    repository
    setevent
    test
    textbox
    version
    window
    
    prompt$ cobcrun cobweb-agar repository
    repository.
           function agar-window 
           function agar-windowshow 
           function agar-setevent 
           function agar-setevent-with-field 
           function agar-eventloop 
           function agar-box 
           function agar-label 
           function agar-button 
           function agar-textbox 
           function agar-fixedplotter 
           function agar-fixedplottercurve 
           function agar-fixedplotterdatum
    

    some samples

           run-tests.
           move agar-window(AG-WINDOW-CENTER, numval(200), numval(100))
             to agar-win-record
                                        *> AG-BOX-HFILL + AG-BOX-HOMOGENOUS
           move agar-box(agar-win, AG-BOX-HORIZ, numval(3))
             to agar-box-record
    
           move agar-label(agar-box-widget, numval(0), z"Hello, world")
             to agar-label-record
    
           move agar-button(agar-box-widget, numval(0), z"Goodbye",
                            "windown", z"goodbye-button", numval(1))
             to agar-button-record
    
           move agar-textbox(agar-win, numval(0), z"textbox:", work-buffer,
                            "textboxer", "agar-text-test")
             to agar-textbox-record
    
           move agar-fixedplotter(agar-win, AG-PLOTTER-LINES, numval(15))
             to agar-plotter-record
    
           move agar-fixedplottercurve(agar-plotter-widget, z"plot-1",
                                       numval(0),             *> red
                                       numval(255),           *> green
                                       numval(0),             *> blue
                                       numval(2000))          *> limit
             to agar-curve-record
    
           perform varying looper from 0 by 0.1 until looper > 9.3
               compute agar-16bits = sin(looper) * 50
               move agar-fixedplotterdatum(agar-curve-widget, agar-16bits)
                 to extraneous
           end-perform
    
          *> display the window
           move agar-windowshow(agar-win) to extraneous
    
          *> run the event loop until run down (close with sysmenu)
           move agar-eventloop() to rc
           if rc not equal 0 then
               display "warning: eventloop non-zero " rc upon syserr
           end-if
    
          *> clean up
           call "AG_DestroyGraphics" returning omitted
           call "AG_Destroy" returning omitted
           .
          *> [helpstart-test]
          *> cobweb-agar test
          *> Run internal tests, as a demo. Also acts as an example for
          *> using cobweb-agar features.
          *>
          *> See the run-tests paragraph inside the cobweb-agar program.
          *> [helpend-test]
    

    The cobweb-agar test paragraph.

    Cheers,
    Brian

     

    Last edit: Brian Tiffin 2017-10-11
  • Brian Tiffin

    Brian Tiffin - 2017-10-11

    Getting there.

    The code is still covered in construction dust, but

    prompt$ cobcrun cobweb-agar help list
    cobweb-agar [version 0.2] 2017101119274710-0400
    
    List of cobweb-agar help topics:
    agar-box
    agar-button
    agar-combo
    agar-console
    agar-consolemsg
    agar-dirdlg
    agar-filedlg
    agar-label
    agar-setevent
    agar-setevent-with-field
    agar-textbox
    agar-tlist-add
    agar-window
    embedded
    help
    license
    repository
    setevent
    test
    textbox
    version
    window
    windowshow
    zoom
    
    prompt$ make test
    cobcrun cobweb-agar test
    
    field: return-agar-text-test changed 9 times.
    textbox buffer now :This is the data   012345     :
    shared-data :This is the data   012345               :
    

    As of Oct 11.

    cobweb-agar-test-5.png

    Cheers,
    Brian

     
1 2 3 .. 7 > >> (Page 1 of 7)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.