#include "system/lt.h"
#include "system/str.h"
#include "system/log.h"
-#include "math/point.h"
+#include "math/vec.h"
#include "label_layer.h"
#include "dynarray.h"
#include "color.h"
#define LABEL_LAYER_SELECTION_THICCNESS 5.0f
-// TODO(#1079): LabelLayer doe snot support z reordering
typedef enum {
LABEL_LAYER_IDLE = 0,
Dynarray *texts;
int selection;
ColorPicker color_picker;
- Point move_anchor;
+ Vec2f move_anchor;
Edit_field *edit_field;
- Point inter_position;
+ Vec2f inter_position;
Color inter_color;
int id_name_counter;
const char *id_name_prefix;
UndoType type;
LabelLayer *layer;
char id[LABEL_LAYER_ID_MAX_SIZE];
- Point position;
+ Vec2f position;
Color color;
char text[LABEL_LAYER_TEXT_MAX_SIZE];
size_t index;
RETURN_LT(lt, NULL);
}
- label_layer->positions = PUSH_LT(lt, create_dynarray(sizeof(Point)), destroy_dynarray);
+ label_layer->positions = PUSH_LT(lt, create_dynarray(sizeof(Vec2f)), destroy_dynarray);
if (label_layer->positions == NULL) {
RETURN_LT(lt, NULL);
}
for (size_t i = 0; i < n; ++i) {
char hex[7];
char id[LABEL_LAYER_ID_MAX_SIZE];
- Point position;
+ Vec2f position;
line = line_stream_next(line_stream);
if (line == NULL) {
size_t n = dynarray_count(label_layer->ids);
char *ids = dynarray_data(label_layer->ids);
- Point *positions = dynarray_data(label_layer->positions);
+ Vec2f *positions = dynarray_data(label_layer->positions);
Color *colors = dynarray_data(label_layer->colors);
char *texts = dynarray_data(label_layer->texts);
? label_layer->inter_color
: colors[i];
- const Point position =
+ const Vec2f position =
label_layer->state == LABEL_LAYER_MOVE && label_layer->selection == (int) i
? label_layer->inter_position
: positions[i];
static
int label_layer_element_at(LabelLayer *label_layer,
const Sprite_font *font,
- Point position)
+ Vec2f position)
{
trace_assert(label_layer);
const int n = (int) dynarray_count(label_layer->texts);
char *ids = dynarray_data(label_layer->ids);
char *texts = dynarray_data(label_layer->texts);
- Point *positions = dynarray_data(label_layer->positions);
+ Vec2f *positions = dynarray_data(label_layer->positions);
for (int i = n - 1; i >= 0; --i) {
Rect boundary = rect_boundary2(
static
int label_layer_add_label(LabelLayer *label_layer,
- Point position,
+ Vec2f position,
Color color,
const char *text,
UndoHistory *undo_history)
}
Color *colors = dynarray_data(label_layer->colors);
- Point *positions = dynarray_data(label_layer->positions);
+ Vec2f *positions = dynarray_data(label_layer->positions);
char *ids = dynarray_data(label_layer->ids);
char *texts = dynarray_data(label_layer->texts);
case SDL_MOUSEBUTTONDOWN: {
switch (event->button.button) {
case SDL_BUTTON_LEFT: {
- const Point position = camera_map_screen(
+ const Vec2f position = camera_map_screen(
camera,
event->button.x,
event->button.y);
if ((event->key.keysym.mod & KMOD_LCTRL) && clipboard) {
int x, y;
SDL_GetMouseState(&x, &y);
- Point position = camera_map_screen(camera, x, y);
+ Vec2f position = camera_map_screen(camera, x, y);
label_layer_add_label(
label_layer,
trace_assert(camera);
trace_assert(label_layer->selection >= 0);
+ Vec2f *positions = dynarray_data(label_layer->positions);
+
switch (event->type) {
case SDL_MOUSEMOTION: {
label_layer->inter_position = vec_sub(
case SDL_MOUSEBUTTONUP: {
switch (event->button.button) {
case SDL_BUTTON_LEFT: {
- UNDO_PUSH(undo_history, create_undo_context(label_layer, UNDO_UPDATE));
+ const float distance = vec_length(
+ vec_sub(label_layer->inter_position,
+ positions[label_layer->selection]));
+
+ if (distance > 1e-6) {
+ UNDO_PUSH(undo_history, create_undo_context(label_layer, UNDO_UPDATE));
+
+ dynarray_replace_at(
+ label_layer->positions,
+ (size_t)label_layer->selection,
+ &label_layer->inter_position);
+ }
- dynarray_replace_at(
- label_layer->positions,
- (size_t)label_layer->selection,
- &label_layer->inter_position);
label_layer->state = LABEL_LAYER_IDLE;
} break;
}
return dynarray_data(label_layer->ids);
}
-Point *label_layer_positions(const LabelLayer *label_layer)
+Vec2f *label_layer_positions(const LabelLayer *label_layer)
{
return dynarray_data(label_layer->positions);
}
size_t n = dynarray_count(label_layer->ids);
char *ids = dynarray_data(label_layer->ids);
- Point *positions = dynarray_data(label_layer->positions);
+ Vec2f *positions = dynarray_data(label_layer->positions);
Color *colors = dynarray_data(label_layer->colors);
char *texts = dynarray_data(label_layer->texts);