]> git.lizzy.rs Git - nothing.git/commitdiff
(#910) Move file unit to libsystem
authorrexim <reximkut@gmail.com>
Sat, 6 Jul 2019 18:06:46 +0000 (01:06 +0700)
committerrexim <reximkut@gmail.com>
Sat, 6 Jul 2019 18:06:46 +0000 (01:06 +0700)
It didn't compile on Windows

CMakeLists.txt
src/game/level/level_editor/color_picker.c
src/game/level/level_editor/color_picker.h

index 7fe465d6a4e2b8abddca3b0074d332e94399e15a..433b05aef72e12f755bfbd6c5daf9ab11427d3c5 100644 (file)
@@ -46,6 +46,8 @@ add_library(system STATIC
   src/dynarray.c
   src/hashset.h
   src/hashset.c
+  src/system/file.h
+  src/system/file.c
   )
 
 add_library(ebisp STATIC
@@ -163,8 +165,6 @@ add_executable(nothing
   src/game/level/level_editor/layer.c
   src/game/level/level_editor/label_layer.c
   src/game/level/level_editor/label_layer.h
-  src/system/file.h
-  src/system/file.c
 )
 target_link_libraries(nothing ${SDL2_LIBRARIES} system ebisp)
 
index 65fd6c05cf782b15df9bddb94c980acc8e6d5fe7..488e40669b0ecb60864fa4463da7306b09f53c3f 100644 (file)
@@ -25,9 +25,11 @@ ColorPicker create_color_picker_from_rgba(Color color)
 {
     Color color_hsla = rgba_to_hsla(color);
     ColorPicker color_picker = {
-        .hue = {0, color_hsla.r, 360.0f},
-        .saturation = {0, color_hsla.g, 1.0f},
-        .lightness = {0, color_hsla.b, 1.0f}
+        .sliders = {
+            {0, color_hsla.r, 360.0f},
+            {0, color_hsla.g, 1.0f},
+            {0, color_hsla.b, 1.0f}
+        }
     };
     return color_picker;
 }
@@ -58,32 +60,16 @@ int color_picker_render(const ColorPicker *color_picker,
     trace_assert(camera);
 
     /* TODO(#931): Color Picker sliders don't have any labels */
-
-    if (slider_render(
-            &color_picker->hue,
-            camera,
-            rect(0.0f, COLOR_SLIDER_HEIGHT,
-                 COLOR_SLIDER_WIDTH, COLOR_SLIDER_HEIGHT)) < 0) {
-        return -1;
-    }
-
-    if (slider_render(
-            &color_picker->saturation,
-            camera,
-            rect(0.0f, COLOR_SLIDER_HEIGHT * 2.0f,
-                 COLOR_SLIDER_WIDTH, COLOR_SLIDER_HEIGHT)) < 0) {
-        return -1;
-    }
-
-    if (slider_render(
-            &color_picker->lightness,
-            camera,
-            rect(0.0f, COLOR_SLIDER_HEIGHT * 3.0f,
-                 COLOR_SLIDER_WIDTH, COLOR_SLIDER_HEIGHT)) < 0) {
-        return -1;
+    for (ColorPickerSlider index = 0; index < COLOR_SLIDER_N; ++index) {
+        if (slider_render(
+                &color_picker->sliders[index],
+                camera,
+                rect(0.0f, COLOR_SLIDER_HEIGHT * (float) (index + 1),
+                     COLOR_SLIDER_WIDTH, COLOR_SLIDER_HEIGHT)) < 0) {
+            return -1;
+        }
     }
 
-
     return 0;
 }
 
@@ -95,30 +81,15 @@ int color_picker_event(ColorPicker *color_picker, const SDL_Event *event, int *s
 
     int selected = 0;
 
-    if (slider_event(&color_picker->hue,
-                     event,
-                     rect(0.0f, COLOR_SLIDER_HEIGHT,
-                          COLOR_SLIDER_WIDTH, COLOR_SLIDER_HEIGHT),
-                     &selected) < 0) {
-        return -1;
-    }
-
-    if (!selected) {
-        if (slider_event(&color_picker->saturation,
-                         event,
-                         rect(0.0f, COLOR_SLIDER_HEIGHT * 2.0f,
-                              COLOR_SLIDER_WIDTH, COLOR_SLIDER_HEIGHT),
-                         &selected) < 0) {
-            return -1;
-        }
-    }
-
-    if (!selected) {
-        if (slider_event(&color_picker->lightness,
-                         event,
-                         rect(0.0f, COLOR_SLIDER_HEIGHT * 3.0f,
-                              COLOR_SLIDER_WIDTH, COLOR_SLIDER_HEIGHT),
-                         &selected) < 0) {
+    for (ColorPickerSlider index = 0;
+         !selected && index < COLOR_SLIDER_N;
+         ++index) {
+        if (slider_event(
+                &color_picker->sliders[index],
+                event,
+                rect(0.0f, COLOR_SLIDER_HEIGHT * (float) (index + 1),
+                     COLOR_SLIDER_WIDTH, COLOR_SLIDER_HEIGHT),
+                &selected) < 0) {
             return -1;
         }
     }
@@ -133,8 +104,8 @@ int color_picker_event(ColorPicker *color_picker, const SDL_Event *event, int *s
 Color color_picker_rgba(const ColorPicker *color_picker)
 {
     return hsla(
-        color_picker->hue.value,
-        color_picker->saturation.value,
-        color_picker->lightness.value,
+        color_picker->sliders[COLOR_SLIDER_HUE].value,
+        color_picker->sliders[COLOR_SLIDER_SAT].value,
+        color_picker->sliders[COLOR_SLIDER_LIT].value,
         1.0f);
 }
index 1f64bea22ac3f40bc708dbcc387503e74c5090f9..3bc98101751ecc15bb69578529cb443c02a08de2 100644 (file)
@@ -5,11 +5,16 @@
 #include "layer.h"
 #include "ui/slider.h"
 
+typedef enum {
+    COLOR_SLIDER_HUE = 0,
+    COLOR_SLIDER_SAT,
+    COLOR_SLIDER_LIT,
+    COLOR_SLIDER_N
+} ColorPickerSlider;
+
 typedef struct {
     // TODO(#933): ColorPicker should use array of sliders
-    Slider hue;
-    Slider saturation;
-    Slider lightness;
+    Slider sliders[COLOR_SLIDER_N];
 } ColorPicker;
 
 typedef struct LineStream LineStream;