db_pixmap.c 922 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #define DB_IMPL_NAME "Pixmap"
  2. typedef struct {
  3. Display *display;
  4. Window window;
  5. GC gc;
  6. Pixmap back_buffer;
  7. } DB;
  8. void db_init(DB *db, Display *display, Window window)
  9. {
  10. db->display = display;
  11. db->window = window;
  12. db->gc = XCreateGC(display, window, 0, NULL);
  13. db->back_buffer = XCreatePixmap(display, window, WIDTH, HEIGHT, 24);
  14. }
  15. void db_clear(DB *db)
  16. {
  17. XSetForeground(db->display, db->gc, 0);
  18. XFillRectangle(db->display, db->back_buffer, db->gc, 0, 0, WIDTH, HEIGHT);
  19. }
  20. void db_fill_rect(DB *db, int x, int y, unsigned int w, unsigned int h)
  21. {
  22. XSetForeground(db->display, db->gc, 0xFF0000);
  23. XFillRectangle(db->display, db->back_buffer, db->gc, x, y, w, h);
  24. }
  25. void db_swap_buffers(DB *db)
  26. {
  27. XCopyArea(db->display,
  28. db->back_buffer,
  29. db->window,
  30. db->gc,
  31. 0, 0,
  32. WIDTH, HEIGHT,
  33. 0, 0);
  34. }