]> mj.ucw.cz Git - leo.git/blob - style.h
Support for fixed objects
[leo.git] / style.h
1 /*
2  *      Hic Est Leo -- Styling
3  *
4  *      (c) 2014 Martin Mares <mj@ucw.cz>
5  */
6
7 #ifndef _LEO_STYLE_H
8 #define _LEO_STYLE_H
9
10 #include "osm.h"
11 #include "dict.h"
12
13 typedef u32 prop_t, layer_t;            // See dictionaries below
14
15 enum style_layer {
16   STYLE_LAYER_ALL,
17   STYLE_LAYER_DEFAULT,
18   // The other style are defined by style_layer_dict
19 };
20
21 struct style_results {                  // Computed style information for a given object in all layers
22   struct osm_object *obj;
23   uns num_layers;
24   struct style_info **layers;
25   uns num_active_layers;
26   layer_t *active_layers;
27   struct mempool *pool;
28 };
29
30 struct style_info {                     // Computed style information per layer
31   struct style_prop_table *hash;        // Hash table of style properties
32 };
33
34 enum style_prop_type {
35   PROP_TYPE_INVALID,
36   PROP_TYPE_STRING,                     // Quoted string hashed in osm_value_dict
37   PROP_TYPE_IDENT,                      // Unquoted string hashed in osm_value_dict
38   PROP_TYPE_NUMBER,                     // Floating-point number
39   PROP_TYPE_COLOR,                      // Color represented in RGB
40   PROP_TYPE_LIST,                       // List of values
41 };
42
43 struct style_prop {
44   prop_t key;                           // From style_prop_dict
45   enum style_prop_type type;            // PROP_TYPE_xxx
46   union {
47     osm_val_t id;
48     color_t color;
49     double number;
50     clist *list;                        // Of style_val_list_entry
51   } val;
52 };
53
54 struct style_val_list_entry {
55   cnode n;
56   struct style_prop val;                // val.key is unused
57 };
58
59 enum prop_keys {                        // Well-known properties
60     PROP_NULL,
61 #define P(x,y) PROP_##x,
62 #include "dict-props.h"
63 #undef P
64 };
65
66 void styles_init(void);
67 void style_init(struct style_results *r);
68 void style_begin(struct style_results *r, struct osm_object *o);
69 void style_end(struct style_results *r);
70
71 void style_set_by_layer(struct style_results *r, layer_t layer, struct style_prop *p);
72
73 void style_set(struct style_info *si, struct style_prop *p);
74 struct style_prop *style_get(struct style_info *si, prop_t key);
75 osm_val_t style_get_ident(struct style_info *si, prop_t key);
76 osm_val_t style_get_string(struct style_info *si, prop_t key);
77 bool style_get_number(struct style_info *si, prop_t key, double *dp);
78 bool style_get_color(struct style_info *si, prop_t key, color_t *colorp);
79 struct style_prop *style_get_and_check(struct style_info *si, prop_t key, uns allowed_types);
80
81 extern struct dict style_prop_dict, style_layer_dict;
82
83 static inline prop_t style_prop_encode(const char *key)
84 {
85   return dict_encode(&style_prop_dict, key);
86 }
87
88 static inline const char *style_prop_decode(prop_t id)
89 {
90   return dict_decode(&style_prop_dict, id);
91 }
92
93 static inline layer_t style_layer_encode(const char *key)
94 {
95   return dict_encode(&style_layer_dict, key);
96 }
97
98 static inline const char *style_layer_decode(layer_t id)
99 {
100   return dict_decode(&style_layer_dict, id);
101 }
102
103 void style_dump(struct style_results *r);
104 void style_dump_prop(struct style_prop *p);
105
106 void style_scale(struct style_info *si, double *wp, double *hp, prop_t width_prop, prop_t height_prop);
107
108 #endif