L1VM - launcher

I did write a launcher for my GUI programs:

L1VM launcher

It shows the current time at the bottom. If you double click at the buttons you can launch the programs. I couldn’t use the normal GUI event loop, because it is a blocking call. So the time could not be updated. I do the mouse coordinations check in the program.

Here is the full launcher code:

// launcher.l1com
//
// SDL demos launch tool
//
#include <intr.l1h>
#include <misc-macros.l1h>
(main func)
    (set const-int64 1 zero 0)
    (set const-int64 1 one 1)
    (set const-int64 1 two 2)
    (set const-int64 1 three 3)
    (set const-int64 1 four 4)
    (set const-int64 1 five 5)
    (set const-int64 1 quit 4)
    (set const-int64 1 delay 10)
    (set const-int64 1 delay_click 500)
    (set const-int64 1 width 220)
    (set const-int64 1 height 260)
    (set const-int64 1 width_b 219)
    (set const-int64 1 height_b 259)
    (set const-int64 1 bit 32)
    (set const-int64 1 gadgets 5)
    (set const-int64 1 fontsize 20)
    (set const-byte 1 back_r 143)
    (set const-byte 1 back_g 147)
    (set const-byte 1 back_b 151)
    (set const-byte 1 alpha 255)
    (set const-byte 1 black 0)
    (set const-int64 1 lines_x 5)
    (set const-int64 1 lines_y 5)
    (set const-int64 1 fractalix_x 5)
    (set const-int64 1 fractalix_y 40)
    (set const-int64 1 demo_x 5)
    (set const-int64 1 demo_y 75)
    (set const-int64 1 pov_edit_x 5)
    (set const-int64 1 pov_edit_y 110)
    (set const-int64 1 quit_x 5)
    (set const-int64 1 quit_y 150)
    (set int64 1 lines_x2 0)
    (set int64 1 lines_y2 0)
    (set int64 1 fractalix_x2 0)
    (set int64 1 fractalix_y2 0)
    (set int64 1 demo_x2 0)
    (set int64 1 demo_y2 0)
    (set int64 1 pov_edit_x2 0)
    (set int64 1 pov_edit_y2 0)
    (set int64 1 quit_x2 0)
    (set int64 1 quit_y2 0)
    // mouse state
    (set int64 1 x 0)
    (set int64 1 y 0)
    (set int64 1 mouse_button_left 0)
    (set int64 1 mouse_button_middle 0)
    (set int64 1 mouse_button_right 0)
    (set string s fontnamestr "fonts/free/FreeMono.ttf")
    (set string s linesstr     "lines         ")
    (set string s fractalixstr "fractalix-3.2 ")
    (set string s sdl_demostr  "demo          ")
    (set string s pov_editstr  "POV-edit      ")
    (set string s quitstr      "quit          ")
    (set string s lines_runstr "l1vm lines &")
    (set string s fractalix_runstr "l1vm fractalix-3.2.1 &")
    (set string s demo_runstr "l1vm sdl-lib-2 &")
    (set string s pov_edit_runstr "l1vm pov-edit/pov-edit-4 &")
    (set string s window_titlestr "L1VM -launcher")
    (set const-int64 1 status 1)
    (set int64 1 gadget_sel 0)
    (set string 256 gadget_retstr "")
    (set int64 1 ret 0)
    (set int64 1 value 0)
    (set int64 1 f 0)
    (reset-reg)
    // open screen
    (zero width height bit zero :sdl_open_screen !)
    (ret stpop)
    (one :string_init !)
    (two :process_init !)
    (three :time_init !)
    (window_titlestr :sdl_set_window_title !)

    // load font
    (fontnamestr fontsize :sdl_font_ttf !)
    (gadgets :init_gui !)
    (zero zero width_b height_b back_r back_g back_b alpha :sdl_rectangle_fill !)
    (zero lines_x lines_y linesstr status :set_gadget_button !)
    (one fractalix_x fractalix_y fractalixstr status :set_gadget_button !)
    (two demo_x demo_y sdl_demostr status :set_gadget_button !)
    (three pov_edit_x pov_edit_y pov_editstr status :set_gadget_button !)
    (four quit_x quit_y quitstr status :set_gadget_button !)
    // get x2/y2
    (zero :get_gadget_x2y2 !)
    (lines_x2 lines_y2 stpop)
    (one :get_gadget_x2y2 !)
    (fractalix_x2 fractalix_y2 stpop)
    (two :get_gadget_x2y2 !)
    (demo_x2 demo_y2 stpop)
    (three :get_gadget_x2y2 !)
    (pov_edit_x2 pov_edit_y2 stpop)
    (four :get_gadget_x2y2 !)
    (quit_x2 quit_y2 stpop)
    (:loop)
    (:time_show !)
    (:sdl_get_mouse_state !)
    (x stpopi)
    (y stpopi)
    (mouse_button_left stpopi)
    (mouse_button_middle stpopi)
    (mouse_button_right stpopi)
    (:sdl_update !)
    (((mouse_button_left zero ==) f =) f if)
        // detime (delay)
        (:event_wait)
        detime (delay_click)
        (:sdl_get_mouse_state !)
        (x stpopi)
        (y stpopi)
        (mouse_button_left stpopi)
        (mouse_button_middle stpopi)
        (mouse_button_right stpopi)
        (((mouse_button_left zero ==) f =) f if)
            (:event_wait jmp)
        (endif)

        (((((x quit_x >=)(x quit_x2 <=) &&)((y quit_y >=)(y quit_y2 <=) &&) &&) f =) f if)
            // quit
            (:sdl_quit !)
            exit (zero)
        (endif)
        (((((x lines_x >=)(x lines_x2 <=) &&)((y lines_y >=)(y lines_y2 <=) &&) &&) f =) f if)
             (lines_runstr :run_shell !)
        (endif)
        (((((x fractalix_x >=)(x fractalix_x2 <=) &&)((y fractalix_y >=)(y fractalix_y2 <=) &&) &&) f =) f if)
             (fractalix_runstr :run_shell !)
        (endif)
        (((((x demo_x >=)(x demo_x2 <=) &&)((y demo_y >=)(y demo_y2 <=) &&) &&) f =) f if)
             (demo_runstr :run_shell !)
        (endif)
        (((((x pov_edit_x >=)(x pov_edit_x2 <=) &&)((y pov_edit_y >=)(y pov_edit_y2 <=) &&) &&) f =) f if)
             (pov_edit_runstr :run_shell !)
        (endif)
    (endif)
    detime (delay)
    (:loop jmp)
(funcend)
(time_show func)
    #var ~ time_show
    (set int64 1 time_x~ 60)
    (set int64 1 time_y~ 215)
    (set int64 1 time_x2~ 219)
    (set int64 1 time_y2~ 255)
    (set string 9 timestr~ "")
    (set int64 1 time_len~ 9)
    (set byte 1 col_black~ 0)
    (set int64 1 delay_sec~ 1000)

    (timestr~ time_len~ :time_timetostring !)
    (time_x~ time_y~ time_x2~ time_y2~ back_r back_g back_b alpha :sdl_rectangle_fill !)
    (time_x~ time_y~ col_black~ col_black~ col_black~ timestr~ :sdl_text_ttf !)
    (:sdl_update !)
(funcend)

#include <sdl-lib.l1h>
#include <string.l1h>
#include <process-lib.l1h>
#include <time.l1h>

As you can see, the GUI buttons are created in about 7 lines of code! With :sdl_get_mouse_state I get the current mouse state. If the mouse buttons are clicked and the current coordinate. I do then check if the click was inside a button and launch the program.