zori_style.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include <allegro5/allegro_color.h>
  2. #include "zori.h"
  3. #include "zori_style.h"
  4. static struct zori_style * the_default_style = NULL;
  5. /** Initialize the global default style. */
  6. zori_id zori_initialize_default_style(void) {
  7. the_default_style = calloc(1, sizeof(*the_default_style));
  8. if (!the_default_style) return ZORI_ID_ENOMEM;
  9. the_default_style->text.font = al_create_builtin_font();
  10. the_default_style->text.color = al_color_name("white");
  11. the_default_style->text.flags = ALLEGRO_ALIGN_LEFT;
  12. the_default_style->border.color = al_color_name("white");
  13. the_default_style->back.color = al_color_name("green");
  14. return ZORI_ID_OK;
  15. }
  16. /** Returns the global default style */
  17. struct zori_style * zori_get_default_style() {
  18. return the_default_style;
  19. }
  20. /** Destroys the global default style. */
  21. void zori_destroy_default_style(void) {
  22. free(the_default_style);
  23. the_default_style = NULL;
  24. }
  25. /* Fills in a background style part. */
  26. struct zori_background_style * zori_background_style_init(
  27. struct zori_background_style * bs, zori_color color, zori_bitmap * bitmap, int corner_radius, int flags) {
  28. if (!bs) return NULL;
  29. bs->color = color;
  30. bs->image = bitmap;
  31. bs->flags = flags;
  32. bs->radius = corner_radius;
  33. return bs;
  34. };
  35. /* Fills in a text style part. */
  36. struct zori_text_style * zori_text_style_init(struct zori_text_style * ts,
  37. zori_color color, zori_font * font, int flags) {
  38. if (!ts) return NULL;
  39. ts->color = color;
  40. ts->font = font;
  41. ts->flags = flags;
  42. return ts;
  43. };