Moving block example
Simple example to draw a block to window which follows mouse movement. Nothing really interesting here.
Compilation
Easiest way to get this example running is to go to examples directory in package root, and run:
$ ./build.sh gui_draw_block
build.sh script compiles Ano script to C, copies source files in place and pops up instructions what to do next. Follow them. Check also examples/README for more info.
Preview
; ------------------------------------------------------------------------------
; gui_draw_block.ano
;
; To compile:
;
; $ ./build/ano ./examples/gui_draw_block/gui_draw_block.ano > \
; engine/dsl_ano.h
; ------------------------------------------------------------------------------
;
; @ANO_SCRIPT_NAME gui_draw_block
; @ANO_SCRIPT_VERSION 0.0.1
; @ANO_SCRIPT_DESCRIPTION Simple thread drawing moving block
;
; @ANO_FLAGS_USE_PROTOS [ ]
; @ANO_FLAGS_VAR_NAME_SUBS [ ]
; @ANO_FLAGS_VAR_WARN_UNUSED [ ]
;
; Copyright © 2016-2026, Jani Salonen <salojan@goto10.co>
; All rights reserved.
;
; Example to draw a block to window which follows mouse movement. Nothing
; really interesting here.
;
main {
; Global pre-initialized variables.
;
mov color ("cyanwhite")
mov pos_x ([int] 0)
mov pos_y ([int] 0)
mov set_w ([int] 64)
mov set_h ([int] 64)
; Initialize windowing system…
;
gui_enabled {
window_init
; …and open main window.
;
window_open (\
title_name: "Drawing window", \
title_charset: NULL, \
flags: 0, \
parent_handle: NOPARENT, \
widget_stack_id: NOWIDGET, \
widget_set: 0, \
window_refresh_divider: ACTIVE_REFRESH, \
position_x: POS_CENTERED, \
position_y: POS_CENTERED, \
size_width: 600, \
size_height: 300, \
cb_main_loop: "cb_mainloop", \
cb_expose: NULL, \
cb_key_press: NULL, \
cb_key_release: NULL, \
cb_button_press: NULL, \
cb_button_release: NULL, \
cb_client_message: NULL, \
cb_save_yourself: NULL, \
cb_configure_notify: NULL, \
cb_destroy_notify: "cb_destroy", \
cb_motion_notify: "cb_motion", \
cb_map_notify: NULL, \
cb_unmap_notify: NULL, \
cb_open_notify: "cb_open")
}
; No exit here as callbacks are taking over when main process is done.
}
_WINCB_MAINLOOP_ callback cb_mainloop (_hnd) {
; Clear window…
;
draw_wipe (_hnd)
; …and draw simple block where the pointer is.
;
draw_set (_hnd, \
pos_x, pos_y, pos_x + set_w, pos_y + set_h, color)
}
_WINCB_OPEN_ callback cb_open (_hnd) {
_hnd.map()
}
_WINCB_DESTROY_ callback cb_destroy (_hnd) {
_hnd.destroy()
exit
}
_WINCB_MOTION_ callback cb_motion (_hnd, \
_x, _y, _x_root, _y_root, _state, _detail) {
; Update block coordinates.
;
mov pos_x (_x - (set_w / 2))
mov pos_y (_y - (set_h / 2))
}
; ------------------------------------------------------------------------------ ; gui_draw_block.w2c ; ; To compile: ; ; $ ./build/widget ./examples/gui_draw_block/gui_draw_block.w2c > \ ; engine/widget_defs.h ; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------ ; gui_draw_block.m2c ; ; To compile: ; ; $ ./build/menu ./examples/gui_draw_block/gui_draw_block.m2c > \ ; engine/menu_defs.h ; ------------------------------------------------------------------------------
Copyright © 2026, Jani Salonen <salojan at goto10 piste co>. Piste is finnish word and means dot. All rights reserved.