- if (point_layer->state == POINT_LAYER_NORMAL_STATE &&
- event->type == SDL_MOUSEBUTTONDOWN &&
- event->button == SDL_BUTTON_LEFT) {
- const int n = (int) dynarray_count(point_layer->points);
- const Point *points = dynarray_data(point_layer->points);
- const Point point = camera_map_screen(camera, event->x, event->y);
-
- for (int i = 0; i < n; ++i) {
- if (vec_length(vec_sub(points[i], point)) < POINT_LAYER_ELEMENT_RADIUS) {
- point_layer->selected = i;
- return 0;
- }
- }
-
- char id[ID_MAX_SIZE];
-
- for (size_t i = 0; i < ID_MAX_SIZE - 1; ++i) {
- id[i] = (char) ('a' + rand() % ('z' - 'a' + 1));
- }
- id[ID_MAX_SIZE - 1] = '\0';
-
- dynarray_push(point_layer->points, &point);
- dynarray_push(point_layer->colors, &point_layer->color_picker.color);
- dynarray_push(point_layer->ids, id);
+ int selected = 0;
+ if (color_picker_event(
+ &point_layer->color_picker,
+ event,
+ &selected) < 0) {
+ return -1;