]> mj.ucw.cz Git - leo.git/blob - style.h
TODO
[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_cleanup(struct style_results *r);
69 void style_begin(struct style_results *r, struct osm_object *o);
70 void style_end(struct style_results *r);
71 void style_enable_default_layer(struct style_results *r);
72
73 void style_set_by_layer(struct style_results *r, layer_t layer, struct style_prop *p);
74 struct style_prop *style_get_by_layer(struct style_results *r, layer_t layer, prop_t key);
75
76 void style_set(struct style_info *si, struct style_prop *p);
77 struct style_prop *style_get(struct style_info *si, prop_t key);
78 osm_val_t style_get_ident(struct style_info *si, prop_t key);
79 osm_val_t style_get_string(struct style_info *si, prop_t key);
80 bool style_get_number(struct style_info *si, prop_t key, double *dp);
81 bool style_get_color(struct style_info *si, prop_t key, color_t *colorp);
82 struct style_prop *style_get_and_check(struct style_info *si, prop_t key, uns allowed_types);
83
84 extern struct dict style_prop_dict, style_layer_dict;
85
86 static inline prop_t style_prop_encode(const char *key)
87 {
88   return dict_encode(&style_prop_dict, key);
89 }
90
91 static inline const char *style_prop_decode(prop_t id)
92 {
93   return dict_decode(&style_prop_dict, id);
94 }
95
96 static inline layer_t style_layer_encode(const char *key)
97 {
98   return dict_encode(&style_layer_dict, key);
99 }
100
101 static inline layer_t style_layer_encode_if_exists(const char *key)
102 {
103   return dict_encode_if_exists(&style_layer_dict, key);
104 }
105
106 static inline const char *style_layer_decode(layer_t id)
107 {
108   return dict_decode(&style_layer_dict, id);
109 }
110
111 void style_dump(struct style_results *r);
112 void style_dump_prop(struct style_prop *p);
113
114 void style_scale(struct style_info *si, double *wp, double *hp, prop_t width_prop, prop_t height_prop);
115
116 #endif