palette.odin 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package karl2d_palette
  2. import k2 "../.."
  3. import "core:log"
  4. import "core:fmt"
  5. _ :: fmt
  6. tex: k2.Texture
  7. init :: proc() {
  8. k2.init(1470, 1530, "Karl2D Palette Demo")
  9. }
  10. step :: proc() -> bool {
  11. k2.new_frame()
  12. k2.process_events()
  13. k2.clear(k2.WHITE)
  14. k2.draw_rect({0, 0, f32(k2.get_screen_width() / 2), f32(k2.get_screen_height())}, k2.BLACK)
  15. colors := [?]k2.Color {
  16. k2.BLACK,
  17. k2.WHITE,
  18. k2.GRAY,
  19. k2.DARK_GRAY,
  20. k2.BLUE,
  21. k2.DARK_BLUE,
  22. k2.LIGHT_BLUE,
  23. k2.GREEN,
  24. k2.DARK_GREEN,
  25. k2.LIGHT_GREEN,
  26. k2.RED,
  27. k2.LIGHT_RED,
  28. k2.DARK_RED,
  29. k2.LIGHT_PURPLE,
  30. k2.YELLOW,
  31. k2.LIGHT_YELLOW,
  32. k2.MAGENTA,
  33. }
  34. color_names := [?]string {
  35. "BLACK",
  36. "WHITE",
  37. "GRAY",
  38. "DARK_GRAY",
  39. "BLUE",
  40. "DARK_BLUE",
  41. "LIGHT_BLUE",
  42. "GREEN",
  43. "DARK_GREEN",
  44. "LIGHT_GREEN",
  45. "RED",
  46. "LIGHT_RED",
  47. "DARK_RED",
  48. "LIGHT_PURPLE",
  49. "YELLOW",
  50. "LIGHT_YELLOW",
  51. "MAGENTA",
  52. }
  53. x := f32(290)
  54. y := f32(0)
  55. PAD :: 20
  56. SW :: 50
  57. SH :: 50
  58. for bg, i in colors {
  59. k2.draw_rect({x, y, 890, SH+PAD*2}, bg)
  60. k2.draw_text(color_names[i], {x + 890+PAD, y+25}, 40, bg)
  61. color_name_width := k2.measure_text(color_names[i], 40)
  62. k2.draw_text(color_names[i], {290-color_name_width.x-PAD, y+25}, 40, bg)
  63. for c in colors {
  64. k2.draw_rect({x + PAD, y + PAD, SW, SH}, c)
  65. x += SW
  66. }
  67. x = 290
  68. y += SH + PAD*2
  69. }
  70. k2.present()
  71. free_all(context.temp_allocator)
  72. return !k2.shutdown_wanted()
  73. }
  74. shutdown :: proc() {
  75. k2.destroy_texture(tex)
  76. k2.shutdown()
  77. }
  78. main :: proc() {
  79. context.logger = log.create_console_logger()
  80. init()
  81. run := true
  82. for run {
  83. run = step()
  84. }
  85. shutdown()
  86. }