all drawing now thru cairo

This commit is contained in:
Bob Polis 2020-10-24 19:25:24 +02:00
parent eb39883bfa
commit 4949ac449e

View File

@ -28,16 +28,18 @@ void print_version() {
void draw(sc::gui::Window& window) {
SDL_Surface* s {SDL_CreateRGBSurface(0, 700, 700, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0)};
sc::gui::Image image {s};
SDL_FillRect(s, nullptr, SDL_MapRGB(s->format, 255, 255, 255));
SDL_Rect rect { 300, 300, 100, 100 };
SDL_FillRect(s, &rect, SDL_MapRGB(s->format, 255, 128, 0));
sc::gui::ImageLock lock {image};
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)};
cairo_set_line_width(cr, 0.1);
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_rectangle(cr, 0, 0, s->w, s->h);
cairo_fill(cr);
cairo_rectangle(cr, 300, 300, 100, 100);
cairo_set_source_rgb(cr, 1, 0.5, 0);
cairo_fill(cr);
cairo_rectangle(cr, 200, 200, 100, 100);
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_fill(cr);
window.show_image(image);
cairo_surface_destroy(cs);