#include <stdio.h> #include "graphapp.h" Control *c; /* global */ void draw_shapes(Control *c, Graphics *g) { set_colour(g, RED); fill_rect(g, r); set_colour(g, BLUE); fill_ellipse(g, inset_rect(r,4)); set_colour(g, GREEN); draw_line(g, pt(r.x,r.y), pt(r.x+r.width,r.y+r.height)); draw_line(g, pt(r.x,r.y+r.height), pt(r.x+r.width,r.y)); } void resize_control(Window *w) { Rect r = get_window_area(w); set_control_area(c, inset_rect(r,10)); } int main(int argc, char *argv[]) { App *app; Window *w; Rect r; app = new_app(argc, argv); w = new_window(app, rect(50,50,150,200), "Rectangles", STANDARD_WINDOW); set_window_background(w, LIGHT_GREY); r = rect(10,10,100,100); c = new_control(w, r); on_control_redraw(c, draw_shapes); on_window_resize(w, resize_control); show_window(w); main_loop(app); return 0; }
Notes: