added some text drawing

This commit is contained in:
Bob Polis 2020-10-24 22:57:05 +02:00
parent 4949ac449e
commit 5a7e2a0547

View File

@ -32,15 +32,30 @@ void draw(sc::gui::Window& window) {
cairo_surface_t* cs {cairo_image_surface_create_for_data(static_cast<unsigned char*>(s->pixels),
CAIRO_FORMAT_RGB24, s->w, s->h, s->pitch)};
cairo_t* cr {cairo_create(cs)};
// white background
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_rectangle(cr, 0, 0, s->w, s->h);
cairo_fill(cr);
// orange rectangle
cairo_rectangle(cr, 300, 300, 100, 100);
cairo_set_source_rgb(cr, 1, 0.5, 0);
cairo_fill(cr);
// black rectangle
cairo_rectangle(cr, 200, 200, 100, 100);
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_fill(cr);
// light blue text
cairo_set_source_rgb(cr, 0, 0.5, 1);
cairo_select_font_face(cr, "Optima", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size(cr, 42);
cairo_move_to(cr, 350, 150);
cairo_show_text(cr, "Cairo on SDL");
// show
window.show_image(image);
cairo_surface_destroy(cs);
cairo_destroy(cr);