/[zanavi_public1]/navit/navit/graphics.c
ZANavi

Diff of /navit/navit/graphics.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2 Revision 27
1/**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
1/** 20/**
2 * Navit, a modular navigation system. 21 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team 22 * Copyright (C) 2005-2008 Navit Team
4 * 23 *
5 * This program is free software; you can redistribute it and/or 24 * This program is free software; you can redistribute it and/or
51#include "file.h" 70#include "file.h"
52#include "event.h" 71#include "event.h"
53// 72//
54#include "attr.h" 73#include "attr.h"
55#include "navit.h" 74#include "navit.h"
56 75#include "route.h"
57
58// bad thing
59struct navit *global_navit;
60// bad thing
61
62 76
63//############################################################################################################## 77//##############################################################################################################
64//# Description: 78//# Description:
65//# Comment: 79//# Comment:
66//# Authors: Martin Schaller (04/2008) 80//# Authors: Martin Schaller (04/2008)
78 struct graphics_font **font; 92 struct graphics_font **font;
79 struct graphics_gc *gc[3]; 93 struct graphics_gc *gc[3];
80 struct attr **attrs; 94 struct attr **attrs;
81 struct callback_list *cbl; 95 struct callback_list *cbl;
82 struct point_rect r; 96 struct point_rect r;
83 int gamma,brightness,contrast; 97 int gamma, brightness, contrast;
84 int colormgmt; 98 int colormgmt;
85 int font_size; 99 int font_size;
86 GList *selection; 100 GList *selection;
87}; 101};
88 102
103
104/*
89struct display_context 105 struct display_context
90{ 106 {
91 struct graphics *gra; 107 struct graphics *gra;
92 struct element *e; 108 struct element *e;
93 struct graphics_gc *gc; 109 struct graphics_gc *gc;
94 struct graphics_gc *gc_background; 110 struct graphics_gc *gc_background;
95 struct graphics_image *img; 111 struct graphics_image *img;
96 enum projection pro; 112 enum projection pro;
97 int mindist; 113 int mindist;
98 struct transformation *trans; 114 struct transformation *trans;
99 enum item_type type; 115 enum item_type type;
100 int maxlen; 116 int maxlen;
117 };
118
119 #define HASH_SIZE 1024
120 */
121
122/*
123 struct hash_entry
124 {
125 enum item_type type;
126 struct displayitem *di;
127 };
128 */
129
130/*
131 struct displaylist {
132 int busy;
133 int workload;
134 struct callback *cb;
135 struct layout *layout, *layout_hashed;
136 struct display_context dc;
137 int order, order_hashed, max_offset;
138 struct mapset *ms;
139 struct mapset_handle *msh;
140 struct map *m;
141 int conv;
142 struct map_selection *sel;
143 struct map_rect *mr;
144 struct callback *idle_cb;
145 struct event_idle *idle_ev;
146 unsigned int seq;
147 struct hash_entry hash_entries[HASH_SIZE];
148 };
149 */
150
151struct displaylist_icon_cache
152{
153 unsigned int seq;
154
101}; 155};
102 156
103#define HASH_SIZE 1024
104struct hash_entry
105{
106 enum item_type type;
107 struct displayitem *di;
108};
109
110
111struct displaylist {
112 int busy;
113 int workload;
114 struct callback *cb;
115 struct layout *layout, *layout_hashed;
116 struct display_context dc;
117 int order, order_hashed, max_offset;
118 struct mapset *ms;
119 struct mapset_handle *msh;
120 struct map *m;
121 int conv;
122 struct map_selection *sel;
123 struct map_rect *mr;
124 struct callback *idle_cb;
125 struct event_idle *idle_ev;
126 unsigned int seq;
127 struct hash_entry hash_entries[HASH_SIZE];
128};
129
130
131struct displaylist_icon_cache {
132 unsigned int seq;
133
134};
135
136
137/** 157/**
138 * FIXME 158 * FIXME
139 * @param <> 159 * @param <>
140 * @returns <> 160 * @returns <>
141 * @author Martin Schaller (04/2008) 161 * @author Martin Schaller (04/2008)
142*/ 162 */
143struct displayitem { 163struct displayitem
164{
144 struct displayitem *next; 165 struct displayitem *next;
145 struct item item; 166 struct item item;
146 char *label; 167 char *label;
147 int count; 168 int count;
148 struct coord c[0]; 169 struct coord c[0];
150 171
151static void draw_circle(struct point *pnt, int diameter, int scale, int start, int len, struct point *res, int *pos, int dir); 172static void draw_circle(struct point *pnt, int diameter, int scale, int start, int len, struct point *res, int *pos, int dir);
152static void graphics_process_selection(struct graphics *gra, struct displaylist *dl); 173static void graphics_process_selection(struct graphics *gra, struct displaylist *dl);
153static void graphics_gc_init(struct graphics *this_); 174static void graphics_gc_init(struct graphics *this_);
154 175
155static void
156clear_hash(struct displaylist *dl) 176static void clear_hash(struct displaylist *dl)
157{ 177{
158 int i; 178 int i;
159 for (i = 0 ; i < HASH_SIZE ; i++) 179 for (i = 0; i < HASH_SIZE_GRAPHICS_; i++)
160 dl->hash_entries[i].type=type_none; 180 dl->hash_entries[i].type = type_none;
161} 181}
162 182
163static struct hash_entry * 183static struct hash_entry *
164get_hash_entry(struct displaylist *dl, enum item_type type) 184get_hash_entry(struct displaylist *dl, enum item_type type)
165{ 185{
166 int hashidx=(type*2654435761UL) & (HASH_SIZE-1); 186 int hashidx = (type * 2654435761UL) & (HASH_SIZE_GRAPHICS_ - 1);
167 int offset=dl->max_offset; 187 int offset = dl->max_offset;
168 do { 188 do
189 {
169 if (!dl->hash_entries[hashidx].type) 190 if (!dl->hash_entries[hashidx].type)
191 {
170 return NULL; 192 return NULL;
193 }
194 if (dl->hash_entries[hashidx].type == type)
195 {
196 return &dl->hash_entries[hashidx];
197 }
198 hashidx = (hashidx + 1) & (HASH_SIZE_GRAPHICS_ - 1);
199 }
200
201 while (offset-- > 0);
202
203 return NULL;
204}
205
206static struct hash_entry *
207set_hash_entry(struct displaylist *dl, enum item_type type)
208{
209 int hashidx = (type * 2654435761UL) & (HASH_SIZE_GRAPHICS_ - 1);
210 int offset = 0;
211 for (;;)
212 {
213 if (!dl->hash_entries[hashidx].type)
214 {
215 dl->hash_entries[hashidx].type = type;
216 if (dl->max_offset < offset)
217 dl->max_offset = offset;
218 return &dl->hash_entries[hashidx];
219 }
171 if (dl->hash_entries[hashidx].type == type) 220 if (dl->hash_entries[hashidx].type == type)
172 return &dl->hash_entries[hashidx]; 221 return &dl->hash_entries[hashidx];
173 hashidx=(hashidx+1)&(HASH_SIZE-1); 222 hashidx = (hashidx + 1) & (HASH_SIZE_GRAPHICS_ - 1);
174 } while (offset-- > 0); 223 offset++;
224 }
175 return NULL; 225 return NULL;
176} 226}
177 227
178static struct hash_entry *
179set_hash_entry(struct displaylist *dl, enum item_type type)
180{
181 int hashidx=(type*2654435761UL) & (HASH_SIZE-1);
182 int offset=0;
183 for (;;) {
184 if (!dl->hash_entries[hashidx].type) {
185 dl->hash_entries[hashidx].type=type;
186 if (dl->max_offset < offset)
187 dl->max_offset=offset;
188 return &dl->hash_entries[hashidx];
189 }
190 if (dl->hash_entries[hashidx].type == type)
191 return &dl->hash_entries[hashidx];
192 hashidx=(hashidx+1)&(HASH_SIZE-1);
193 offset++;
194 }
195 return NULL;
196}
197
198static int
199graphics_set_attr_do(struct graphics *gra, struct attr *attr) 228static int graphics_set_attr_do(struct graphics *gra, struct attr *attr)
200{ 229{
201 switch (attr->type) { 230 switch (attr->type)
231 {
202 case attr_gamma: 232 case attr_gamma:
203 gra->gamma=attr->u.num; 233 gra->gamma = attr->u.num;
204 break; 234 break;
205 case attr_brightness: 235 case attr_brightness:
206 gra->brightness=attr->u.num; 236 gra->brightness = attr->u.num;
207 break; 237 break;
208 case attr_contrast: 238 case attr_contrast:
209 gra->contrast=attr->u.num; 239 gra->contrast = attr->u.num;
210 break; 240 break;
211 case attr_font_size: 241 case attr_font_size:
212 gra->font_size=attr->u.num; 242 gra->font_size = attr->u.num;
213 return 1; 243 return 1;
214 default: 244 default:
215 return 0; 245 return 0;
216 } 246 }
217 gra->colormgmt=(gra->gamma != 65536 || gra->brightness != 0 || gra->contrast != 65536); 247 gra->colormgmt = (gra->gamma != 65536 || gra->brightness != 0 || gra->contrast != 65536);
218 graphics_gc_init(gra); 248 graphics_gc_init(gra);
219 return 1; 249 return 1;
220} 250}
221 251
222int
223graphics_set_attr(struct graphics *gra, struct attr *attr) 252int graphics_set_attr(struct graphics *gra, struct attr *attr)
224{ 253{
225 int ret=1; 254 int ret = 1;
226 // dbg(0,"enter\n"); 255 // //DBG dbg(0,"enter\n");
227 if (gra->meth.set_attr) 256 if (gra->meth.set_attr)
228 ret=gra->meth.set_attr(gra->priv, attr); 257 ret = gra->meth.set_attr(gra->priv, attr);
229 if (!ret) 258 if (!ret)
230 ret=graphics_set_attr_do(gra, attr); 259 ret = graphics_set_attr_do(gra, attr);
231 return ret != 0; 260 return ret != 0;
232} 261}
233 262
234void
235graphics_set_rect(struct graphics *gra, struct point_rect *pr) 263void graphics_set_rect(struct graphics *gra, struct point_rect *pr)
236{ 264{
237 gra->r=*pr; 265 gra->r = *pr;
238} 266}
239 267
240/** 268/**
241 * Creates a new graphics object 269 * Creates a new graphics object
242 * attr type required 270 * attr type required
243 * @param <> 271 * @param <>
244 * @returns <> 272 * @returns <>
245 * @author Martin Schaller (04/2008) 273 * @author Martin Schaller (04/2008)
246*/ 274 */
247struct graphics * graphics_new(struct attr *parent, struct attr **attrs) 275struct graphics * graphics_new(struct attr *parent, struct attr **attrs)
248{ 276{
249 struct graphics *this_; 277 struct graphics *this_;
250 struct attr *type_attr; 278 struct attr *type_attr;
251 struct graphics_priv * (*graphicstype_new)(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl); 279 struct graphics_priv * (*graphicstype_new)(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl);
252 280
253 if (! (type_attr=attr_search(attrs, NULL, attr_type))) { 281 if (!(type_attr = attr_search(attrs, NULL, attr_type)))
254 return NULL; 282 {
255 }
256
257 graphicstype_new=plugin_get_graphics_type(type_attr->u.str);
258 if (! graphicstype_new)
259 return NULL; 283 return NULL;
284 }
285
286 graphicstype_new = plugin_get_graphics_type(type_attr->u.str);
287 if (!graphicstype_new)
288 {
289 return NULL;
290 }
291
260 this_=g_new0(struct graphics, 1); 292 this_=g_new0(struct graphics, 1);
261 this_->cbl=callback_list_new(); 293 this_->cbl = callback_list_new();
262 this_->priv=(*graphicstype_new)(parent->u.navit, &this_->meth, attrs, this_->cbl); 294 this_->priv = (*graphicstype_new)(parent->u.navit, &this_->meth, attrs, this_->cbl);
263 this_->attrs=attr_list_dup(attrs); 295 this_->attrs = attr_list_dup(attrs);
264 this_->brightness=0; 296 this_->brightness = 0;
265 this_->contrast=65536; 297 this_->contrast = 65536;
266 this_->gamma=65536; 298 this_->gamma = 65536;
267 this_->font_size=20; 299 this_->font_size = 20;
300
268 while (*attrs) { 301 while (*attrs)
302 {
269 graphics_set_attr_do(this_,*attrs); 303 graphics_set_attr_do(this_, *attrs);
270 attrs++; 304 attrs++;
271 } 305 }
306
272 return this_; 307 return this_;
273} 308}
274 309
275/** 310/**
276 * FIXME 311 * FIXME
277 * @param <> 312 * @param <>
278 * @returns <> 313 * @returns <>
279 * @author Martin Schaller (04/2008) 314 * @author Martin Schaller (04/2008)
280*/ 315 */
281int graphics_get_attr(struct graphics *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) 316int graphics_get_attr(struct graphics *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
282{ 317{
283 return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter); 318 return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
284} 319}
285 320
286/** 321/**
287 * FIXME 322 * FIXME
288 * @param <> 323 * @param <>
289 * @returns <> 324 * @returns <>
290 * @author Martin Schaller (04/2008) 325 * @author Martin Schaller (04/2008)
291*/ 326 */
292struct graphics * graphics_overlay_new(struct graphics *parent, struct point *p, int w, int h, int alpha, int wraparound) 327struct graphics * graphics_overlay_new(struct graphics *parent, struct point *p, int w, int h, int alpha, int wraparound)
293{ 328{
294 struct graphics *this_; 329 struct graphics *this_;
295 struct point_rect pr; 330 struct point_rect pr;
296 if (!parent->meth.overlay_new) 331 if (!parent->meth.overlay_new)
297 return NULL;
298 this_=g_new0(struct graphics, 1); 332 return NULL;this_=g_new0(struct graphics, 1);
299 this_->priv=parent->meth.overlay_new(parent->priv, &this_->meth, p, w, h, alpha, wraparound); 333 this_->priv = parent->meth.overlay_new(parent->priv, &this_->meth, p, w, h, alpha, wraparound);
300 pr.lu.x=0; 334 pr.lu.x = 0;
301 pr.lu.y=0; 335 pr.lu.y = 0;
302 pr.rl.x=w; 336 pr.rl.x = w;
303 pr.rl.y=h; 337 pr.rl.y = h;
304 this_->font_size=20; 338 this_->font_size = 20;
305 graphics_set_rect(this_, &pr); 339 graphics_set_rect(this_, &pr);
306 if (!this_->priv) { 340 if (!this_->priv)
341 {
307 g_free(this_); 342 g_free(this_);
308 this_=NULL; 343 this_ = NULL;
309 } 344 }
310 return this_; 345 return this_;
311} 346}
312 347
313/** 348/**
318 * @param w The new width of the overlay 353 * @param w The new width of the overlay
319 * @param h The new height of the overlay 354 * @param h The new height of the overlay
320 * @param alpha The new alpha of the overlay 355 * @param alpha The new alpha of the overlay
321 * @param wraparound The new wraparound of the overlay 356 * @param wraparound The new wraparound of the overlay
322 */ 357 */
323void
324graphics_overlay_resize(struct graphics *this_, struct point *p, int w, int h, int alpha, int wraparound) 358void graphics_overlay_resize(struct graphics *this_, struct point *p, int w, int h, int alpha, int wraparound)
325{ 359{
326 if (! this_->meth.overlay_resize) { 360 if (!this_->meth.overlay_resize)
361 {
327 return; 362 return;
328 } 363 }
329 364
330 this_->meth.overlay_resize(this_->priv, p, w, h, alpha, wraparound); 365 this_->meth.overlay_resize(this_->priv, p, w, h, alpha, wraparound);
331} 366}
332 367
333static void
334graphics_gc_init(struct graphics *this_) 368static void graphics_gc_init(struct graphics *this_)
335{ 369{
336 struct color background={ COLOR_BACKGROUND_ }; 370 struct color background =
337 struct color black={ COLOR_BLACK_ }; 371 { COLOR_BACKGROUND_ };
338 struct color white={ COLOR_WHITE_ }; 372 struct color black =
373 { COLOR_BLACK_ };
374 struct color white =
375 { COLOR_WHITE_ };
339 if (!this_->gc[0] || !this_->gc[1] || !this_->gc[2]) 376 if (!this_->gc[0] || !this_->gc[1] || !this_->gc[2])
340 return; 377 return;
341 graphics_gc_set_background(this_->gc[0], &background ); 378 graphics_gc_set_background(this_->gc[0], &background);
342 graphics_gc_set_foreground(this_->gc[0], &background ); 379 graphics_gc_set_foreground(this_->gc[0], &background);
343 graphics_gc_set_background(this_->gc[1], &black ); 380 graphics_gc_set_background(this_->gc[1], &black);
344 graphics_gc_set_foreground(this_->gc[1], &white ); 381 graphics_gc_set_foreground(this_->gc[1], &white);
345 graphics_gc_set_background(this_->gc[2], &white ); 382 graphics_gc_set_background(this_->gc[2], &white);
346 graphics_gc_set_foreground(this_->gc[2], &black ); 383 graphics_gc_set_foreground(this_->gc[2], &black);
347} 384}
348 385
349
350
351/** 386/**
352 * FIXME 387 * FIXME
353 * @param <> 388 * @param <>
354 * @returns <> 389 * @returns <>
355 * @author Martin Schaller (04/2008) 390 * @author Martin Schaller (04/2008)
356*/ 391 */
357void graphics_init(struct graphics *this_) 392void graphics_init(struct graphics *this_)
358{ 393{
359 if (this_->gc[0]) 394 if (this_->gc[0])
360 return; 395 return;
361 this_->gc[0]=graphics_gc_new(this_); 396 this_->gc[0] = graphics_gc_new(this_);
362 this_->gc[1]=graphics_gc_new(this_); 397 this_->gc[1] = graphics_gc_new(this_);
363 this_->gc[2]=graphics_gc_new(this_); 398 this_->gc[2] = graphics_gc_new(this_);
364 graphics_gc_init(this_); 399 graphics_gc_init(this_);
365 graphics_background_gc(this_, this_->gc[0]); 400 graphics_background_gc(this_, this_->gc[0]);
366} 401}
367 402
368/** 403/**
369 * FIXME 404 * FIXME
370 * @param <> 405 * @param <>
371 * @returns <> 406 * @returns <>
372 * @author Martin Schaller (04/2008) 407 * @author Martin Schaller (04/2008)
373*/ 408 */
374void * graphics_get_data(struct graphics *this_, const char *type) 409void * graphics_get_data(struct graphics *this_, const char *type)
375{ 410{
376 return (this_->meth.get_data(this_->priv, type)); 411 return (this_->meth.get_data(this_->priv, type));
377} 412}
378 413
389/** 424/**
390 * FIXME 425 * FIXME
391 * @param <> 426 * @param <>
392 * @returns <> 427 * @returns <>
393 * @author Martin Schaller (04/2008) 428 * @author Martin Schaller (04/2008)
394*/ 429 */
395struct graphics_font * graphics_font_new(struct graphics *gra, int size, int flags) 430struct graphics_font * graphics_font_new(struct graphics *gra, int size, int flags)
396{ 431{
397 struct graphics_font *this_; 432 struct graphics_font *this_;
398 433
399 this_=g_new0(struct graphics_font,1); 434 this_=g_new0(struct graphics_font,1);
400 this_->priv=gra->meth.font_new(gra->priv, &this_->meth, gra->default_font, size, flags); 435 this_->priv = gra->meth.font_new(gra->priv, &this_->meth, gra->default_font, size, flags);
401 return this_; 436 return this_;
402} 437}
403 438
404struct graphics_font * graphics_named_font_new(struct graphics *gra, char *font, int size, int flags) 439struct graphics_font * graphics_named_font_new(struct graphics *gra, char *font, int size, int flags)
405{ 440{
406 struct graphics_font *this_; 441 struct graphics_font *this_;
407 442
408 this_=g_new0(struct graphics_font,1); 443 this_=g_new0(struct graphics_font,1);
409 this_->priv=gra->meth.font_new(gra->priv, &this_->meth, font, size, flags); 444 this_->priv = gra->meth.font_new(gra->priv, &this_->meth, font, size, flags);
410 return this_; 445 return this_;
411} 446}
412
413 447
414/** 448/**
415 * Destroy graphics 449 * Destroy graphics
416 * Called when navit exits 450 * Called when navit exits
417 * @param gra The graphics instance 451 * @param gra The graphics instance
436 * @author Sarah Nordstrom (05/2008) 470 * @author Sarah Nordstrom (05/2008)
437 */ 471 */
438void graphics_font_destroy_all(struct graphics *gra) 472void graphics_font_destroy_all(struct graphics *gra)
439{ 473{
440 int i; 474 int i;
441 for(i = 0 ; i < gra->font_len; i++) { 475 for (i = 0; i < gra->font_len; i++)
476 {
442 if(!gra->font[i]) continue; 477 if (!gra->font[i])
478 continue;
443 gra->font[i]->meth.font_destroy(gra->font[i]->priv); 479 gra->font[i]->meth.font_destroy(gra->font[i]->priv);
444 gra->font[i] = NULL; 480 gra->font[i] = NULL;
445 } 481 }
446} 482}
447 483
448/** 484/**
449 * FIXME 485 * FIXME
450 * @param <> 486 * @param <>
451 * @returns <> 487 * @returns <>
452 * @author Martin Schaller (04/2008) 488 * @author Martin Schaller (04/2008)
453*/ 489 */
454struct graphics_gc * graphics_gc_new(struct graphics *gra) 490struct graphics_gc * graphics_gc_new(struct graphics *gra)
455{ 491{
456 struct graphics_gc *this_; 492 struct graphics_gc *this_;
457 493
458 this_=g_new0(struct graphics_gc,1); 494 this_=g_new0(struct graphics_gc,1);
459 this_->priv=gra->meth.gc_new(gra->priv, &this_->meth); 495 this_->priv = gra->meth.gc_new(gra->priv, &this_->meth);
460 this_->gra=gra; 496 this_->gra = gra;
461 return this_; 497 return this_;
462} 498}
463 499
464/** 500/**
465 * FIXME 501 * FIXME
466 * @param <> 502 * @param <>
467 * @returns <> 503 * @returns <>
468 * @author Martin Schaller (04/2008) 504 * @author Martin Schaller (04/2008)
469*/ 505 */
470void graphics_gc_destroy(struct graphics_gc *gc) 506void graphics_gc_destroy(struct graphics_gc *gc)
471{ 507{
472 gc->meth.gc_destroy(gc->priv); 508 gc->meth.gc_destroy(gc->priv);
473 g_free(gc); 509 g_free(gc);
474} 510}
475 511
476static void
477graphics_convert_color(struct graphics *gra, struct color *in, struct color *out) 512static void graphics_convert_color(struct graphics *gra, struct color *in, struct color *out)
478{ 513{
479 *out=*in; 514 *out = *in;
480 if (gra->brightness) { 515 if (gra->brightness)
516 {
481 out->r+=gra->brightness; 517 out->r += gra->brightness;
482 out->g+=gra->brightness; 518 out->g += gra->brightness;
483 out->b+=gra->brightness; 519 out->b += gra->brightness;
484 } 520 }
485 if (gra->contrast != 65536) { 521 if (gra->contrast != 65536)
522 {
486 out->r=out->r*gra->contrast/65536; 523 out->r = out->r * gra->contrast / 65536;
487 out->g=out->g*gra->contrast/65536; 524 out->g = out->g * gra->contrast / 65536;
488 out->b=out->b*gra->contrast/65536; 525 out->b = out->b * gra->contrast / 65536;
489 } 526 }
490 if (out->r < 0) 527 if (out->r < 0)
491 out->r=0; 528 out->r = 0;
492 if (out->r > 65535) 529 if (out->r > 65535)
493 out->r=65535; 530 out->r = 65535;
494 if (out->g < 0) 531 if (out->g < 0)
495 out->g=0; 532 out->g = 0;
496 if (out->g > 65535) 533 if (out->g > 65535)
497 out->g=65535; 534 out->g = 65535;
498 if (out->b < 0) 535 if (out->b < 0)
499 out->b=0; 536 out->b = 0;
500 if (out->b > 65535) 537 if (out->b > 65535)
501 out->b=65535; 538 out->b = 65535;
502 if (gra->gamma != 65536) { 539 if (gra->gamma != 65536)
540 {
503 out->r=pow(out->r/65535.0,gra->gamma/65536.0)*65535.0; 541 out->r = pow(out->r / 65535.0, gra->gamma / 65536.0) * 65535.0;
504 out->g=pow(out->g/65535.0,gra->gamma/65536.0)*65535.0; 542 out->g = pow(out->g / 65535.0, gra->gamma / 65536.0) * 65535.0;
505 out->b=pow(out->b/65535.0,gra->gamma/65536.0)*65535.0; 543 out->b = pow(out->b / 65535.0, gra->gamma / 65536.0) * 65535.0;
506 } 544 }
507} 545}
508 546
509/** 547/**
510 * FIXME 548 * FIXME
511 * @param <> 549 * @param <>
512 * @returns <> 550 * @returns <>
513 * @author Martin Schaller (04/2008) 551 * @author Martin Schaller (04/2008)
514*/ 552 */
515void graphics_gc_set_foreground(struct graphics_gc *gc, struct color *c) 553void graphics_gc_set_foreground(struct graphics_gc *gc, struct color *c)
516{ 554{
517 struct color cn; 555 struct color cn;
518 if (gc->gra->colormgmt) { 556 if (gc->gra->colormgmt)
557 {
519 graphics_convert_color(gc->gra, c, &cn); 558 graphics_convert_color(gc->gra, c, &cn);
520 c=&cn; 559 c = &cn;
521 } 560 }
522 gc->meth.gc_set_foreground(gc->priv, c); 561 gc->meth.gc_set_foreground(gc->priv, c);
523} 562}
524 563
525/** 564/**
526 * FIXME 565 * FIXME
527 * @param <> 566 * @param <>
528 * @returns <> 567 * @returns <>
529 * @author Martin Schaller (04/2008) 568 * @author Martin Schaller (04/2008)
530*/ 569 */
531void graphics_gc_set_background(struct graphics_gc *gc, struct color *c) 570void graphics_gc_set_background(struct graphics_gc *gc, struct color *c)
532{ 571{
533 struct color cn; 572 struct color cn;
534 if (gc->gra->colormgmt) { 573 if (gc->gra->colormgmt)
574 {
535 graphics_convert_color(gc->gra, c, &cn); 575 graphics_convert_color(gc->gra, c, &cn);
536 c=&cn; 576 c = &cn;
537 } 577 }
538 gc->meth.gc_set_background(gc->priv, c); 578 gc->meth.gc_set_background(gc->priv, c);
539} 579}
540 580
541
542/** 581/**
543 * FIXME 582 * FIXME
544 * @param <> 583 * @param <>
545 * @returns <> 584 * @returns <>
546 * @author Martin Schaller (04/2008) 585 * @author Martin Schaller (04/2008)
547*/ 586 */
548void graphics_gc_set_stipple(struct graphics_gc *gc, struct graphics_image *img) 587void graphics_gc_set_stipple(struct graphics_gc *gc, struct graphics_image *img)
549{ 588{
550 gc->meth.gc_set_stipple(gc->priv, img ? img->priv : NULL); 589 gc->meth.gc_set_stipple(gc->priv, img ? img->priv : NULL);
551} 590}
552 591
553
554/** 592/**
555 * FIXME 593 * FIXME
556 * @param <> 594 * @param <>
557 * @returns <> 595 * @returns <>
558 * @author Martin Schaller (04/2008) 596 * @author Martin Schaller (04/2008)
559*/ 597 */
560void graphics_gc_set_linewidth(struct graphics_gc *gc, int width) 598void graphics_gc_set_linewidth(struct graphics_gc *gc, int width)
561{ 599{
562 gc->meth.gc_set_linewidth(gc->priv, width); 600 gc->meth.gc_set_linewidth(gc->priv, width);
563} 601}
564 602
565/** 603/**
566 * FIXME 604 * FIXME
567 * @param <> 605 * @param <>
568 * @returns <> 606 * @returns <>
569 * @author Martin Schaller (04/2008) 607 * @author Martin Schaller (04/2008)
570*/ 608 */
571void graphics_gc_set_dashes(struct graphics_gc *gc, int width, int offset, unsigned char dash_list[], int n) 609void graphics_gc_set_dashes(struct graphics *gra, struct graphics_gc *gc, int width, int offset, int dash_list[], int n, int order)
572{ 610{
573 if (gc->meth.gc_set_dashes) 611 if (gc->meth.gc_set_dashes)
612 {
574 gc->meth.gc_set_dashes(gc->priv, width, offset, dash_list, n); 613 gc->meth.gc_set_dashes(gra->priv, gc->priv, width, offset, dash_list, order);
614 }
575} 615}
576 616
577/** 617/**
578 * Create a new image from file path scaled to w and h pixels 618 * Create a new image from file path scaled to w and h pixels
579 * @param gra the graphics instance 619 * @param gra the graphics instance
580 * @param path path of the image to load 620 * @param path path of the image to load
581 * @param w width to rescale to 621 * @param w width to rescale to
582 * @param h height to rescale to 622 * @param h height to rescale to
583 * @returns <> 623 * @returns <>
584 * @author Martin Schaller (04/2008) 624 * @author Martin Schaller (04/2008)
585*/ 625 */
586struct graphics_image * graphics_image_new_scaled(struct graphics *gra, char *path, int w, int h) 626struct graphics_image * graphics_image_new_scaled(struct graphics *gra, char *path, int w, int h)
587{ 627{
588 struct graphics_image *this_; 628 struct graphics_image *this_;
589 629
590 this_=g_new0(struct graphics_image,1); 630 this_=g_new0(struct graphics_image,1);
591 this_->height=h; 631 this_->height = h;
592 this_->width=w; 632 this_->width = w;
593 this_->priv=gra->meth.image_new(gra->priv, &this_->meth, path, &this_->width, &this_->height, &this_->hot, 0); 633 this_->priv = gra->meth.image_new(gra->priv, &this_->meth, path, &this_->width, &this_->height, &this_->hot, 0);
594 if (! this_->priv) { 634 if (!this_->priv)
635 {
595 g_free(this_); 636 g_free(this_);
596 this_=NULL; 637 this_ = NULL;
597 } 638 }
598 return this_; 639 return this_;
599} 640}
600 641
601/** 642/**
605 * @param w width to rescale to 646 * @param w width to rescale to
606 * @param h height to rescale to 647 * @param h height to rescale to
607 * @param rotate angle to rotate the image. Warning, graphics might only support 90 degree steps here 648 * @param rotate angle to rotate the image. Warning, graphics might only support 90 degree steps here
608 * @returns <> 649 * @returns <>
609 * @author Martin Schaller (04/2008) 650 * @author Martin Schaller (04/2008)
610*/ 651 */
611struct graphics_image * graphics_image_new_scaled_rotated(struct graphics *gra, char *path, int w, int h, int rotate) 652struct graphics_image * graphics_image_new_scaled_rotated(struct graphics *gra, char *path, int w, int h, int rotate)
612{ 653{
613 struct graphics_image *this_; 654 struct graphics_image *this_;
614 655
615 this_=g_new0(struct graphics_image,1); 656 this_=g_new0(struct graphics_image,1);
616 this_->height=h; 657 this_->height = h;
617 this_->width=w; 658 this_->width = w;
618 this_->priv=gra->meth.image_new(gra->priv, &this_->meth, path, &this_->width, &this_->height, &this_->hot, rotate); 659 this_->priv = gra->meth.image_new(gra->priv, &this_->meth, path, &this_->width, &this_->height, &this_->hot, rotate);
619 if (! this_->priv) { 660 if (!this_->priv)
661 {
620 g_free(this_); 662 g_free(this_);
621 this_=NULL; 663 this_ = NULL;
622 } 664 }
623 return this_; 665 return this_;
624} 666}
625 667
626/** 668/**
627 * Create a new image from file path 669 * Create a new image from file path
628 * @param gra the graphics instance 670 * @param gra the graphics instance
629 * @param path path of the image to load 671 * @param path path of the image to load
630 * @returns <> 672 * @returns <>
631 * @author Martin Schaller (04/2008) 673 * @author Martin Schaller (04/2008)
632*/ 674 */
633struct graphics_image * graphics_image_new(struct graphics *gra, char *path) 675struct graphics_image * graphics_image_new(struct graphics *gra, char *path)
634{ 676{
635 return graphics_image_new_scaled(gra, path, -1, -1); 677 return graphics_image_new_scaled(gra, path, -1, -1);
636} 678}
637 679
638/** 680/**
639 * FIXME 681 * FIXME
640 * @param <> 682 * @param <>
641 * @returns <> 683 * @returns <>
642 * @author Martin Schaller (04/2008) 684 * @author Martin Schaller (04/2008)
643*/ 685 */
644void graphics_image_free(struct graphics *gra, struct graphics_image *img) 686void graphics_image_free(struct graphics *gra, struct graphics_image *img)
645{ 687{
646 if (gra->meth.image_free) 688 if (gra->meth.image_free)
647 gra->meth.image_free(gra->priv, img->priv); 689 gra->meth.image_free(gra->priv, img->priv);
648 g_free(img); 690 g_free(img);
651/** 693/**
652 * FIXME 694 * FIXME
653 * @param <> 695 * @param <>
654 * @returns <> 696 * @returns <>
655 * @author Martin Schaller (04/2008) 697 * @author Martin Schaller (04/2008)
656*/ 698 */
657void graphics_draw_restore(struct graphics *this_, struct point *p, int w, int h) 699void graphics_draw_restore(struct graphics *this_, struct point *p, int w, int h)
658{ 700{
659 //dbg(0,"ooo enter ooo\n"); 701 ////DBG dbg(0,"ooo enter ooo\n");
660 702
661 this_->meth.draw_restore(this_->priv, p, w, h); 703 this_->meth.draw_restore(this_->priv, p, w, h);
662} 704}
663 705
664/** 706/**
665 * FIXME 707 * FIXME
666 * @param <> 708 * @param <>
667 * @returns <> 709 * @returns <>
668 * @author Martin Schaller (04/2008) 710 * @author Martin Schaller (04/2008)
669*/ 711 */
670void graphics_draw_mode(struct graphics *this_, enum draw_mode_num mode) 712void graphics_draw_mode(struct graphics *this_, enum draw_mode_num mode)
671{ 713{
672 //dbg(0,"ooo enter ooo\n"); 714 ////DBG dbg(0,"ooo enter ooo\n");
673 715
674 this_->meth.draw_mode(this_->priv, mode); 716 this_->meth.draw_mode(this_->priv, mode);
675} 717}
676 718
677/** 719/**
678 * FIXME 720 * FIXME
679 * @param <> 721 * @param <>
680 * @returns <> 722 * @returns <>
681 * @author Martin Schaller (04/2008) 723 * @author Martin Schaller (04/2008)
682*/ 724 */
683void graphics_draw_lines(struct graphics *this_, struct graphics_gc *gc, struct point *p, int count) 725void graphics_draw_lines(struct graphics *this_, struct graphics_gc *gc, struct point *p, int count)
684{ 726{
685 this_->meth.draw_lines(this_->priv, gc->priv, p, count); 727 this_->meth.draw_lines(this_->priv, gc->priv, p, count);
686} 728}
687 729
693/** 735/**
694 * FIXME 736 * FIXME
695 * @param <> 737 * @param <>
696 * @returns <> 738 * @returns <>
697 * @author Martin Schaller (04/2008) 739 * @author Martin Schaller (04/2008)
698*/ 740 */
699void graphics_draw_circle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int r) 741void graphics_draw_circle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int r)
700{ 742{
701 struct point *pnt=g_alloca(sizeof(struct point)*(r*4+64)); 743 struct point *pnt = g_alloca(sizeof(struct point) * (r * 4 + 64));
702 int i=0; 744 int i = 0;
703 745
704 if(this_->meth.draw_circle) 746 if (this_->meth.draw_circle)
705 this_->meth.draw_circle(this_->priv, gc->priv, p, r); 747 this_->meth.draw_circle(this_->priv, gc->priv, p, r);
706 else 748 else
707 { 749 {
708 draw_circle(p, r, 0, -1, 1026, pnt, &i, 1); 750 draw_circle(p, r, 0, -1, 1026, pnt, &i, 1);
709 pnt[i] = pnt[0]; 751 pnt[i] = pnt[0];
715/** 757/**
716 * FIXME 758 * FIXME
717 * @param <> 759 * @param <>
718 * @returns <> 760 * @returns <>
719 * @author Martin Schaller (04/2008) 761 * @author Martin Schaller (04/2008)
720*/ 762 */
721void graphics_draw_rectangle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int w, int h) 763void graphics_draw_rectangle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int w, int h)
722{ 764{
723 this_->meth.draw_rectangle(this_->priv, gc->priv, p, w, h); 765 this_->meth.draw_rectangle(this_->priv, gc->priv, p, w, h);
724} 766}
725 767
726void graphics_draw_rectangle_rounded(struct graphics *this_, struct graphics_gc *gc, struct point *plu, int w, int h, int r, int fill) 768void graphics_draw_rectangle_rounded(struct graphics *this_, struct graphics_gc *gc, struct point *plu, int w, int h, int r, int fill)
727{ 769{
728 struct point *p=g_alloca(sizeof(struct point)*(r*4+32)); 770 struct point *p = g_alloca(sizeof(struct point) * (r * 4 + 32));
729 struct point pi0={plu->x+r,plu->y+r}; 771 struct point pi0 =
730 struct point pi1={plu->x+w-r,plu->y+r}; 772 { plu->x + r, plu->y + r };
731 struct point pi2={plu->x+w-r,plu->y+h-r}; 773 struct point pi1 =
732 struct point pi3={plu->x+r,plu->y+h-r}; 774 { plu->x + w - r, plu->y + r };
775 struct point pi2 =
776 { plu->x + w - r, plu->y + h - r };
777 struct point pi3 =
778 { plu->x + r, plu->y + h - r };
733 int i=0; 779 int i = 0;
734 780
735 draw_circle(&pi2, r*2, 0, -1, 258, p, &i, 1); 781 draw_circle(&pi2, r * 2, 0, -1, 258, p, &i, 1);
736 draw_circle(&pi1, r*2, 0, 255, 258, p, &i, 1); 782 draw_circle(&pi1, r * 2, 0, 255, 258, p, &i, 1);
737 draw_circle(&pi0, r*2, 0, 511, 258, p, &i, 1); 783 draw_circle(&pi0, r * 2, 0, 511, 258, p, &i, 1);
738 draw_circle(&pi3, r*2, 0, 767, 258, p, &i, 1); 784 draw_circle(&pi3, r * 2, 0, 767, 258, p, &i, 1);
739 p[i]=p[0]; 785 p[i] = p[0];
740 i++; 786 i++;
741 if (fill) 787 if (fill)
742 this_->meth.draw_polygon(this_->priv, gc->priv, p, i); 788 this_->meth.draw_polygon(this_->priv, gc->priv, p, i);
743 else 789 else
744 this_->meth.draw_lines(this_->priv, gc->priv, p, i); 790 this_->meth.draw_lines(this_->priv, gc->priv, p, i);
745} 791}
746 792
747
748/** 793/**
749 * FIXME 794 * FIXME
750 * @param <> 795 * @param <>
751 * @returns <> 796 * @returns <>
752 * @author Martin Schaller (04/2008) 797 * @author Martin Schaller (04/2008)
753*/ 798 */
754void graphics_draw_text(struct graphics *this_, struct graphics_gc *gc1, struct graphics_gc *gc2, struct graphics_font *font, char *text, struct point *p, int dx, int dy) 799void graphics_draw_text(struct graphics *this_, struct graphics_gc *gc1, struct graphics_gc *gc2, struct graphics_font *font, char *text, struct point *p, int dx, int dy)
755{ 800{
756 this_->meth.draw_text(this_->priv, gc1->priv, gc2 ? gc2->priv : NULL, font->priv, text, p, dx, dy); 801 this_->meth.draw_text(this_->priv, gc1->priv, gc2 ? gc2->priv : NULL, font->priv, text, p, dx, dy);
757} 802}
758 803
759
760/** 804/**
761 * FIXME 805 * FIXME
762 * @param <> 806 * @param <>
763 * @returns <> 807 * @returns <>
764 * @author Martin Schaller (04/2008) 808 * @author Martin Schaller (04/2008)
765*/ 809 */
766void graphics_get_text_bbox(struct graphics *this_, struct graphics_font *font, char *text, int dx, int dy, struct point *ret, int estimate) 810void graphics_get_text_bbox(struct graphics *this_, struct graphics_font *font, char *text, int dx, int dy, struct point *ret, int estimate)
767{ 811{
768 this_->meth.get_text_bbox(this_->priv, font->priv, text, dx, dy, ret, estimate); 812 this_->meth.get_text_bbox(this_->priv, font->priv, text, dx, dy, ret, estimate);
769} 813}
770 814
771/** 815/**
772 * FIXME 816 * FIXME
773 * @param <> 817 * @param <>
774 * @returns <> 818 * @returns <>
775 * @author Martin Schaller (04/2008) 819 * @author Martin Schaller (04/2008)
776*/ 820 */
777void graphics_overlay_disable(struct graphics *this_, int disable) 821void graphics_overlay_disable(struct graphics *this_, int disable)
778{ 822{
779 if (this_->meth.overlay_disable) 823 if (this_->meth.overlay_disable)
780 this_->meth.overlay_disable(this_->priv, disable); 824 this_->meth.overlay_disable(this_->priv, disable);
781} 825}
783/** 827/**
784 * FIXME 828 * FIXME
785 * @param <> 829 * @param <>
786 * @returns <> 830 * @returns <>
787 * @author Martin Schaller (04/2008) 831 * @author Martin Schaller (04/2008)
788*/ 832 */
789void graphics_draw_image(struct graphics *this_, struct graphics_gc *gc, struct point *p, struct graphics_image *img) 833void graphics_draw_image(struct graphics *this_, struct graphics_gc *gc, struct point *p, struct graphics_image *img)
790{ 834{
791 this_->meth.draw_image(this_->priv, gc->priv, p, img->priv); 835 this_->meth.draw_image(this_->priv, gc->priv, p, img->priv);
792} 836}
793
794 837
795/** 838/**
796 * 839 *
797 * 840 *
798 * @author Zoff (2011) 841 * @author Zoff (2011)
799*/ 842 */
800void graphics_draw_bigmap(struct graphics *this_, struct graphics_gc *gc, int yaw, int order, float clat, float clng, int x, int y, int scx, int scy, int px, int py, int valid) 843void graphics_draw_bigmap(struct graphics *this_, struct graphics_gc *gc, int yaw, int order, float clat, float clng, int x, int y, int scx, int scy, int px, int py, int valid)
801{ 844{
802 this_->meth.draw_bigmap(this_->priv, gc->priv, yaw, order, clat, clng, x, y, scx, scy, px, py, valid); 845 this_->meth.draw_bigmap(this_->priv, gc->priv, yaw, order, clat, clng, x, y, scx, scy, px, py, valid);
803} 846}
804 847
805void graphics_send_osd_values(struct graphics *this_, struct graphics_gc *gc, char *id, char *text1, char *text2, char *text3, int i1, int i2, int i3, int i4, float f1, float f2, float f3) 848void graphics_send_osd_values(struct graphics *this_, struct graphics_gc *gc, char *id, char *text1, char *text2, char *text3, int i1, int i2, int i3, int i4, float f1, float f2, float f3)
806{ 849{
807 this_->meth.send_osd_values(this_->priv, gc->priv, id, text1, text2, text3, i1, i2, i3, i4, f1, f2, f3); 850 this_->meth.send_osd_values(this_->priv, gc->priv, id, text1, text2, text3, i1, i2, i3, i4, f1, f2, f3);
808} 851}
809
810 852
811//############################################################################################################## 853//##############################################################################################################
812//# Description: 854//# Description:
813//# Comment: 855//# Comment:
814//# Authors: Martin Schaller (04/2008) 856//# Authors: Martin Schaller (04/2008)
815//############################################################################################################## 857//##############################################################################################################
816int
817graphics_draw_drag(struct graphics *this_, struct point *p) 858int graphics_draw_drag(struct graphics *this_, struct point *p)
818{ 859{
819 //dbg(0,"ooo enter ooo\n"); 860 ////DBG dbg(0,"ooo enter ooo\n");
820 861
821 if (!this_->meth.draw_drag) 862 if (!this_->meth.draw_drag)
822 { 863 {
823 return 0; 864 return 0;
824 } 865 }
825 //dbg(0,"draw DRAG start ...\n"); 866 ////DBG dbg(0,"draw DRAG start ...\n");
826 this_->meth.draw_drag(this_->priv, p); 867 this_->meth.draw_drag(this_->priv, p);
827 //dbg(0,"draw DRAG end ...\n"); 868 ////DBG dbg(0,"draw DRAG end ...\n");
828 return 1; 869 return 1;
829} 870}
830 871
831void
832graphics_background_gc(struct graphics *this_, struct graphics_gc *gc) 872void graphics_background_gc(struct graphics *this_, struct graphics_gc *gc)
833{ 873{
834 //dbg(0,"ooo enter ooo\n"); 874 ////DBG dbg(0,"ooo enter ooo\n");
835 875
836 this_->meth.background_gc(this_->priv, gc ? gc->priv : NULL); 876 this_->meth.background_gc(this_->priv, gc ? gc->priv : NULL);
837} 877}
838 878
839#include "attr.h" 879#include "attr.h"
840#include "popup.h" 880#include "popup.h"
841#include <stdio.h> 881#include <stdio.h>
842
843 882
844#if 0 883#if 0
845//############################################################################################################## 884//##############################################################################################################
846//# Description: 885//# Description:
847//# Comment: 886//# Comment:
871 struct popup_item *curr_item,*last=NULL; 910 struct popup_item *curr_item,*last=NULL;
872 item=list->data; 911 item=list->data;
873 mr=map_rect_new(item->map, NULL, NULL, 0); 912 mr=map_rect_new(item->map, NULL, NULL, 0);
874 printf("id hi=0x%x lo=0x%x\n", item->id_hi, item->id_lo); 913 printf("id hi=0x%x lo=0x%x\n", item->id_hi, item->id_lo);
875 item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo); 914 item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
876 if (item) { 915 if (item)
916 {
877 if (item_attr_get(item, attr_name, &attr)) { 917 if (item_attr_get(item, attr_name, &attr))
918 {
878 curr_item=popup_item_new_text(popup,attr.u.str,1); 919 curr_item=popup_item_new_text(popup,attr.u.str,1);
879 if (item_attr_get(item, attr_info_html, &attr)) { 920 if (item_attr_get(item, attr_info_html, &attr))
921 {
880 popup_item_new_func(&last,"HTML Info",1, popup_view_html, g_strdup(attr.u.str)); 922 popup_item_new_func(&last,"HTML Info",1, popup_view_html, g_strdup(attr.u.str));
881 } 923 }
882 if (item_attr_get(item, attr_price_html, &attr)) { 924 if (item_attr_get(item, attr_price_html, &attr))
925 {
883 popup_item_new_func(&last,"HTML Preis",2, popup_view_html, g_strdup(attr.u.str)); 926 popup_item_new_func(&last,"HTML Preis",2, popup_view_html, g_strdup(attr.u.str));
884 } 927 }
885 curr_item->submenu=last; 928 curr_item->submenu=last;
886 } 929 }
887 } 930 }
888 map_rect_destroy(mr); 931 map_rect_destroy(mr);
889} 932}
890#endif 933#endif
891 934
892
893/** 935/**
894 * FIXME 936 * FIXME
895 * @param <> 937 * @param <>
896 * @returns <> 938 * @returns <>
897 * @author Martin Schaller (04/2008) 939 * @author Martin Schaller (04/2008)
898*/ 940 */
899static void xdisplay_free(struct displaylist *dl) 941static void xdisplay_free(struct displaylist *dl)
900{ 942{
901 int i; 943 int i;
902 for (i = 0 ; i < HASH_SIZE ; i++) { 944 for (i = 0; i < HASH_SIZE_GRAPHICS_; i++)
945 {
903 struct displayitem *di=dl->hash_entries[i].di; 946 struct displayitem *di = dl->hash_entries[i].di;
904 while (di) { 947 while (di)
948 {
905 struct displayitem *next=di->next; 949 struct displayitem *next = di->next;
906 g_free(di); 950 g_free(di);
907 di=next; 951 di = next;
908 } 952 }
909 dl->hash_entries[i].di=NULL; 953 dl->hash_entries[i].di = NULL;
910 } 954 }
911} 955}
912 956
913/** 957/**
914 * FIXME 958 * FIXME
915 * @param <> 959 * @param <>
916 * @returns <> 960 * @returns <>
917 * @author Martin Schaller (04/2008) 961 * @author Martin Schaller (04/2008)
918*/ 962 */
919static void display_add(struct hash_entry *entry, struct item *item, int count, struct coord *c, char **label, int label_count) 963static void display_add(struct hash_entry *entry, struct item *item, int count, struct coord *c, char **label, int label_count)
920{ 964{
921 struct displayitem *di; 965 struct displayitem *di;
922 int len,i; 966 int len, i;
923 char *p; 967 char *p;
924 968
925 len=sizeof(*di)+count*sizeof(*c); 969 len = sizeof(*di) + count * sizeof(*c);
926 if (label && label_count) { 970 if (label && label_count)
971 {
927 for (i = 0 ; i < label_count ; i++) { 972 for (i = 0; i < label_count; i++)
973 {
928 if (label[i]) 974 if (label[i])
929 len+=strlen(label[i])+1; 975 len += strlen(label[i]) + 1;
930 else 976 else
931 len++; 977 len++;
932 } 978 }
933 } 979 }
934 p=g_malloc(len); 980 p = g_malloc(len);
935 981
936 di=(struct displayitem *)p; 982 di = (struct displayitem *) p;
937 p+=sizeof(*di)+count*sizeof(*c); 983 p += sizeof(*di) + count * sizeof(*c);
938 di->item=*item; 984 di->item = *item;
939 if (label && label_count) { 985 if (label && label_count)
986 {
940 di->label=p; 987 di->label = p;
941 for (i = 0 ; i < label_count ; i++) { 988 for (i = 0; i < label_count; i++)
989 {
942 if (label[i]) { 990 if (label[i])
991 {
943 strcpy(p, label[i]); 992 strcpy(p, label[i]);
944 p+=strlen(label[i])+1; 993 p += strlen(label[i]) + 1;
994 }
945 } else 995 else
946 *p++='\0'; 996 *p++ = '\0';
997 }
947 } 998 }
948 } else 999 else
1000 {
949 di->label=NULL; 1001 di->label = NULL;
1002 }
950 di->count=count; 1003 di->count = count;
951 memcpy(di->c, c, count*sizeof(*c)); 1004 memcpy(di->c, c, count * sizeof(*c));
952 di->next=entry->di; 1005 di->next = entry->di;
953 entry->di=di; 1006 entry->di = di;
954} 1007}
955 1008
956
957/** 1009/**
958 * FIXME 1010 * FIXME
959 * @param <> 1011 * @param <>
960 * @returns <> 1012 * @returns <>
961 * @author Martin Schaller (04/2008) 1013 * @author Martin Schaller (04/2008)
962*/ 1014 */
963static void label_line(struct graphics *gra, struct graphics_gc *fg, struct graphics_gc *bg, struct graphics_font *font, struct point *p, int count, char *label) 1015static void label_line(struct graphics *gra, struct graphics_gc *fg, struct graphics_gc *bg, struct graphics_font *font, struct point *p, int count, char *label)
964{ 1016{
965 int i,x,y,tl,tlm,th,thm,tlsq,l; 1017 int i, x, y, tl, tlm, th, thm, tlsq, l;
966 float lsq; 1018 float lsq;
967 double dx,dy; 1019 double dx, dy;
968 struct point p_t; 1020 struct point p_t;
969 struct point pb[5]; 1021 struct point pb[5];
970 1022
971 if (gra->meth.get_text_bbox) { 1023 if (gra->meth.get_text_bbox)
1024 {
972 gra->meth.get_text_bbox(gra->priv, font->priv, label, 0x10000, 0x0, pb, 1); 1025 gra->meth.get_text_bbox(gra->priv, font->priv, label, 0x10000, 0x0, pb, 1);
973 tl=(pb[2].x-pb[0].x); 1026 tl = (pb[2].x - pb[0].x);
974 th=(pb[0].y-pb[1].y); 1027 th = (pb[0].y - pb[1].y);
975 } else { 1028 }
1029 else
1030 {
976 tl=strlen(label)*4; 1031 tl = strlen(label) * 4;
977 th=8; 1032 th = 8;
978 } 1033 }
979 tlm=tl*32; 1034 tlm = tl * 32;
980 thm=th*36; 1035 thm = th * 36;
981 tlsq = tlm*tlm; 1036 tlsq = tlm * tlm;
982 for (i = 0 ; i < count-1 ; i++) { 1037 for (i = 0; i < count - 1; i++)
1038 {
983 dx=p[i+1].x-p[i].x; 1039 dx = p[i + 1].x - p[i].x;
984 dx*=32; 1040 dx *= 32;
985 dy=p[i+1].y-p[i].y; 1041 dy = p[i + 1].y - p[i].y;
986 dy*=32; 1042 dy *= 32;
987 lsq = dx*dx+dy*dy; 1043 lsq = dx * dx + dy * dy;
988 if (lsq > tlsq) { 1044 if (lsq > tlsq)
1045 {
989 l=(int)sqrtf(lsq); 1046 l = (int) sqrtf(lsq);
990 x=p[i].x; 1047 x = p[i].x;
991 y=p[i].y; 1048 y = p[i].y;
992 if (dx < 0) { 1049 if (dx < 0)
1050 {
993 dx=-dx; 1051 dx = -dx;
994 dy=-dy; 1052 dy = -dy;
995 x=p[i+1].x; 1053 x = p[i + 1].x;
996 y=p[i+1].y; 1054 y = p[i + 1].y;
997 } 1055 }
998 x+=(l-tlm)*dx/l/64; 1056 x += (l - tlm) * dx / l / 64;
999 y+=(l-tlm)*dy/l/64; 1057 y += (l - tlm) * dy / l / 64;
1000 x-=dy*thm/l/64; 1058 x -= dy * thm / l / 64;
1001 y+=dx*thm/l/64; 1059 y += dx * thm / l / 64;
1002 p_t.x=x; 1060 p_t.x = x;
1003 p_t.y=y; 1061 p_t.y = y;
1004#if 0 1062#if 0
1005 dbg(0,"display_text: '%s', %d, %d, %d, %d %d\n", label, x, y, dx*0x10000/l, dy*0x10000/l, l); 1063 //DBG dbg(0,"display_text: '%s', %d, %d, %d, %d %d\n", label, x, y, dx*0x10000/l, dy*0x10000/l, l);
1006#endif 1064#endif
1007 if (x < gra->r.rl.x && x + tl > gra->r.lu.x && y + tl > gra->r.lu.y && y - tl < gra->r.rl.y) 1065 if (x < gra->r.rl.x && x + tl > gra->r.lu.x && y + tl > gra->r.lu.y && y - tl < gra->r.rl.y)
1008 gra->meth.draw_text(gra->priv, fg->priv, bg?bg->priv:NULL, font->priv, label, &p_t, dx*0x10000/l, dy*0x10000/l); 1066 gra->meth.draw_text(gra->priv, fg->priv, bg ? bg->priv : NULL, font->priv, label, &p_t, dx * 0x10000 / l, dy * 0x10000 / l);
1009 } 1067 }
1010 } 1068 }
1011} 1069}
1012 1070
1013static void display_draw_arrow(struct point *p, int dx, int dy, int l, struct graphics_gc *gc, struct graphics *gra) 1071static void display_draw_arrow(struct point *p, int dx, int dy, int l, struct graphics_gc *gc, struct graphics *gra)
1014{ 1072{
1015 struct point pnt[3]; 1073 struct point pnt[3];
1016 pnt[0]=pnt[1]=pnt[2]=*p; 1074 pnt[0] = pnt[1] = pnt[2] = *p;
1017 pnt[0].x+=-dx*l/65536+dy*l/65536; 1075 pnt[0].x += -dx * l / 65536 + dy * l / 65536;
1018 pnt[0].y+=-dy*l/65536-dx*l/65536; 1076 pnt[0].y += -dy * l / 65536 - dx * l / 65536;
1019 pnt[2].x+=-dx*l/65536-dy*l/65536; 1077 pnt[2].x += -dx * l / 65536 - dy * l / 65536;
1020 pnt[2].y+=-dy*l/65536+dx*l/65536; 1078 pnt[2].y += -dy * l / 65536 + dx * l / 65536;
1021 gra->meth.draw_lines(gra->priv, gc->priv, pnt, 3); 1079 gra->meth.draw_lines(gra->priv, gc->priv, pnt, 3);
1022} 1080}
1023 1081
1024static void display_draw_arrows(struct graphics *gra, struct graphics_gc *gc, struct point *pnt, int count) 1082static void display_draw_arrows(struct graphics *gra, struct graphics_gc *gc, struct point *pnt, int count)
1025{ 1083{
1026 int i,dx,dy,l; 1084 int i, dx, dy, l;
1027 struct point p; 1085 struct point p;
1028 for (i = 0 ; i < count-1 ; i++) { 1086 for (i = 0; i < count - 1; i++)
1087 {
1029 dx=pnt[i+1].x-pnt[i].x; 1088 dx = pnt[i + 1].x - pnt[i].x;
1030 dy=pnt[i+1].y-pnt[i].y; 1089 dy = pnt[i + 1].y - pnt[i].y;
1031 l=sqrt(dx*dx+dy*dy); 1090 l = sqrt(dx * dx + dy * dy);
1032 if (l) { 1091 if (l)
1092 {
1033 dx=dx*65536/l; 1093 dx = dx * 65536 / l;
1034 dy=dy*65536/l; 1094 dy = dy * 65536 / l;
1035 p=pnt[i]; 1095 p = pnt[i];
1036 p.x+=dx*15/65536; 1096 p.x += dx * 15 / 65536;
1037 p.y+=dy*15/65536; 1097 p.y += dy * 15 / 65536;
1038 display_draw_arrow(&p, dx, dy, 10, gc, gra); 1098 display_draw_arrow(&p, dx, dy, 10, gc, gra);
1039 p=pnt[i+1]; 1099 p = pnt[i + 1];
1040 p.x-=dx*15/65536; 1100 p.x -= dx * 15 / 65536;
1041 p.y-=dy*15/65536; 1101 p.y -= dy * 15 / 65536;
1042 display_draw_arrow(&p, dx, dy, 10, gc, gra); 1102 display_draw_arrow(&p, dx, dy, 10, gc, gra);
1043 } 1103 }
1044 } 1104 }
1045} 1105}
1046 1106
1047static int
1048intersection(struct point * a1, int adx, int ady, struct point * b1, int bdx, int bdy, 1107static int intersection(struct point * a1, int adx, int ady, struct point * b1, int bdx, int bdy, struct point * res)
1049 struct point * res)
1050{ 1108{
1051 int n, a, b; 1109 int n, a, b;
1052 n = bdy * adx - bdx * ady; 1110 n = bdy * adx - bdx * ady;
1053 a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x); 1111 a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
1054 b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x); 1112 b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
1055 if (n < 0) { 1113 if (n < 0)
1114 {
1056 n = -n; 1115 n = -n;
1057 a = -a; 1116 a = -a;
1058 b = -b; 1117 b = -b;
1059 } 1118 }
1060#if 0 1119#if 0
1061 if (a < 0 || b < 0) 1120 if (a < 0 || b < 0)
1062 return 0; 1121 return 0;
1063 if (a > n || b > n) 1122 if (a > n || b > n)
1064 return 0; 1123 return 0;
1065#endif 1124#endif
1066 if (n == 0) 1125 if (n == 0)
1067 return 0; 1126 return 0;
1068 res->x = a1->x + a * adx / n; 1127 res->x = a1->x + a * adx / n;
1069 res->y = a1->y + a * ady / n; 1128 res->y = a1->y + a * ady / n;
1070 return 1; 1129 return 1;
1071} 1130}
1072 1131
1073struct circle { 1132struct circle
1133{
1074 short x,y,fowler; 1134 short x, y, fowler;
1075} circle64[]={ 1135} circle64[] =
1136{
1076{0,128,0}, 1137{ 0, 128, 0 },
1077{13,127,13}, 1138{ 13, 127, 13 },
1078{25,126,25}, 1139{ 25, 126, 25 },
1079{37,122,38}, 1140{ 37, 122, 38 },
1080{49,118,53}, 1141{ 49, 118, 53 },
1081{60,113,67}, 1142{ 60, 113, 67 },
1082{71,106,85}, 1143{ 71, 106, 85 },
1083{81,99,104}, 1144{ 81, 99, 104 },
1084{91,91,128}, 1145{ 91, 91, 128 },
1085{99,81,152}, 1146{ 99, 81, 152 },
1086{106,71,171}, 1147{ 106, 71, 171 },
1087{113,60,189}, 1148{ 113, 60, 189 },
1088{118,49,203}, 1149{ 118, 49, 203 },
1089{122,37,218}, 1150{ 122, 37, 218 },
1090{126,25,231}, 1151{ 126, 25, 231 },
1091{127,13,243}, 1152{ 127, 13, 243 },
1092{128,0,256}, 1153{ 128, 0, 256 },
1093{127,-13,269}, 1154{ 127, -13, 269 },
1094{126,-25,281}, 1155{ 126, -25, 281 },
1095{122,-37,294}, 1156{ 122, -37, 294 },
1096{118,-49,309}, 1157{ 118, -49, 309 },
1097{113,-60,323}, 1158{ 113, -60, 323 },
1098{106,-71,341}, 1159{ 106, -71, 341 },
1099{99,-81,360}, 1160{ 99, -81, 360 },
1100{91,-91,384}, 1161{ 91, -91, 384 },
1101{81,-99,408}, 1162{ 81, -99, 408 },
1102{71,-106,427}, 1163{ 71, -106, 427 },
1103{60,-113,445}, 1164{ 60, -113, 445 },
1104{49,-118,459}, 1165{ 49, -118, 459 },
1105{37,-122,474}, 1166{ 37, -122, 474 },
1106{25,-126,487}, 1167{ 25, -126, 487 },
1107{13,-127,499}, 1168{ 13, -127, 499 },
1108{0,-128,512}, 1169{ 0, -128, 512 },
1109{-13,-127,525}, 1170{ -13, -127, 525 },
1110{-25,-126,537}, 1171{ -25, -126, 537 },
1111{-37,-122,550}, 1172{ -37, -122, 550 },
1112{-49,-118,565}, 1173{ -49, -118, 565 },
1113{-60,-113,579}, 1174{ -60, -113, 579 },
1114{-71,-106,597}, 1175{ -71, -106, 597 },
1115{-81,-99,616}, 1176{ -81, -99, 616 },
1116{-91,-91,640}, 1177{ -91, -91, 640 },
1117{-99,-81,664}, 1178{ -99, -81, 664 },
1118{-106,-71,683}, 1179{ -106, -71, 683 },
1119{-113,-60,701}, 1180{ -113, -60, 701 },
1120{-118,-49,715}, 1181{ -118, -49, 715 },
1121{-122,-37,730}, 1182{ -122, -37, 730 },
1122{-126,-25,743}, 1183{ -126, -25, 743 },
1123{-127,-13,755}, 1184{ -127, -13, 755 },
1124{-128,0,768}, 1185{ -128, 0, 768 },
1125{-127,13,781}, 1186{ -127, 13, 781 },
1126{-126,25,793}, 1187{ -126, 25, 793 },
1127{-122,37,806}, 1188{ -122, 37, 806 },
1128{-118,49,821}, 1189{ -118, 49, 821 },
1129{-113,60,835}, 1190{ -113, 60, 835 },
1130{-106,71,853}, 1191{ -106, 71, 853 },
1131{-99,81,872}, 1192{ -99, 81, 872 },
1132{-91,91,896}, 1193{ -91, 91, 896 },
1133{-81,99,920}, 1194{ -81, 99, 920 },
1134{-71,106,939}, 1195{ -71, 106, 939 },
1135{-60,113,957}, 1196{ -60, 113, 957 },
1136{-49,118,971}, 1197{ -49, 118, 971 },
1137{-37,122,986}, 1198{ -37, 122, 986 },
1138{-25,126,999}, 1199{ -25, 126, 999 },
1139{-13,127,1011}, 1200{ -13, 127, 1011 }, };
1140};
1141 1201
1142static void
1143draw_circle(struct point *pnt, int diameter, int scale, int start, int len, struct point *res, int *pos, int dir) 1202static void draw_circle(struct point *pnt, int diameter, int scale, int start, int len, struct point *res, int *pos, int dir)
1144{ 1203{
1145 struct circle *c; 1204 struct circle *c;
1146 1205
1147#if 0 1206#if 0
1148 dbg(0,"diameter=%d start=%d len=%d pos=%d dir=%d\n", diameter, start, len, *pos, dir); 1207 //DBG dbg(0,"diameter=%d start=%d len=%d pos=%d dir=%d\n", diameter, start, len, *pos, dir);
1149#endif 1208#endif
1150 int count=64; 1209 int count = 64;
1151 int end=start+len; 1210 int end = start + len;
1152 int i,step; 1211 int i, step;
1153 c=circle64; 1212 c = circle64;
1154 if (diameter > 128) 1213 if (diameter > 128)
1155 step=1; 1214 step = 1;
1156 else if (diameter > 64) 1215 else if (diameter > 64)
1157 step=2; 1216 step = 2;
1158 else if (diameter > 24) 1217 else if (diameter > 24)
1159 step=4; 1218 step = 4;
1160 else if (diameter > 8) 1219 else if (diameter > 8)
1161 step=8; 1220 step = 8;
1162 else 1221 else
1163 step=16; 1222 step = 16;
1164 if (len > 0) { 1223 if (len > 0)
1224 {
1165 while (start < 0) { 1225 while (start < 0)
1226 {
1166 start+=1024; 1227 start += 1024;
1167 end+=1024; 1228 end += 1024;
1168 } 1229 }
1169 while (end > 0) { 1230 while (end > 0)
1231 {
1170 i=0; 1232 i = 0;
1171 while (i < count && c[i].fowler <= start) 1233 while (i < count && c[i].fowler <= start)
1234 {
1172 i+=step; 1235 i += step;
1236 }
1173 while (i < count && c[i].fowler < end) { 1237 while (i < count && c[i].fowler < end)
1238 {
1174 if (1< *pos || 0<dir) { 1239 if (1 < *pos || 0 < dir)
1240 {
1175 res[*pos].x=pnt->x+((c[i].x*diameter+128)>>8); 1241 res[*pos].x = pnt->x + ((c[i].x * diameter + 128) >> 8);
1176 res[*pos].y=pnt->y+((c[i].y*diameter+128)>>8); 1242 res[*pos].y = pnt->y + ((c[i].y * diameter + 128) >> 8);
1177 (*pos)+=dir; 1243 (*pos) += dir;
1178 } 1244 }
1179 i+=step; 1245 i += step;
1180 } 1246 }
1181 end-=1024; 1247 end -= 1024;
1182 start-=1024; 1248 start -= 1024;
1249 }
1183 } 1250 }
1184 } else { 1251 else
1252 {
1185 while (start > 1024) { 1253 while (start > 1024)
1254 {
1186 start-=1024; 1255 start -= 1024;
1187 end-=1024; 1256 end -= 1024;
1188 } 1257 }
1189 while (end < 1024) { 1258 while (end < 1024)
1259 {
1190 i=count-1; 1260 i = count - 1;
1191 while (i >= 0 && c[i].fowler >= start) 1261 while (i >= 0 && c[i].fowler >= start)
1192 i-=step; 1262 i -= step;
1193 while (i >= 0 && c[i].fowler > end) { 1263 while (i >= 0 && c[i].fowler > end)
1264 {
1194 if (1< *pos || 0<dir) { 1265 if (1 < *pos || 0 < dir)
1266 {
1195 res[*pos].x=pnt->x+((c[i].x*diameter+128)>>8); 1267 res[*pos].x = pnt->x + ((c[i].x * diameter + 128) >> 8);
1196 res[*pos].y=pnt->y+((c[i].y*diameter+128)>>8); 1268 res[*pos].y = pnt->y + ((c[i].y * diameter + 128) >> 8);
1197 (*pos)+=dir; 1269 (*pos) += dir;
1198 } 1270 }
1199 i-=step; 1271 i -= step;
1200 } 1272 }
1201 start+=1024; 1273 start += 1024;
1202 end+=1024; 1274 end += 1024;
1203 }
1204 } 1275 }
1276 }
1205} 1277}
1206 1278
1207
1208static int
1209fowler(int dy, int dx) 1279static int fowler(int dy, int dx)
1210{ 1280{
1211 int adx, ady; /* Absolute Values of Dx and Dy */ 1281 int adx, ady; /* Absolute Values of Dx and Dy */
1212 int code; /* Angular Region Classification Code */ 1282 int code; /* Angular Region Classification Code */
1213 1283
1214 adx = (dx < 0) ? -dx : dx; /* Compute the absolute values. */ 1284 adx = (dx < 0) ? -dx : dx; /* Compute the absolute values. */
1215 ady = (dy < 0) ? -dy : dy; 1285 ady = (dy < 0) ? -dy : dy;
1216 1286
1217 code = (adx < ady) ? 1 : 0; 1287 code = (adx < ady) ? 1 : 0;
1218 if (dx < 0) 1288 if (dx < 0)
1219 code += 2; 1289 code += 2;
1220 if (dy < 0) 1290 if (dy < 0)
1221 code += 4; 1291 code += 4;
1222 1292
1223 switch (code) { 1293 switch (code)
1294 {
1224 case 0: 1295 case 0:
1225 return (dx == 0) ? 0 : 128*ady / adx; /* [ 0, 45] */ 1296 return (dx == 0) ? 0 : 128 * ady / adx; /* [ 0, 45] */
1226 case 1: 1297 case 1:
1227 return (256 - (128*adx / ady)); /* ( 45, 90] */ 1298 return (256 - (128 * adx / ady)); /* ( 45, 90] */
1228 case 3: 1299 case 3:
1229 return (256 + (128*adx / ady)); /* ( 90,135) */ 1300 return (256 + (128 * adx / ady)); /* ( 90,135) */
1230 case 2: 1301 case 2:
1231 return (512 - (128*ady / adx)); /* [135,180] */ 1302 return (512 - (128 * ady / adx)); /* [135,180] */
1232 case 6: 1303 case 6:
1233 return (512 + (128*ady / adx)); /* (180,225] */ 1304 return (512 + (128 * ady / adx)); /* (180,225] */
1234 case 7: 1305 case 7:
1235 return (768 - (128*adx / ady)); /* (225,270) */ 1306 return (768 - (128 * adx / ady)); /* (225,270) */
1236 case 5: 1307 case 5:
1237 return (768 + (128*adx / ady)); /* [270,315) */ 1308 return (768 + (128 * adx / ady)); /* [270,315) */
1238 case 4: 1309 case 4:
1239 return (1024 - (128*ady / adx));/* [315,360) */ 1310 return (1024 - (128 * ady / adx));/* [315,360) */
1240 } 1311 }
1241 return 0; 1312 return 0;
1242} 1313}
1243static int 1314
1244int_sqrt(unsigned int n) 1315static int int_sqrt(unsigned int n)
1245{ 1316{
1246 unsigned int h, p= 0, q= 1, r= n; 1317 unsigned int h, p = 0, q = 1, r = n;
1247 1318
1248 /* avoid q rollover */ 1319 /* avoid q rollover */
1249 if(n >= (1<<(sizeof(n)*8-2))) { 1320 if (n >= (1 << (sizeof(n) * 8 - 2)))
1321 {
1250 q = 1<<(sizeof(n)*8-2); 1322 q = 1 << (sizeof(n) * 8 - 2);
1251 } else { 1323 }
1324 else
1325 {
1252 while ( q <= n ) { 1326 while (q <= n)
1327 {
1253 q <<= 2; 1328 q <<= 2;
1254 } 1329 }
1255 q >>= 2; 1330 q >>= 2;
1256 } 1331 }
1257 1332
1258 while ( q != 0 ) { 1333 while (q != 0)
1334 {
1259 h = p + q; 1335 h = p + q;
1260 p >>= 1; 1336 p >>= 1;
1261 if ( r >= h ) { 1337 if (r >= h)
1338 {
1262 p += q; 1339 p += q;
1263 r -= h; 1340 r -= h;
1264 } 1341 }
1265 q >>= 2; 1342 q >>= 2;
1266 } 1343 }
1267 return p; 1344 return p;
1268} 1345}
1269 1346
1270struct offset { 1347struct offset
1348{
1271 int px,py,nx,ny; 1349 int px, py, nx, ny;
1272}; 1350};
1273 1351
1274static void
1275calc_offsets(int wi, int l, int dx, int dy, struct offset *res) 1352static void calc_offsets(int wi, int l, int dx, int dy, struct offset *res)
1276{ 1353{
1277 int x,y; 1354 int x, y;
1278 1355
1279 x = (dx * wi) / l; 1356 x = (dx * wi) / l;
1280 y = (dy * wi) / l; 1357 y = (dy * wi) / l;
1281 if (x < 0) { 1358 if (x < 0)
1359 {
1282 res->nx = -x/2; 1360 res->nx = -x / 2;
1283 res->px = (x-1)/2; 1361 res->px = (x - 1) / 2;
1284 } else { 1362 }
1363 else
1364 {
1285 res->nx = -(x+1)/2; 1365 res->nx = -(x + 1) / 2;
1286 res->px = x/2; 1366 res->px = x / 2;
1287 } 1367 }
1288 if (y < 0) { 1368 if (y < 0)
1369 {
1289 res->ny = -y/2; 1370 res->ny = -y / 2;
1290 res->py = (y-1)/2; 1371 res->py = (y - 1) / 2;
1291 } else { 1372 }
1373 else
1374 {
1292 res->ny = -(y+1)/2; 1375 res->ny = -(y + 1) / 2;
1293 res->py = y/2; 1376 res->py = y / 2;
1294 } 1377 }
1295} 1378}
1296 1379
1297static void
1298graphics_draw_polyline_as_polygon(struct graphics *gra, struct graphics_gc *gc, struct point *pnt, int count, int *width, int step, int fill, int order, int oneway) 1380static void graphics_draw_polyline_as_polygon(struct graphics *gra, struct graphics_gc *gc, struct point *pnt, int count, int *width, int step, int fill, int order, int oneway)
1299{ 1381{
1300 int maxpoints=200; 1382 int maxpoints = 200;
1301 struct point *res=g_alloca(sizeof(struct point)*maxpoints); 1383 struct point *res = g_alloca(sizeof(struct point) * maxpoints);
1302 struct point pos, poso, neg, nego; 1384 struct point pos, poso, neg, nego;
1303 int i, dx=0, dy=0, l=0, dxo=0, dyo=0; 1385 int i, dx = 0, dy = 0, l = 0, dxo = 0, dyo = 0;
1304 struct offset o,oo={0,0,0,0}; 1386 struct offset o, oo =
1387 { 0, 0, 0, 0 };
1305 int fow=0, fowo=0, delta; 1388 int fow = 0, fowo = 0, delta;
1306 int wi, ppos = maxpoints/2, npos = maxpoints/2; 1389 int wi, ppos = maxpoints / 2, npos = maxpoints / 2;
1307 int state,prec=5; 1390 int state, prec = 5;
1308 int max_circle_points=20; 1391 int max_circle_points = 20;
1309 int lscale=16; 1392 int lscale = 16;
1310 i=0; 1393 i = 0;
1311 for (;;) { 1394 for (;;)
1395 {
1312 wi=*width; 1396 wi = *width;
1313 width+=step; 1397 width += step;
1314 if (i < count - 1) { 1398 if (i < count - 1)
1399 {
1315 int dxs,dys,lscales; 1400 int dxs, dys, lscales;
1316 1401
1317 dx = (pnt[i + 1].x - pnt[i].x); 1402 dx = (pnt[i + 1].x - pnt[i].x);
1318 dy = (pnt[i + 1].y - pnt[i].y); 1403 dy = (pnt[i + 1].y - pnt[i].y);
1319#if 0 1404#if 0
1320 l = int_sqrt(dx * dx * lscale * lscale + dy * dy * lscale * lscale); 1405 l = int_sqrt(dx * dx * lscale * lscale + dy * dy * lscale * lscale);
1321#else 1406#else
1322 dxs=dx*dx; 1407 dxs = dx * dx;
1323 dys=dy*dy; 1408 dys = dy * dy;
1324 lscales=lscale*lscale; 1409 lscales = lscale * lscale;
1325 if (dxs + dys > lscales) 1410 if (dxs + dys > lscales)
1326 l = int_sqrt(dxs+dys)*lscale; 1411 l = int_sqrt(dxs + dys) * lscale;
1327 else 1412 else
1328 l = int_sqrt((dxs+dys)*lscales); 1413 l = int_sqrt((dxs + dys) * lscales);
1329#endif 1414#endif
1330 fow=fowler(-dy, dx); 1415 fow = fowler(-dy, dx);
1331 } 1416 }
1332 if (! l) 1417 if (!l)
1333 l=1; 1418 l = 1;
1334 if (wi*lscale > 10000) 1419 if (wi * lscale > 10000)
1335 lscale=10000/wi; 1420 lscale = 10000 / wi;
1336 dbg_assert(wi*lscale <= 10000); 1421 dbg_assert(wi * lscale <= 10000);
1337 calc_offsets(wi*lscale, l, dx, dy, &o); 1422 calc_offsets(wi * lscale, l, dx, dy, &o);
1338 pos.x = pnt[i].x + o.ny; 1423 pos.x = pnt[i].x + o.ny;
1339 pos.y = pnt[i].y + o.px; 1424 pos.y = pnt[i].y + o.px;
1340 neg.x = pnt[i].x + o.py; 1425 neg.x = pnt[i].x + o.py;
1341 neg.y = pnt[i].y + o.nx; 1426 neg.y = pnt[i].y + o.nx;
1342 if (! i) 1427 if (!i)
1343 state=0; 1428 state = 0;
1344 else if (i == count-1) 1429 else if (i == count - 1)
1345 state=2; 1430 state = 2;
1346 else if (npos < max_circle_points || ppos >= maxpoints-max_circle_points) 1431 else if (npos < max_circle_points || ppos >= maxpoints - max_circle_points)
1347 state=3; 1432 state = 3;
1348 else 1433 else
1349 state=1; 1434 state = 1;
1350 switch (state) { 1435 switch (state)
1436 {
1351 case 1: 1437 case 1:
1352 if (fowo != fow) { 1438 if (fowo != fow)
1439 {
1353 poso.x = pnt[i].x + oo.ny; 1440 poso.x = pnt[i].x + oo.ny;
1354 poso.y = pnt[i].y + oo.px; 1441 poso.y = pnt[i].y + oo.px;
1355 nego.x = pnt[i].x + oo.py; 1442 nego.x = pnt[i].x + oo.py;
1356 nego.y = pnt[i].y + oo.nx; 1443 nego.y = pnt[i].y + oo.nx;
1357 delta=fowo-fow; 1444 delta = fowo - fow;
1358 if (delta < 0) 1445 if (delta < 0)
1359 delta+=1024; 1446 delta += 1024;
1360 if (delta < 512) { 1447 if (delta < 512)
1448 {
1361 if (intersection(&pos, dx, dy, &poso, dxo, dyo, &res[ppos])) 1449 if (intersection(&pos, dx, dy, &poso, dxo, dyo, &res[ppos]))
1450 {
1362 ppos++; 1451 ppos++;
1452 }
1363 res[--npos] = nego; 1453 res[--npos] = nego;
1364 --npos; 1454 --npos;
1455 if (fill == 1)
1456 {
1457 if (draw_polylines_fast == 0)
1458 {
1365 if (fill==1) draw_circle(&pnt[i], wi, prec, fowo-512, -delta, res, &npos, -1); 1459 draw_circle(&pnt[i], wi, prec, fowo - 512, -delta, res, &npos, -1);
1460 }
1461 }
1366 res[npos] = neg; 1462 res[npos] = neg;
1463 }
1367 } else { 1464 else
1465 {
1368 res[ppos++] = poso; 1466 res[ppos++] = poso;
1467 if (fill == 1)
1468 {
1469 if (draw_polylines_fast == 0)
1470 {
1369 if (fill==1) draw_circle(&pnt[i], wi, prec, fowo, 1024-delta, res, &ppos, 1); 1471 draw_circle(&pnt[i], wi, prec, fowo, 1024 - delta, res, &ppos, 1);
1472 }
1473 }
1370 res[ppos++] = pos; 1474 res[ppos++] = pos;
1371 if (intersection(&neg, dx, dy, &nego, dxo, dyo, &res[npos - 1])) 1475 if (intersection(&neg, dx, dy, &nego, dxo, dyo, &res[npos - 1]))
1476 {
1372 npos--; 1477 npos--;
1478 }
1479 }
1373 } 1480 }
1481 break;
1482 case 2:
1483 case 3:
1484 res[--npos] = neg;
1485 --npos;
1486 if (fill == 1)
1487 {
1488 if (draw_polylines_fast == 0)
1489 {
1490 draw_circle(&pnt[i], wi, prec, fow - 512, -512, res, &npos, -1);
1491 }
1374 } 1492 }
1493 res[npos] = pos;
1494 res[ppos++] = pos;
1495 dbg_assert(npos > 0);
1496 dbg_assert(ppos < maxpoints);
1497 if (fill == 1)
1498 {
1499 gra->meth.draw_polygon2(gra->priv, gc->priv, res + npos, ppos - npos, order, oneway);
1500 }
1501 else
1502 {
1503 gra->meth.draw_lines_dashed(gra->priv, gc->priv, res + npos, ppos - npos, order, oneway);
1504 }
1505 if (state == 2)
1506 break;
1507 npos = maxpoints / 2;
1508 ppos = maxpoints / 2;
1509 case 0:
1510 res[ppos++] = neg;
1511 if (fill == 1)
1512 {
1513 if (draw_polylines_fast == 0)
1514 {
1515 draw_circle(&pnt[i], wi, prec, fow + 512, 512, res, &ppos, 1);
1516 }
1517 }
1518 res[ppos++] = pos;
1519 break;
1520 }
1521
1522 i++;
1523
1524 if (i >= count)
1525 {
1375 break; 1526 break;
1376 case 2:
1377 case 3:
1378 res[--npos] = neg;
1379 --npos;
1380 if (fill==1) draw_circle(&pnt[i], wi, prec, fow-512, -512, res, &npos, -1);
1381 res[npos] = pos;
1382 res[ppos++] = pos;
1383 dbg_assert(npos > 0);
1384 dbg_assert(ppos < maxpoints);
1385 if (fill==1)
1386 {
1387 gra->meth.draw_polygon2(gra->priv, gc->priv, res+npos, ppos-npos, order, oneway);
1388 } 1527 }
1389 else 1528
1390 {
1391 gra->meth.draw_lines_dashed(gra->priv, gc->priv, res+npos, ppos-npos, order, oneway);
1392 }
1393 if (state == 2)
1394 break;
1395 npos=maxpoints/2;
1396 ppos=maxpoints/2;
1397 case 0:
1398 res[ppos++] = neg;
1399 if (fill==1) draw_circle(&pnt[i], wi, prec, fow+512, 512, res, &ppos, 1);
1400 res[ppos++] = pos;
1401 break;
1402 }
1403 i++;
1404 if (i >= count)
1405 break;
1406 if (step) { 1529 if (step)
1530 {
1407 wi=*width; 1531 wi = *width;
1408 calc_offsets(wi*lscale, l, dx, dy, &oo); 1532 calc_offsets(wi * lscale, l, dx, dy, &oo);
1533 }
1409 } else 1534 else
1535 {
1410 oo=o; 1536 oo = o;
1537 }
1538
1411 dxo = -dx; 1539 dxo = -dx;
1412 dyo = -dy; 1540 dyo = -dy;
1413 fowo=fow; 1541 fowo = fow;
1414 } 1542 }
1415} 1543}
1416 1544
1417
1418struct wpoint { 1545struct wpoint
1546{
1419 int x,y,w; 1547 int x, y, w;
1420}; 1548};
1421 1549
1422static int
1423clipcode(struct wpoint *p, struct point_rect *r) 1550static int clipcode(struct wpoint *p, struct point_rect *r)
1424{ 1551{
1425 int code=0; 1552 int code = 0;
1426 if (p->x < r->lu.x) 1553 if (p->x < r->lu.x)
1427 code=1; 1554 code = 1;
1428 if (p->x > r->rl.x) 1555 if (p->x > r->rl.x)
1429 code=2; 1556 code = 2;
1430 if (p->y < r->lu.y) 1557 if (p->y < r->lu.y)
1431 code |=4; 1558 code |= 4;
1432 if (p->y > r->rl.y) 1559 if (p->y > r->rl.y)
1433 code |=8; 1560 code |= 8;
1434 return code; 1561 return code;
1435} 1562}
1436 1563
1437
1438static int
1439clip_line(struct wpoint *p1, struct wpoint *p2, struct point_rect *r) 1564static int clip_line(struct wpoint *p1, struct wpoint *p2, struct point_rect *r)
1440{ 1565{
1441 int code1,code2,ret=1; 1566 int code1, code2, ret = 1;
1442 int dx,dy,dw; 1567 int dx, dy, dw;
1443 code1=clipcode(p1, r); 1568 code1 = clipcode(p1, r);
1444 if (code1) 1569 if (code1)
1445 ret |= 2; 1570 ret |= 2;
1446 code2=clipcode(p2, r); 1571 code2 = clipcode(p2, r);
1447 if (code2) 1572 if (code2)
1448 ret |= 4; 1573 ret |= 4;
1449 dx=p2->x-p1->x; 1574 dx = p2->x - p1->x;
1450 dy=p2->y-p1->y; 1575 dy = p2->y - p1->y;
1451 dw=p2->w-p1->w; 1576 dw = p2->w - p1->w;
1452 while (code1 || code2) { 1577 while (code1 || code2)
1578 {
1453 if (code1 & code2) 1579 if (code1 & code2)
1454 return 0; 1580 return 0;
1455 if (code1 & 1) { 1581 if (code1 & 1)
1582 {
1456 p1->y+=(r->lu.x-p1->x)*dy/dx; 1583 p1->y += (r->lu.x - p1->x) * dy / dx;
1457 p1->w+=(r->lu.x-p1->x)*dw/dx; 1584 p1->w += (r->lu.x - p1->x) * dw / dx;
1458 p1->x=r->lu.x; 1585 p1->x = r->lu.x;
1586 }
1459 } else if (code1 & 2) { 1587 else if (code1 & 2)
1588 {
1460 p1->y+=(r->rl.x-p1->x)*dy/dx; 1589 p1->y += (r->rl.x - p1->x) * dy / dx;
1461 p1->w+=(r->rl.x-p1->x)*dw/dx; 1590 p1->w += (r->rl.x - p1->x) * dw / dx;
1462 p1->x=r->rl.x; 1591 p1->x = r->rl.x;
1592 }
1463 } else if (code1 & 4) { 1593 else if (code1 & 4)
1594 {
1464 p1->x+=(r->lu.y-p1->y)*dx/dy; 1595 p1->x += (r->lu.y - p1->y) * dx / dy;
1465 p1->w+=(r->lu.y-p1->y)*dw/dy; 1596 p1->w += (r->lu.y - p1->y) * dw / dy;
1466 p1->y=r->lu.y; 1597 p1->y = r->lu.y;
1598 }
1467 } else if (code1 & 8) { 1599 else if (code1 & 8)
1600 {
1468 p1->x+=(r->rl.y-p1->y)*dx/dy; 1601 p1->x += (r->rl.y - p1->y) * dx / dy;
1469 p1->w+=(r->rl.y-p1->y)*dw/dy; 1602 p1->w += (r->rl.y - p1->y) * dw / dy;
1470 p1->y=r->rl.y; 1603 p1->y = r->rl.y;
1471 } 1604 }
1472 code1=clipcode(p1, r); 1605 code1 = clipcode(p1, r);
1473 if (code1 & code2) 1606 if (code1 & code2)
1474 return 0; 1607 return 0;
1475 if (code2 & 1) { 1608 if (code2 & 1)
1609 {
1476 p2->y+=(r->lu.x-p2->x)*dy/dx; 1610 p2->y += (r->lu.x - p2->x) * dy / dx;
1477 p2->w+=(r->lu.x-p2->x)*dw/dx; 1611 p2->w += (r->lu.x - p2->x) * dw / dx;
1478 p2->x=r->lu.x; 1612 p2->x = r->lu.x;
1613 }
1479 } else if (code2 & 2) { 1614 else if (code2 & 2)
1615 {
1480 p2->y+=(r->rl.x-p2->x)*dy/dx; 1616 p2->y += (r->rl.x - p2->x) * dy / dx;
1481 p2->w+=(r->rl.x-p2->x)*dw/dx; 1617 p2->w += (r->rl.x - p2->x) * dw / dx;
1482 p2->x=r->rl.x; 1618 p2->x = r->rl.x;
1619 }
1483 } else if (code2 & 4) { 1620 else if (code2 & 4)
1621 {
1484 p2->x+=(r->lu.y-p2->y)*dx/dy; 1622 p2->x += (r->lu.y - p2->y) * dx / dy;
1485 p2->w+=(r->lu.y-p2->y)*dw/dy; 1623 p2->w += (r->lu.y - p2->y) * dw / dy;
1486 p2->y=r->lu.y; 1624 p2->y = r->lu.y;
1625 }
1487 } else if (code2 & 8) { 1626 else if (code2 & 8)
1627 {
1488 p2->x+=(r->rl.y-p2->y)*dx/dy; 1628 p2->x += (r->rl.y - p2->y) * dx / dy;
1489 p2->w+=(r->rl.y-p2->y)*dw/dy; 1629 p2->w += (r->rl.y - p2->y) * dw / dy;
1490 p2->y=r->rl.y; 1630 p2->y = r->rl.y;
1491 } 1631 }
1492 code2=clipcode(p2, r); 1632 code2 = clipcode(p2, r);
1493 } 1633 }
1494 return ret; 1634 return ret;
1495} 1635}
1496 1636
1497static void
1498graphics_draw_polyline_clipped(struct graphics *gra, struct graphics_gc *gc, struct point *pa, int count, int *width, int step, int poly, int order, int oneway) 1637static void graphics_draw_polyline_clipped(struct graphics *gra, struct graphics_gc *gc, struct point *pa, int count, int *width, int step, int poly, int order, int oneway)
1499{ 1638{
1500 struct point *p=g_alloca(sizeof(struct point)*(count+1)); 1639 struct point *p = g_alloca(sizeof(struct point) * (count + 1));
1501 int *w=g_alloca(sizeof(int)*(count*step+1)); 1640 int *w = g_alloca(sizeof(int) * (count * step + 1));
1502 struct wpoint p1,p2; 1641 struct wpoint p1, p2;
1503 int i,code,out=0; 1642 int i, code, out = 0;
1504 int wmax; 1643 int wmax;
1505 struct point_rect r=gra->r; 1644 struct point_rect r = gra->r;
1506 1645
1507 wmax=width[0]; 1646 wmax = width[0];
1508 if (step) { 1647 if (step)
1648 {
1509 for (i = 1 ; i < count ; i++) { 1649 for (i = 1; i < count; i++)
1650 {
1510 if (width[i*step] > wmax) 1651 if (width[i * step] > wmax)
1511 wmax=width[i*step]; 1652 wmax = width[i * step];
1512 } 1653 }
1513 } 1654 }
1514 if (wmax <= 0) 1655 if (wmax <= 0)
1656 {
1515 return; 1657 return;
1658 }
1516 r.lu.x-=wmax; 1659 r.lu.x -= wmax;
1517 r.lu.y-=wmax; 1660 r.lu.y -= wmax;
1518 r.rl.x+=wmax; 1661 r.rl.x += wmax;
1519 r.rl.y+=wmax; 1662 r.rl.y += wmax;
1663
1520 for (i = 0 ; i < count ; i++) { 1664 for (i = 0; i < count; i++)
1665 {
1521 if (i) { 1666 if (i)
1667 {
1522 p1.x=pa[i-1].x; 1668 p1.x = pa[i - 1].x;
1523 p1.y=pa[i-1].y; 1669 p1.y = pa[i - 1].y;
1524 p1.w=width[(i-1)*step]; 1670 p1.w = width[(i - 1) * step];
1525 p2.x=pa[i].x; 1671 p2.x = pa[i].x;
1526 p2.y=pa[i].y; 1672 p2.y = pa[i].y;
1527 p2.w=width[i*step]; 1673 p2.w = width[i * step];
1528 /* 0 = invisible, 1 = completely visible, 3 = start point clipped, 5 = end point clipped, 7 both points clipped */ 1674 /* 0 = invisible, 1 = completely visible, 3 = start point clipped, 5 = end point clipped, 7 both points clipped */
1529 code=clip_line(&p1, &p2, &r); 1675 code = clip_line(&p1, &p2, &r);
1676
1530 if (((code == 1 || code == 5) && i == 1) || (code & 2)) { 1677 if (((code == 1 || code == 5) && i == 1) || (code & 2))
1678 {
1531 p[out].x=p1.x; 1679 p[out].x = p1.x;
1532 p[out].y=p1.y; 1680 p[out].y = p1.y;
1533 w[out*step]=p1.w; 1681 w[out * step] = p1.w;
1534 out++; 1682 out++;
1535 } 1683 }
1684
1536 if (code) { 1685 if (code)
1686 {
1537 p[out].x=p2.x; 1687 p[out].x = p2.x;
1538 p[out].y=p2.y; 1688 p[out].y = p2.y;
1539 w[out*step]=p2.w; 1689 w[out * step] = p2.w;
1540 out++; 1690 out++;
1541 } 1691 }
1692
1542 if (i == count-1 || (code & 4)) { 1693 if (i == count - 1 || (code & 4))
1694 {
1543 if (out > 1) { 1695 if (out > 1)
1544 if (poly==1) 1696 {
1697 if ((poly == 1) || (poly == 0))
1545 { 1698 {
1546 // normal street 1699 // normal street
1700 //if (1 == 0)
1701 //{
1702 // // draw as polygon --> OLD method
1547 graphics_draw_polyline_as_polygon(gra, gc, p, out, w, step, 1, order, 0); 1703 // graphics_draw_polyline_as_polygon(gra, gc, p, out, w, step, 1, order, 0);
1704 //}
1705 //else
1706 //{
1707 // draw as line
1708 // dbg(0,"w=%d", width[i]);
1709 gra->meth.draw_lines3(gra->priv, gc->priv, p, out, order, width[i]);
1710 //}
1711
1548 // one way arrow 1712 // one way arrow
1549 if (oneway > 0) 1713 if (oneway > 0)
1550 { 1714 {
1551 gra->meth.draw_lines2(gra->priv, gc->priv, p, out, order, oneway); 1715 gra->meth.draw_lines2(gra->priv, gc->priv, p, out, order, oneway);
1552 } 1716 }
1553 } 1717 }
1554 else if (poly==2) 1718 else if (poly == 2)
1555 { 1719 {
1556 // street is underground 1720 // ******* street is underground ********
1721 // ******* street is underground ********
1722 // ******* street is underground ********
1723
1724 //if (1 == 0)
1725 //{
1726 // // draw as polygon --> OLD method
1557 graphics_draw_polyline_as_polygon(gra, gc, p, out, w, step, 0, order, 0); 1727 // graphics_draw_polyline_as_polygon(gra, gc, p, out, w, step, 0, order, 0);
1728 //}
1729 //else
1730 //{
1731 // draw as line
1732 gra->meth.draw_lines4(gra->priv, gc->priv, p, out, order, width[i], 1);
1733 //}
1734
1558 // one way arrow 1735 // one way arrow
1559 if (oneway > 0) 1736 if (oneway > 0)
1560 { 1737 {
1561 gra->meth.draw_lines2(gra->priv, gc->priv, p, out, order, oneway); 1738 gra->meth.draw_lines2(gra->priv, gc->priv, p, out, order, oneway);
1562 } 1739 }
1563 } 1740 }
1741 else if (poly == 3)
1742 {
1743 // ******* street has bridge ********
1744 // ******* street has bridge ********
1745 // ******* street has bridge ********
1746 gra->meth.draw_lines4(gra->priv, gc->priv, p, out, order, width[i], 2);
1747
1748 // one way arrow
1749 if (oneway > 0)
1750 {
1751 gra->meth.draw_lines2(gra->priv, gc->priv, p, out, order, oneway);
1752 }
1753 }
1754 // --> now NOT used anymore!!
1564 else // poly==0 -> street that is only a line (width=1) 1755 else // poly==0 -> street that is only a line (width=1)
1565 { 1756 {
1757 // OLD // gra->meth.draw_lines2(gra->priv, gc->priv, p, out, order, 0);
1758
1759 gra->meth.draw_lines3(gra->priv, gc->priv, p, out, order, width[i]);
1760
1761 // one way arrow
1762 if (oneway > 0)
1763 {
1566 gra->meth.draw_lines2(gra->priv, gc->priv, p, out, order, 0); 1764 gra->meth.draw_lines2(gra->priv, gc->priv, p, out, order, oneway);
1765 }
1567 } 1766 }
1568 out=0; 1767 out = 0;
1569 } 1768 }
1570 } 1769 }
1571 } 1770 }
1572 } 1771 }
1573} 1772}
1574 1773
1575static int
1576is_inside(struct point *p, struct point_rect *r, int edge) 1774static int is_inside(struct point *p, struct point_rect *r, int edge)
1577{ 1775{
1578 switch(edge) { 1776 switch (edge)
1777 {
1579 case 0: 1778 case 0:
1580 return p->x >= r->lu.x; 1779 return p->x >= r->lu.x;
1581 case 1: 1780 case 1:
1582 return p->x <= r->rl.x; 1781 return p->x <= r->rl.x;
1583 case 2: 1782 case 2:
1584 return p->y >= r->lu.y; 1783 return p->y >= r->lu.y;
1585 case 3: 1784 case 3:
1586 return p->y <= r->rl.y; 1785 return p->y <= r->rl.y;
1587 default: 1786 default:
1588 return 0; 1787 return 0;
1589 } 1788 }
1590} 1789}
1591 1790
1592static void
1593poly_intersection(struct point *p1, struct point *p2, struct point_rect *r, int edge, struct point *ret) 1791static void poly_intersection(struct point *p1, struct point *p2, struct point_rect *r, int edge, struct point *ret)
1594{ 1792{
1595 int dx=p2->x-p1->x; 1793 int dx = p2->x - p1->x;
1596 int dy=p2->y-p1->y; 1794 int dy = p2->y - p1->y;
1597 switch(edge) { 1795 switch (edge)
1796 {
1598 case 0: 1797 case 0:
1599 ret->y=p1->y+(r->lu.x-p1->x)*dy/dx; 1798 ret->y = p1->y + (r->lu.x - p1->x) * dy / dx;
1600 ret->x=r->lu.x; 1799 ret->x = r->lu.x;
1601 break; 1800 break;
1602 case 1: 1801 case 1:
1603 ret->y=p1->y+(r->rl.x-p1->x)*dy/dx; 1802 ret->y = p1->y + (r->rl.x - p1->x) * dy / dx;
1604 ret->x=r->rl.x; 1803 ret->x = r->rl.x;
1605 break; 1804 break;
1606 case 2: 1805 case 2:
1607 ret->x=p1->x+(r->lu.y-p1->y)*dx/dy; 1806 ret->x = p1->x + (r->lu.y - p1->y) * dx / dy;
1608 ret->y=r->lu.y; 1807 ret->y = r->lu.y;
1609 break; 1808 break;
1610 case 3: 1809 case 3:
1611 ret->x=p1->x+(r->rl.y-p1->y)*dx/dy; 1810 ret->x = p1->x + (r->rl.y - p1->y) * dx / dy;
1612 ret->y=r->rl.y; 1811 ret->y = r->rl.y;
1613 break; 1812 break;
1614 } 1813 }
1615} 1814}
1616 1815
1617static void
1618graphics_draw_polygon_clipped(struct graphics *gra, struct graphics_gc *gc, struct point *pin, int count_in) 1816static void graphics_draw_polygon_clipped(struct graphics *gra, struct graphics_gc *gc, struct point *pin, int count_in)
1619{ 1817{
1620 struct point_rect r=gra->r; 1818 struct point_rect r = gra->r;
1621 struct point *pout,*p,*s,pi,*p1,*p2; 1819 struct point *pout, *p, *s, pi, *p1, *p2;
1622 int limit=10000; 1820 int limit = 10000;
1623 struct point *pa1=g_alloca(sizeof(struct point) * (count_in < limit ? count_in*8+1:0)); 1821 struct point *pa1 = g_alloca(sizeof(struct point) * (count_in < limit ? count_in * 8 + 1 : 0));
1624 struct point *pa2=g_alloca(sizeof(struct point) * (count_in < limit ? count_in*8+1:0)); 1822 struct point *pa2 = g_alloca(sizeof(struct point) * (count_in < limit ? count_in * 8 + 1 : 0));
1625 int count_out,edge=3; 1823 int count_out, edge = 3;
1626 int i; 1824 int i;
1627#if 0 1825#if 0
1628 r.lu.x+=20; 1826 r.lu.x+=20;
1629 r.lu.y+=20; 1827 r.lu.y+=20;
1630 r.rl.x-=20; 1828 r.rl.x-=20;
1631 r.rl.y-=20; 1829 r.rl.y-=20;
1632#endif 1830#endif
1633 if (count_in < limit) { 1831 if (count_in < limit)
1832 {
1634 p1=pa1; 1833 p1 = pa1;
1635 p2=pa2; 1834 p2 = pa2;
1636 } else { 1835 }
1836 else
1837 {
1637 p1=g_new(struct point, count_in*8+1); 1838 p1=g_new(struct point, count_in*8+1);
1638 p2=g_new(struct point, count_in*8+1); 1839 p2=g_new(struct point, count_in*8+1);
1639 } 1840 }
1640 1841
1641 pout=p1; 1842 pout=p1;
1642 for (edge = 0 ; edge < 4 ; edge++) { 1843 for (edge = 0; edge < 4; edge++)
1844 {
1643 p=pin; 1845 p=pin;
1644 s=pin+count_in-1; 1846 s=pin+count_in-1;
1645 count_out=0; 1847 count_out=0;
1646 for (i = 0 ; i < count_in ; i++) { 1848 for (i = 0; i < count_in; i++)
1849 {
1647 if (is_inside(p, &r, edge)) { 1850 if (is_inside(p, &r, edge))
1851 {
1648 if (! is_inside(s, &r, edge)) { 1852 if (! is_inside(s, &r, edge))
1853 {
1649 poly_intersection(s,p,&r,edge,&pi); 1854 poly_intersection(s,p,&r,edge,&pi);
1650 pout[count_out++]=pi; 1855 pout[count_out++]=pi;
1651 } 1856 }
1652 pout[count_out++]=*p; 1857 pout[count_out++]=*p;
1858 }
1653 } else { 1859 else
1860 {
1654 if (is_inside(s, &r, edge)) { 1861 if (is_inside(s, &r, edge))
1862 {
1655 poly_intersection(p,s,&r,edge,&pi); 1863 poly_intersection(p,s,&r,edge,&pi);
1656 pout[count_out++]=pi; 1864 pout[count_out++]=pi;
1657 } 1865 }
1658 } 1866 }
1659 s=p; 1867 s=p;
1660 p++; 1868 p++;
1661 } 1869 }
1662 count_in=count_out; 1870 count_in=count_out;
1663 if (pin == p1) { 1871 if (pin == p1)
1872 {
1664 pin=p2; 1873 pin=p2;
1665 pout=p1; 1874 pout=p1;
1875 }
1666 } else { 1876 else
1877 {
1667 pin=p1; 1878 pin=p1;
1668 pout=p2; 1879 pout=p2;
1669 } 1880 }
1670 } 1881 }
1882
1671 gra->meth.draw_polygon(gra->priv, gc->priv, pin, count_in); 1883 gra->meth.draw_polygon(gra->priv, gc->priv, pin, count_in);
1672 if (count_in >= limit) { 1884 if (count_in >= limit)
1885 {
1673 g_free(p1); 1886 g_free(p1);
1674 g_free(p2); 1887 g_free(p2);
1675 } 1888 }
1676} 1889}
1677 1890
1678
1679static void
1680display_context_free(struct display_context *dc) 1891static void display_context_free(struct display_context *dc)
1681{ 1892{
1682 if (dc->gc) 1893 if (dc->gc)
1683 graphics_gc_destroy(dc->gc); 1894 graphics_gc_destroy(dc->gc);
1684 if (dc->gc_background) 1895 if (dc->gc_background)
1685 graphics_gc_destroy(dc->gc_background); 1896 graphics_gc_destroy(dc->gc_background);
1686 if (dc->img) 1897 if (dc->img)
1687 graphics_image_free(dc->gra, dc->img); 1898 graphics_image_free(dc->gra, dc->img);
1688 dc->gc=NULL; 1899 dc->gc = NULL;
1689 dc->gc_background=NULL; 1900 dc->gc_background = NULL;
1690 dc->img=NULL; 1901 dc->img = NULL;
1691} 1902}
1692 1903
1693static struct graphics_font * 1904static struct graphics_font *
1694get_font(struct graphics *gra, int size) 1905get_font(struct graphics *gra, int size)
1695{ 1906{
1696 if (size > 64) 1907 if (size > 64)
1908 {
1697 size=64; 1909 size = 64;
1910 }
1698 if (size >= gra->font_len) { 1911 if (size >= gra->font_len)
1912 {
1699 gra->font=g_renew(struct graphics_font *, gra->font, size+1); 1913 gra->font=g_renew(struct graphics_font *, gra->font, size+1);
1700 while (gra->font_len <= size) 1914 while (gra->font_len <= size)
1915 {
1701 gra->font[gra->font_len++]=NULL; 1916 gra->font[gra->font_len++] = NULL;
1702 } 1917 }
1918 }
1703 if (! gra->font[size]) 1919 if (!gra->font[size])
1920 {
1704 gra->font[size]=graphics_font_new(gra, size*gra->font_size, 0); 1921 gra->font[size] = graphics_font_new(gra, size * gra->font_size, 0);
1922 }
1705 return gra->font[size]; 1923 return gra->font[size];
1706} 1924}
1707 1925
1708void graphics_draw_text_std(struct graphics *this_, int text_size, char *text, struct point *p) 1926void graphics_draw_text_std(struct graphics *this_, int text_size, char *text, struct point *p)
1709{ 1927{
1710 struct graphics_font *font=get_font(this_, text_size); 1928 struct graphics_font *font = get_font(this_, text_size);
1711 struct point bbox[4]; 1929 struct point bbox[4];
1712 int i; 1930 int i;
1713 1931
1714 graphics_get_text_bbox(this_, font, text, 0x10000, 0, bbox, 0); 1932 graphics_get_text_bbox(this_, font, text, 0x10000, 0, bbox, 0);
1715 for (i = 0 ; i < 4 ; i++) { 1933 for (i = 0; i < 4; i++)
1934 {
1716 bbox[i].x+=p->x; 1935 bbox[i].x += p->x;
1717 bbox[i].y+=p->y; 1936 bbox[i].y += p->y;
1718 } 1937 }
1719 graphics_draw_rectangle(this_, this_->gc[2], &bbox[1], bbox[2].x-bbox[0].x, bbox[0].y-bbox[1].y+5); 1938 graphics_draw_rectangle(this_, this_->gc[2], &bbox[1], bbox[2].x - bbox[0].x, bbox[0].y - bbox[1].y + 5);
1720 graphics_draw_text(this_, this_->gc[1], this_->gc[2], font, text, p, 0x10000, 0); 1939 graphics_draw_text(this_, this_->gc[1], this_->gc[2], font, text, p, 0x10000, 0);
1721} 1940}
1722 1941
1723char * 1942char *
1724graphics_icon_path(char *icon) 1943graphics_icon_path(char *icon)
1725{ 1944{
1726 static char *navit_sharedir; 1945 static char *navit_sharedir;
1727 char *ret=NULL; 1946 char *ret = NULL;
1728 struct file_wordexp *wordexp=NULL; 1947 struct file_wordexp *wordexp = NULL;
1729 dbg(1,"enter %s\n",icon); 1948 // dbg(1, "enter %s\n", icon);
1730 if (strchr(icon, '$')) { 1949 if (strchr(icon, '$'))
1950 {
1731 wordexp=file_wordexp_new(icon); 1951 wordexp = file_wordexp_new(icon);
1732 if (file_wordexp_get_count(wordexp)) 1952 if (file_wordexp_get_count(wordexp))
1953 {
1733 icon=file_wordexp_get_array(wordexp)[0]; 1954 icon = file_wordexp_get_array(wordexp)[0];
1734 } 1955 }
1956 }
1957
1735 if (strchr(icon,'/')) 1958 if (strchr(icon, '/'))
1959 {
1736 ret=g_strdup(icon); 1960 ret = g_strdup(icon);
1961 }
1737 else { 1962 else
1963 {
1738#ifdef HAVE_API_ANDROID 1964#ifdef HAVE_API_ANDROID
1739 // get resources for the correct screen density 1965 // get resources for the correct screen density
1740 // 1966 //
1741 // this part not needed, android unpacks only the correct version into res/drawable dir! 1967 // this part not needed, android unpacks only the correct version into res/drawable dir!
1742 // dbg(1,"android icon_path %s\n",icon); 1968 // // dbg(1,"android icon_path %s\n",icon);
1743 // static char *android_density; 1969 // static char *android_density;
1744 // android_density = getenv("ANDROID_DENSITY"); 1970 // android_density = getenv("ANDROID_DENSITY");
1745 // ret=g_strdup_printf("res/drawable-%s/%s",android_density ,icon); 1971 // ret=g_strdup_printf("res/drawable-%s/%s",android_density ,icon);
1746 ret=g_strdup_printf("res/drawable/%s" ,icon); 1972 ret=g_strdup_printf("res/drawable/%s" ,icon);
1747#else 1973#else
1748 if (! navit_sharedir) 1974 if (!navit_sharedir)
1975 {
1749 navit_sharedir = getenv("NAVIT_SHAREDIR"); 1976 navit_sharedir = getenv("NAVIT_SHAREDIR");
1977 }
1750 ret=g_strdup_printf("%s/xpm/%s", navit_sharedir, icon); 1978 ret = g_strdup_printf("%s/xpm/%s", navit_sharedir, icon);
1751#endif 1979#endif
1752 } 1980 }
1981
1753 if (wordexp) 1982 if (wordexp)
1983 {
1754 file_wordexp_destroy(wordexp); 1984 file_wordexp_destroy(wordexp);
1985 }
1986
1755 return ret; 1987 return ret;
1756} 1988}
1757 1989
1758static int
1759limit_count(struct coord *c, int count) 1990static int limit_count(struct coord *c, int count)
1760{ 1991{
1761 int i; 1992 int i;
1762 for (i = 1 ; i < count ; i++) { 1993 for (i = 1; i < count; i++)
1994 {
1763 if (c[i].x == c[0].x && c[i].y == c[0].y) 1995 if (c[i].x == c[0].x && c[i].y == c[0].y)
1764 return i+1; 1996 return i + 1;
1765 } 1997 }
1766 return count; 1998 return count;
1767} 1999}
1768 2000
1769
1770static void
1771displayitem_draw(struct displayitem *di, void *dummy, struct display_context *dc, int order, int allow_dashed) 2001static void displayitem_draw(struct displayitem *di, void *dummy, struct display_context *dc, int order, int allow_dashed)
1772{ 2002{
1773 //dbg(0,"ooo enter ooo\n"); 2003 ////DBG dbg(0,"ooo enter ooo\n");
1774 2004
1775 int *width=g_alloca(sizeof(int)*dc->maxlen); 2005 int *width = g_alloca(sizeof(int) * dc->maxlen);
1776 struct point *pa=g_alloca(sizeof(struct point)*dc->maxlen); 2006 struct point *pa = g_alloca(sizeof(struct point) * dc->maxlen);
1777 struct graphics *gra=dc->gra; 2007 struct graphics *gra = dc->gra;
1778 struct graphics_gc *gc=dc->gc; 2008 struct graphics_gc *gc = dc->gc;
1779 struct element *e=dc->e; 2009 struct element *e = dc->e;
1780 struct graphics_image *img=dc->img; 2010 struct graphics_image *img = dc->img;
1781 struct point p; 2011 struct point p;
1782 char *path; 2012 char *path;
1783 2013
1784 // dbg(0,"enter\n"); 2014 // //DBG dbg(0,"enter\n");
1785 2015
1786 while (di) 2016 while (di)
1787 { 2017 {
1788 int i,count=di->count,mindist=dc->mindist; 2018 int i, count = di->count, mindist = dc->mindist;
1789 2019
1790 if (! gc) 2020 if (!gc)
1791 { 2021 {
1792 gc=graphics_gc_new(gra); 2022 gc = graphics_gc_new(gra);
1793 graphics_gc_set_foreground(gc, &e->color); 2023 graphics_gc_set_foreground(gc, &e->color);
1794 dc->gc=gc; 2024 dc->gc = gc;
1795 } 2025 }
1796 2026
1797 if (item_type_is_area(dc->type) && (dc->e->type == element_polyline || dc->e->type == element_text)) 2027 if (item_type_is_area(dc->type) && (dc->e->type == element_polyline || dc->e->type == element_text))
2028 {
1798 count=limit_count(di->c, count); 2029 count = limit_count(di->c, count);
2030 }
1799 if (dc->type == type_poly_water_tiled) 2031 if (dc->type == type_poly_water_tiled)
2032 {
1800 mindist=0; 2033 mindist = 0;
2034 }
1801 if (dc->e->type == element_polyline) 2035 if (dc->e->type == element_polyline)
2036 {
1802 count=transform(dc->trans, dc->pro, di->c, pa, count, mindist, e->u.polyline.width, width); 2037 count = transform(dc->trans, dc->pro, di->c, pa, count, mindist, e->u.polyline.width, width);
2038 }
1803 else 2039 else
2040 {
1804 count=transform(dc->trans, dc->pro, di->c, pa, count, mindist, 0, NULL); 2041 count = transform(dc->trans, dc->pro, di->c, pa, count, mindist, 0, NULL);
1805 2042 //struct coord *c9191;
2043 //c9191 = di->c;
2044 //dbg(0,"di->c %i %i pa %d %d \n",c9191->x, c9191->y, pa->x, pa->y);
2045 }
1806 2046
1807 switch (e->type) 2047 switch (e->type)
1808 { 2048 {
1809 case element_polygon: 2049 case element_polygon:
1810 graphics_draw_polygon_clipped(gra, gc, pa, count); 2050 graphics_draw_polygon_clipped(gra, gc, pa, count);
1811 break; 2051 break;
1812 case element_polyline: 2052 case element_polyline:
1813 // dbg(0,"draw element_polyline");
1814 { 2053 {
1815 gc->meth.gc_set_linewidth(gc->priv, 1); 2054 gc->meth.gc_set_linewidth(gc->priv, 1);
1816 2055
1817 int poly=e->u.polyline.width > 1; 2056 int poly = e->u.polyline.width > 1;
1818 2057
1819 // detect underground streets/lines/etc ... 2058 // detect underground streets/lines/etc ...
1820 if ((allow_dashed)&&(di->item.flags & AF_UNDERGROUND)) 2059 //if ((allow_dashed) && (di->item.flags & AF_UNDERGROUND))
2060 if (di->item.flags & AF_UNDERGROUND)
1821 { 2061 {
1822 // dbg(0,"flags=AF_UNDERGROUND=%d\n",di->item.flags);
1823 poly=2; 2062 poly = 2;
1824 } 2063 }
2064 else if (di->item.flags & AF_BRIDGE)
2065 {
2066 poly = 3;
2067 }
1825 2068
1826 int oneway=0; 2069 int oneway = 0;
1827 2070
1828 if (di->item.flags & AF_ONEWAYREV) 2071 if (di->item.flags & AF_ONEWAYREV)
1829 { 2072 {
1830 oneway=2; 2073 oneway = 2;
1831 } 2074 }
1832 else if (di->item.flags & AF_ONEWAY) 2075 else if (di->item.flags & AF_ONEWAY)
1833 { 2076 {
1834 oneway=1; 2077 oneway = 1;
1835 } 2078 }
1836 2079
2080 // -------- apply dashes -------
1837 if (e->u.polyline.width > 0 && e->u.polyline.dash_num > 0) 2081 //if (e->u.polyline.width > 0 && e->u.polyline.dash_num > 0)
2082 if (e->u.polyline.dash_num > 0)
1838 { 2083 {
1839 graphics_gc_set_dashes(gc, e->u.polyline.width, 2084 graphics_gc_set_dashes(gra, gc, e->u.polyline.width, e->u.polyline.offset, e->u.polyline.dash_table, e->u.polyline.dash_num, order);
1840 e->u.polyline.offset,
1841 e->u.polyline.dash_table,
1842 e->u.polyline.dash_num);
1843 } 2085 }
2086 // -------- apply dashes -------
2087
1844 for (i = 0 ; i < count ; i++) 2088 for (i = 0; i < count; i++)
1845 { 2089 {
1846 if (width[i] < 2) 2090 if (width[i] < 2)
2091 {
1847 width[i]=2; 2092 width[i] = 2;
2093 }
1848 } 2094 }
1849 graphics_draw_polyline_clipped(gra, gc, pa, count, width, 1, poly, order, oneway); 2095 graphics_draw_polyline_clipped(gra, gc, pa, count, width, 1, poly, order, oneway);
2096
2097 // -------- cancel dashes -------
2098 if (e->u.polyline.dash_num > 0)
2099 {
2100 int dummy_1[1];
2101 dummy_1[0]=0;
2102 graphics_gc_set_dashes(gra, gc, e->u.polyline.width, e->u.polyline.offset, dummy_1, e->u.polyline.dash_num, order);
2103 }
2104 // -------- cancel dashes -------
1850 } 2105 }
1851 break; 2106 break;
1852 case element_circle: 2107 case element_circle:
1853 if (count) 2108 if (count)
1854 {
1855 if (e->u.circle.width > 1)
1856 gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
1857
1858 graphics_draw_circle(gra, gc, pa, e->u.circle.radius);
1859
1860 if (di->label && e->text_size)
1861 { 2109 {
1862 struct graphics_font *font=get_font(gra, e->text_size); 2110 if (e->u.circle.width > 1)
1863 struct graphics_gc *gc_background=dc->gc_background; 2111 {
1864 if (! gc_background && e->u.circle.background_color.a) { 2112 gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
1865 gc_background=graphics_gc_new(gra);
1866 graphics_gc_set_foreground(gc_background, &e->u.circle.background_color);
1867 dc->gc_background=gc_background;
1868 } 2113 }
2114
2115 graphics_draw_circle(gra, gc, pa, e->u.circle.radius);
2116
2117 if (di->label && e->text_size)
2118 {
2119 struct graphics_font *font = get_font(gra, e->text_size);
2120 struct graphics_gc *gc_background = dc->gc_background;
2121 if (!gc_background && e->u.circle.background_color.a)
2122 {
2123 gc_background = graphics_gc_new(gra);
2124 graphics_gc_set_foreground(gc_background, &e->u.circle.background_color);
2125 dc->gc_background = gc_background;
2126 }
1869 p.x=pa[0].x+3; 2127 p.x = pa[0].x + 3;
1870 p.y=pa[0].y+10; 2128 p.y = pa[0].y + 10;
2129
2130 if (font)
2131 {
2132 gra->meth.draw_text(gra->priv, gc->priv, gc_background ? gc_background->priv : NULL, font->priv, di->label, &p, 0x10000, 0);
2133 }
2134 else
2135 {
2136 //DBG dbg(0, "Failed to get font with size %d\n", e->text_size);
2137 }
2138 }
2139 }
2140 break;
2141 case element_text:
2142 if (count && di->label)
2143 {
2144 struct graphics_font *font = get_font(gra, e->text_size);
2145 struct graphics_gc *gc_background = dc->gc_background;
2146
2147 if (!gc_background && e->u.text.background_color.a)
2148 {
2149 gc_background = graphics_gc_new(gra);
2150 graphics_gc_set_foreground(gc_background, &e->u.text.background_color);
2151 dc->gc_background = gc_background;
2152 }
1871 2153
1872 if (font) 2154 if (font)
1873 gra->meth.draw_text(gra->priv, gc->priv, gc_background?gc_background->priv:NULL, font->priv, di->label, &p, 0x10000, 0);
1874 else
1875 dbg(0,"Failed to get font with size %d\n",e->text_size);
1876 }
1877 }
1878 break;
1879 case element_text:
1880 if (count && di->label)
1881 {
1882 struct graphics_font *font=get_font(gra, e->text_size);
1883 struct graphics_gc *gc_background=dc->gc_background;
1884
1885 if (! gc_background && e->u.text.background_color.a)
1886 {
1887 gc_background=graphics_gc_new(gra);
1888 graphics_gc_set_foreground(gc_background, &e->u.text.background_color);
1889 dc->gc_background=gc_background;
1890 }
1891
1892 if (font)
1893 label_line(gra, gc, gc_background, font, pa, count, di->label);
1894 else
1895 dbg(0,"Failed to get font with size %d\n",e->text_size);
1896 }
1897 break;
1898 case element_icon:
1899 if (count)
1900 {
1901 if (!img || item_is_custom_poi(di->item))
1902 {
1903 if (item_is_custom_poi(di->item))
1904 { 2155 {
1905 char *icon; 2156 label_line(gra, gc, gc_background, font, pa, count, di->label);
1906 char *src;
1907 if (img)
1908 graphics_image_free(dc->gra, img);
1909 src=e->u.icon.src;
1910 if (!src || !src[0])
1911 src="%s";
1912 icon=g_strdup_printf(src,di->label+strlen(di->label)+1);
1913 path=graphics_icon_path(icon);
1914 g_free(icon);
1915 } 2157 }
1916 else 2158 else
1917 { 2159 {
1918 path=graphics_icon_path(e->u.icon.src); 2160 //DBG dbg(0, "Failed to get font with size %d\n", e->text_size);
1919 } 2161 }
2162 }
2163 break;
2164 case element_icon:
2165 if (count)
2166 {
2167 if (!img || item_is_custom_poi(di->item))
2168 {
2169 if (item_is_custom_poi(di->item))
2170 {
2171 char *icon;
2172 char *src;
2173 if (img)
2174 {
2175 graphics_image_free(dc->gra, img);
2176 }
2177 src = e->u.icon.src;
2178 if (!src || !src[0])
2179 {
2180 src = "%s";
2181 }
2182 icon = g_strdup_printf(src, di->label + strlen(di->label) + 1);
2183 path = graphics_icon_path(icon);
2184 g_free(icon);
2185 }
2186 else
2187 {
2188 path = graphics_icon_path(e->u.icon.src);
2189 }
1920 img=graphics_image_new_scaled_rotated(gra, path, e->u.icon.width, e->u.icon.height, e->u.icon.rotation); 2190 img = graphics_image_new_scaled_rotated(gra, path, e->u.icon.width, e->u.icon.height, e->u.icon.rotation);
2191 if (img)
2192 {
2193 dc->img = img;
2194 }
2195 else
2196 {
2197 dbg(0, "-- ICON MISSING -- failed to load icon '%s'\n", path);
2198 }
2199 g_free(path);
2200 }
2201
1921 if (img) 2202 if (img)
1922 dc->img=img; 2203 {
1923 else 2204 p.x = pa[0].x - img->hot.x;
2205 p.y = pa[0].y - img->hot.y;
1924 dbg(0,"failed to load icon '%s'\n", path); 2206 //dbg(0, "icon: '%s'\n", path);
1925 g_free(path); 2207 //dbg(0,"hot: %d %d\n", img->hot.x, img->hot.y);
2208 gra->meth.draw_image(gra->priv, gra->gc[0]->priv, &p, img->priv);
2209 }
1926 } 2210 }
1927 if (img) 2211 break;
2212 case element_image:
2213 //dbg(0, "image: '%s'\n", di->label);
2214 if (gra->meth.draw_image_warp)
2215 gra->meth.draw_image_warp(gra->priv, gra->gc[0]->priv, pa, count, di->label);
2216 else
1928 { 2217 {
1929 p.x=pa[0].x - img->hot.x; 2218 // dbg(0,"draw_image_warp not supported by graphics driver drawing '%s'\n",di->label);
1930 p.y=pa[0].y - img->hot.y; 2219 }
2220 break;
2221 case element_arrows:
2222 display_draw_arrows(gra, gc, pa, count);
2223 break;
2224 default:
2225 printf("Unhandled element type %d\n", e->type);
2226
2227 }
2228 di = di->next;
2229 }
2230}
2231/**
2232 * FIXME
2233 * @param <>
2234 * @returns <>
2235 * @author Martin Schaller (04/2008)
2236 */
2237static void xdisplay_draw_elements(struct graphics *gra, struct displaylist *display_list, struct itemgra *itm)
2238{
2239 //dbg(0,"Enter\n");
2240
2241 struct element *e;
2242 GList *es, *types;
2243 struct display_context *dc = &display_list->dc;
2244 struct hash_entry *entry;
2245
2246 es = itm->elements;
2247 while (es)
2248 {
2249 //dbg(0,"*es\n");
2250 e = es->data;
2251 dc->e = e;
2252 types = itm->type;
2253 while (types)
2254 {
2255 dc->type = GPOINTER_TO_INT(types->data);
2256 // dbg(0,"**type=%d\n", dc->type);
2257 entry = get_hash_entry(display_list, dc->type);
2258 if (entry && entry->di)
2259 {
2260 //dbg(0,"++type=%s\n", item_to_name(dc->type));
2261 displayitem_draw(entry->di, NULL, dc, display_list->order, 1);
2262 //dbg(0,"**+gc free\n");
2263 display_context_free(dc);
2264 }
2265 types = g_list_next(types);
2266 }
2267 es = g_list_next(es);
2268 }
2269}
2270
2271void graphics_draw_itemgra(struct graphics *gra, struct itemgra *itm, struct transformation *t, char *label)
2272{
2273 ////DBG dbg(0,"ooo enter ooo\n");
2274
2275 // HINT: seems to only be called from vehicle.c (draw the vehicle on screen)
2276
2277 GList *es;
2278 struct display_context dc;
2279 int max_coord = 32;
2280 char *buffer = g_alloca(sizeof(struct displayitem) + max_coord * sizeof(struct coord));
2281 struct displayitem *di = (struct displayitem *) buffer;
2282 es = itm->elements;
2283 di->item.type = type_none;
2284 di->item.id_hi = 0;
2285 di->item.id_lo = 0;
2286 di->item.map = NULL;
2287 di->label = label;
2288 dc.gra = gra;
2289 dc.gc = NULL;
2290 dc.gc_background = NULL;
2291 dc.img = NULL;
2292 dc.pro = projection_screen;
2293 dc.mindist = 0;
2294 dc.trans = t;
2295 dc.type = type_none;
2296 dc.maxlen = max_coord;
2297 while (es)
2298 {
2299 struct element *e = es->data;
2300 if (e->coord_count)
2301 {
2302 if (e->coord_count > max_coord)
2303 {
2304 //DBG dbg(0, "maximum number of coords reached: %d > %d\n", e->coord_count, max_coord);
2305 di->count = max_coord;
2306 }
2307 else
2308 di->count = e->coord_count;
2309 memcpy(di->c, e->coord, di->count * sizeof(struct coord));
2310 }
2311 else
2312 {
2313 di->c[0].x = 0;
2314 di->c[0].y = 0;
2315 di->count = 1;
2316 }
2317 dc.e = e;
2318 di->next = NULL;
2319 displayitem_draw(di, NULL, &dc, transform_get_scale(t), 0);
2320 display_context_free(&dc);
2321 es = g_list_next(es);
2322 }
2323}
2324
2325/**
2326 * FIXME
2327 * @param <>
2328 * @returns <>
2329 * @author Martin Schaller (04/2008)
2330 */
2331static void xdisplay_draw_layer(struct displaylist *display_list, struct graphics *gra, struct layer *lay, int order)
2332{
2333 //DBG dbg(0,"ooo enter ooo\n");
2334
2335 GList *itms;
2336 struct itemgra *itm;
2337 int order_corrected = order;
2338 if (order_corrected < limit_order_corrected)
2339 {
2340 order_corrected = limit_order_corrected;
2341 }
2342 int order_corrected_2 = order;
2343 if (order < 0)
2344 {
2345 order_corrected_2 = 0;
2346 }
2347
2348 //dbg(0,"layer name=%s\n", lay->name);
2349
2350 itms = lay->itemgras;
2351 while (itms)
2352 {
2353 // stop drawing is requested
2354 if (cancel_drawing_global == 1)
2355 {
2356 //DBG dbg(0, "** STOP MD 002 **\n");
2357 break;
2358 }
2359
2360 itm = itms->data;
2361 //if (order_corrected >= itm->order.min && order_corrected <= itm->order.max)
2362 if (order_corrected_2 >= itm->order.min && order_corrected_2 <= itm->order.max)
2363 {
2364 xdisplay_draw_elements(gra, display_list, itm);
2365 }
2366 itms = g_list_next(itms);
2367 }
2368
2369 if (strncmp("streets__tunnel", lay->name, 15) == 0)
2370 {
2371 }
2372 else if (strncmp("streets__bridge", lay->name, 15) == 0)
2373 {
2374 }
2375 // dirty hack to draw "waypoint(s)" ---------------------------
2376 else if (strncmp("Internal", lay->name, 8) == 0)
2377 {
2378 if (global_navit->route)
2379 {
2380 if (global_navit->destination_valid == 1)
2381 {
2382 int count_ = 0;
2383 int curr_ = 0;
2384 count_ = g_list_length(global_navit->route->destinations);
2385 if (count_ > 1)
2386 {
2387 if (!global_img_waypoint)
2388 {
2389 char *path2;
2390 path2 = graphics_icon_path("nav_waypoint_bk_center.png");
2391 global_img_waypoint = graphics_image_new_scaled_rotated(gra, path2, 59, 59, 0);
2392 g_free(path2);
2393 }
2394
2395 struct point p2;
2396 struct coord pc77;
2397 GList *ldest = global_navit->route->destinations;
2398 while (ldest)
2399 {
2400 curr_++;
2401 if (curr_ < count_)
2402 {
2403 struct route_info *dst = ldest->data;
2404 pc77.x = dst->c.x;
2405 pc77.y = dst->c.y;
2406 //dbg(0, "draw1 curr=%d x y: %d %d\n", curr_, dst->c.x, dst->c.y);
2407 enum projection pro = transform_get_projection(global_navit->trans_cursor);
2408 transform(global_navit->trans, pro, &pc77, &p2, 1, 0, 0, NULL);
2409 // transform(global_navit->trans, projection_mg, &pc77, &p2, 1, 0, 0, NULL);
2410 p2.x = p2.x - global_img_waypoint->hot.x; // hot = 29
2411 p2.y = p2.y - global_img_waypoint->hot.y; // hot = 29
1931 gra->meth.draw_image(gra->priv, gra->gc[0]->priv, &p, img->priv); 2412 gra->meth.draw_image(gra->priv, gra->gc[0]->priv, &p2, global_img_waypoint->priv);
2413 }
2414 // next dest. / waypoint
2415 ldest=g_list_next(ldest);
2416 }
1932 } 2417 }
1933 } 2418 }
1934 break;
1935 case element_image:
1936 dbg(1,"image: '%s'\n", di->label);
1937 if (gra->meth.draw_image_warp)
1938 gra->meth.draw_image_warp(gra->priv, gra->gc[0]->priv, pa, count, di->label);
1939 else
1940 dbg(0,"draw_image_warp not supported by graphics driver drawing '%s'\n", di->label);
1941 break;
1942 case element_arrows:
1943 display_draw_arrows(gra,gc,pa,count);
1944 break;
1945 default:
1946 printf("Unhandled element type %d\n", e->type);
1947
1948 }
1949 di=di->next;
1950 }
1951}
1952/**
1953 * FIXME
1954 * @param <>
1955 * @returns <>
1956 * @author Martin Schaller (04/2008)
1957*/
1958static void xdisplay_draw_elements(struct graphics *gra, struct displaylist *display_list, struct itemgra *itm)
1959{
1960
1961 struct element *e;
1962 GList *es,*types;
1963 struct display_context *dc=&display_list->dc;
1964 struct hash_entry *entry;
1965
1966 es=itm->elements;
1967 while (es)
1968 {
1969 e=es->data;
1970 dc->e=e;
1971 types=itm->type;
1972 while (types)
1973 {
1974 dc->type=GPOINTER_TO_INT(types->data);
1975 entry=get_hash_entry(display_list, dc->type);
1976 if (entry && entry->di)
1977 {
1978 displayitem_draw(entry->di, NULL, dc, display_list->order, 1);
1979 display_context_free(dc);
1980 } 2419 }
1981 types=g_list_next(types);
1982 } 2420 }
1983 es=g_list_next(es); 2421 // dirty hack to draw "waypoint(s)" ---------------------------
1984 }
1985} 2422}
1986 2423
1987void
1988graphics_draw_itemgra(struct graphics *gra, struct itemgra *itm, struct transformation *t, char *label)
1989{
1990 //dbg(0,"ooo enter ooo\n");
1991
1992 // HINT: seems to only be called from vehicle.c (draw the vehicle on screen)
1993
1994 GList *es;
1995 struct display_context dc;
1996 int max_coord=32;
1997 char *buffer=g_alloca(sizeof(struct displayitem)+max_coord*sizeof(struct coord));
1998 struct displayitem *di=(struct displayitem *)buffer;
1999 es=itm->elements;
2000 di->item.type=type_none;
2001 di->item.id_hi=0;
2002 di->item.id_lo=0;
2003 di->item.map=NULL;
2004 di->label=label;
2005 dc.gra=gra;
2006 dc.gc=NULL;
2007 dc.gc_background=NULL;
2008 dc.img=NULL;
2009 dc.pro=projection_screen;
2010 dc.mindist=0;
2011 dc.trans=t;
2012 dc.type=type_none;
2013 dc.maxlen=max_coord;
2014 while (es) {
2015 struct element *e=es->data;
2016 if (e->coord_count) {
2017 if (e->coord_count > max_coord) {
2018 dbg(0,"maximum number of coords reached: %d > %d\n",e->coord_count,max_coord);
2019 di->count=max_coord;
2020 } else
2021 di->count=e->coord_count;
2022 memcpy(di->c, e->coord, di->count*sizeof(struct coord));
2023 } else {
2024 di->c[0].x=0;
2025 di->c[0].y=0;
2026 di->count=1;
2027 }
2028 dc.e=e;
2029 di->next=NULL;
2030 displayitem_draw(di, NULL, &dc,transform_get_scale(t), 0);
2031 display_context_free(&dc);
2032 es=g_list_next(es);
2033 }
2034}
2035
2036/** 2424/**
2037 * FIXME 2425 * FIXME
2038 * @param <> 2426 * @param <>
2039 * @returns <> 2427 * @returns <>
2040 * @author Martin Schaller (04/2008) 2428 * @author Martin Schaller (04/2008)
2041*/ 2429 */
2042static void xdisplay_draw_layer(struct displaylist *display_list, struct graphics *gra, struct layer *lay, int order)
2043{
2044 //dbg(0,"ooo enter ooo\n");
2045
2046 GList *itms;
2047 struct itemgra *itm;
2048 int order_corrected=order;
2049 if (order_corrected < 0)
2050 {
2051 order_corrected=0;
2052 }
2053
2054 itms=lay->itemgras;
2055 while (itms)
2056 {
2057 itm=itms->data;
2058 if (order_corrected >= itm->order.min && order_corrected <= itm->order.max)
2059 {
2060 xdisplay_draw_elements(gra, display_list, itm);
2061 }
2062 itms=g_list_next(itms);
2063 }
2064}
2065
2066
2067
2068
2069/**
2070 * FIXME
2071 * @param <>
2072 * @returns <>
2073 * @author Martin Schaller (04/2008)
2074*/
2075static void xdisplay_draw(struct displaylist *display_list, struct graphics *gra, struct layout *l, int order) 2430static void xdisplay_draw(struct displaylist *display_list, struct graphics *gra, struct layout *l, int order)
2076{ 2431{
2077 //dbg(0,"ooo enter ooo\n"); 2432 ////DBG dbg(0,"ooo enter ooo\n");
2078 2433
2079 GList *lays; 2434 GList *lays;
2080 struct layer *lay; 2435 struct layer *lay;
2081 2436
2082 //dbg(0,"draw prerender map for drag!!\n"); 2437 ////DBG dbg(0,"draw prerender map for drag!!\n");
2083 2438
2084 2439
2085 int draw_vector_map=1; 2440 int draw_vector_map = 1;
2086 2441
2087 // if zoomed out too much then use prerendered map tiles 2442 // if zoomed out too much then use prerendered map tiles
2088 if (display_list->order < ORDER_USE_PRERENDERED_MAP ) 2443 if (display_list->order < ORDER_USE_PRERENDERED_MAP)
2089 { 2444 {
2090 draw_vector_map=0; 2445 draw_vector_map = 0;
2091 } 2446 }
2092 2447
2093 //dbg(0,"ooo %d %d %d\n",display_list->order_hashed,ORDER_USE_PRERENDERED_MAP,draw_vector_map); 2448 ////DBG dbg(0,"ooo %d %d %d\n",display_list->order_hashed,ORDER_USE_PRERENDERED_MAP,draw_vector_map);
2094 //dbg(0,"ooo xxx ooo2\n"); 2449 ////DBG dbg(0,"ooo xxx ooo2\n");
2095 2450
2096 if (!draw_vector_map) 2451 if (!draw_vector_map)
2097 { 2452 {
2098 // draw prerendered big mapimage --- HERE --- 2453 // draw prerendered big mapimage --- HERE ---
2099 2454
2100 //dbg(0,"###### order=%d\n",display_list->order); 2455 ////DBG dbg(0,"###### order=%d\n",display_list->order);
2101 struct transformation *t; 2456 struct transformation *t;
2102 t=display_list->dc.trans; 2457 t = display_list->dc.trans;
2103 //dbg(0,"###### screen center x=%d\n",t->screen_center.x); 2458 ////DBG dbg(0,"###### screen center x=%d\n",t->screen_center.x);
2104 //dbg(0,"###### screen center y=%d\n",t->screen_center.y); 2459 ////DBG dbg(0,"###### screen center y=%d\n",t->screen_center.y);
2105 2460
2106 struct coord *cp; 2461 struct coord *cp;
2107 cp=transform_get_center(t); 2462 cp = transform_get_center(t);
2108 //dbg(0,"###### t center x=%d\n",cp->x); 2463 ////DBG dbg(0,"###### t center x=%d\n",cp->x);
2109 //dbg(0,"###### t center y=%d\n",cp->y); 2464 ////DBG dbg(0,"###### t center y=%d\n",cp->y);
2110 2465
2111 struct attr attr; 2466 struct attr attr;
2112 struct config { 2467 struct config
2468 {
2113 struct attr **attrs; 2469 struct attr **attrs;
2114 struct callback_list *cbl; 2470 struct callback_list *cbl;
2115 } *config; 2471 }*config;
2116 struct point p; 2472 struct point p;
2117 int valid=0; 2473 int valid = 0;
2118 // config_get_attr(config, attr_navit, &attr, NULL); 2474 // config_get_attr(config, attr_navit, &attr, NULL);
2119 if (global_navit) 2475 if (global_navit)
2120 { 2476 {
2121 if ((global_navit->vehicle)&&(global_navit->vehicle->vehicle)) 2477 if ((global_navit->vehicle) && (global_navit->vehicle->vehicle))
2122 { 2478 {
2123 //dbg(0,"###### v x=%d\n",p.x); 2479 ////DBG dbg(0,"###### v x=%d\n",p.x);
2124 //dbg(0,"###### v y=%d\n",p.y); 2480 ////DBG dbg(0,"###### v y=%d\n",p.y);
2125 2481
2126 //dbg(0,"###### v2 x=%d\n",global_vehicle_pos_onscreen.x); 2482 ////DBG dbg(0,"###### v2 x=%d\n",global_vehicle_pos_onscreen.x);
2127 //dbg(0,"###### v2 y=%d\n",global_vehicle_pos_onscreen.y); 2483 ////DBG dbg(0,"###### v2 y=%d\n",global_vehicle_pos_onscreen.y);
2128 2484
2129 //dbg(0,"### vf x=%d\n",global_navit->vehicle->last.x); 2485 ////DBG dbg(0,"### vf x=%d\n",global_navit->vehicle->last.x);
2130 //dbg(0,"### vf y=%d\n",global_navit->vehicle->last.y); 2486 ////DBG dbg(0,"### vf y=%d\n",global_navit->vehicle->last.y);
2131 2487
2132 //dbg(0,"### vff x=%d\n",global_navit->vehicle->coord.x); 2488 ////DBG dbg(0,"### vff x=%d\n",global_navit->vehicle->coord.x);
2133 //dbg(0,"### vff y=%d\n",global_navit->vehicle->coord.y); 2489 ////DBG dbg(0,"### vff y=%d\n",global_navit->vehicle->coord.y);
2134 2490
2135 int a,s; 2491 int a, s;
2136 struct point pnt2; 2492 struct point pnt2;
2137 vehicle_get_cursor_data(global_navit->vehicle->vehicle, &pnt2, &a, &s); 2493 vehicle_get_cursor_data(global_navit->vehicle->vehicle, &pnt2, &a, &s);
2138 //dbg(0,"### vf 2 x=%d\n",pnt2.x); 2494 ////DBG dbg(0,"### vf 2 x=%d\n",pnt2.x);
2139 //dbg(0,"### vf 2 y=%d\n",pnt2.y); 2495 ////DBG dbg(0,"### vf 2 y=%d\n",pnt2.y);
2140 //global_vehicle_pos_onscreen.x=pnt2.x; 2496 //global_vehicle_pos_onscreen.x=pnt2.x;
2141 //global_vehicle_pos_onscreen.y=pnt2.y; 2497 //global_vehicle_pos_onscreen.y=pnt2.y;
2142 2498
2143 2499
2144
2145 struct attr pos_attr; 2500 struct attr pos_attr;
2146 if (vehicle_get_attr(global_navit->vehicle->vehicle,attr_position_coord_geo,&pos_attr,NULL)) 2501 if (vehicle_get_attr(global_navit->vehicle->vehicle, attr_position_coord_geo, &pos_attr, NULL))
2147 { 2502 {
2148 //dbg(0,"1 lat=%f, lng=%f\n",pos_attr.u.coord_geo->lat,pos_attr.u.coord_geo->lng); 2503 ////DBG dbg(0,"1 lat=%f, lng=%f\n",pos_attr.u.coord_geo->lat,pos_attr.u.coord_geo->lng);
2149 } 2504 }
2150 2505
2151 valid=1; 2506 valid = 1;
2152 } 2507 }
2153 } 2508 }
2154 2509
2155 //dbg(0,"###### yaw=%d\n",-t->yaw); 2510 ////DBG dbg(0,"###### yaw=%d\n",-t->yaw);
2156 struct coord *c; 2511 struct coord *c;
2157 c=&(t->map_center); 2512 c = &(t->map_center);
2158 //dbg(0,"###### map center x=%d\n",c->x); 2513 ////DBG dbg(0,"###### map center x=%d\n",c->x);
2159 //dbg(0,"###### map center y=%d\n",c->y); 2514 ////DBG dbg(0,"###### map center y=%d\n",c->y);
2160 2515
2161 enum projection pro=transform_get_projection(global_navit->trans_cursor); 2516 enum projection pro = transform_get_projection(global_navit->trans_cursor);
2162 struct coord_geo g22; 2517 struct coord_geo g22;
2163 struct coord *c22; 2518 struct coord *c22;
2164 struct point mcenter_pnt; 2519 struct point mcenter_pnt;
2165 c22=&(t->map_center); 2520 c22 = &(t->map_center);
2166 transform_to_geo(projection_mg, c22, &g22); 2521 transform_to_geo(projection_mg, c22, &g22);
2167 //dbg(0,"2 lat=%f, lng=%f\n",g22.lat,g22.lng); 2522 ////DBG dbg(0,"2 lat=%f, lng=%f\n",g22.lat,g22.lng);
2168 transform(global_navit->trans, pro, c22, &mcenter_pnt, 1, 0, 0, NULL); 2523 transform(global_navit->trans, pro, c22, &mcenter_pnt, 1, 0, 0, NULL);
2169 //dbg(0,"xxx 5 44444xxxx=%d\n",mcenter_pnt.x); 2524 ////DBG dbg(0,"xxx 5 44444xxxx=%d\n",mcenter_pnt.x);
2170 //dbg(0,"yyy 5 44444yyyy=%d\n",mcenter_pnt.y); 2525 ////DBG dbg(0,"yyy 5 44444yyyy=%d\n",mcenter_pnt.y);
2171 2526
2172 2527
2173 struct coord c99; 2528 struct coord c99;
2174 struct coord_geo g99; 2529 struct coord_geo g99;
2175 struct point cursor_pnt; 2530 struct point cursor_pnt;
2176 struct point p99; 2531 struct point p99;
2177 2532
2178 /* 2533 /*
2179 g99.lat=79.0; 2534 g99.lat=79.0;
2180 g99.lng=-170.0; 2535 g99.lng=-170.0;
2536 transform_from_geo(pro, &g99, &c99);
2537 //DBG dbg(0,"left top lat=%f, lng=%f, x=%d y=%d\n",g99.lat,g99.lng,c99.x,c99.y);
2538 ////DBG dbg(0,"left top lat=%f, lng=%f, x=%f y=%f\n",g99.lat,g99.lng,c99.x,c99.y);
2539 ////DBG dbg(0,"0x%x,0x%x\n",c99.x,c99.y);
2540 transform(global_navit->trans, pro, &c99, &cursor_pnt, 1, 0, 0, NULL);
2541 //DBG dbg(0,"xxxxxxx=%d\n",cursor_pnt.x);
2542 //DBG dbg(0,"yyyyyyy=%d\n",cursor_pnt.y);
2543
2544 g99.lat=-79.0;
2545 g99.lng=170.0;
2546 transform_from_geo(pro, &g99, &c99);
2547 //DBG dbg(0,"right bottom lat=%f, lng=%f, x=%d y=%d\n",g99.lat,g99.lng,c99.x,c99.y);
2548 ////DBG dbg(0,"right bottom lat=%f, lng=%f, x=%f y=%f\n",g99.lat,g99.lng,c99.x,c99.y);
2549 transform(global_navit->trans, pro, &c99, &cursor_pnt, 1, 0, 0, NULL);
2550 //DBG dbg(0,"xxxxxxx=%d\n",cursor_pnt.x);
2551 //DBG dbg(0,"yyyyyyy=%d\n",cursor_pnt.y);
2552 */
2553
2554 g99.lat = 0.0;
2555 g99.lng = 0.0;
2181 transform_from_geo(pro, &g99, &c99); 2556 transform_from_geo(pro, &g99, &c99);
2182 dbg(0,"left top lat=%f, lng=%f, x=%d y=%d\n",g99.lat,g99.lng,c99.x,c99.y); 2557 ////DBG dbg(0,"center center lat=%f, lng=%f, x=%d y=%d\n",g99.lat,g99.lng,c99.x,c99.y);
2183 //dbg(0,"left top lat=%f, lng=%f, x=%f y=%f\n",g99.lat,g99.lng,c99.x,c99.y); 2558 ////DBG dbg(0,"center center lat=%f, lng=%f, x=%f y=%f\n",g99.lat,g99.lng,c99.x,c99.y);
2184 //dbg(0,"0x%x,0x%x\n",c99.x,c99.y);
2185 transform(global_navit->trans, pro, &c99, &cursor_pnt, 1, 0, 0, NULL); 2559 transform(global_navit->trans, pro, &c99, &cursor_pnt, 1, 0, 0, NULL);
2186 dbg(0,"xxxxxxx=%d\n",cursor_pnt.x);
2187 dbg(0,"yyyyyyy=%d\n",cursor_pnt.y);
2188
2189 g99.lat=-79.0;
2190 g99.lng=170.0;
2191 transform_from_geo(pro, &g99, &c99);
2192 dbg(0,"right bottom lat=%f, lng=%f, x=%d y=%d\n",g99.lat,g99.lng,c99.x,c99.y);
2193 //dbg(0,"right bottom lat=%f, lng=%f, x=%f y=%f\n",g99.lat,g99.lng,c99.x,c99.y);
2194 transform(global_navit->trans, pro, &c99, &cursor_pnt, 1, 0, 0, NULL);
2195 dbg(0,"xxxxxxx=%d\n",cursor_pnt.x);
2196 dbg(0,"yyyyyyy=%d\n",cursor_pnt.y);
2197 */
2198
2199 g99.lat=0.0;
2200 g99.lng=0.0;
2201 transform_from_geo(pro, &g99, &c99);
2202 //dbg(0,"center center lat=%f, lng=%f, x=%d y=%d\n",g99.lat,g99.lng,c99.x,c99.y);
2203 //dbg(0,"center center lat=%f, lng=%f, x=%f y=%f\n",g99.lat,g99.lng,c99.x,c99.y);
2204 transform(global_navit->trans, pro, &c99, &cursor_pnt, 1, 0, 0, NULL);
2205 //dbg(0,"xxx44444xxxx=%d\n",cursor_pnt.x); 2560 ////DBG dbg(0,"xxx44444xxxx=%d\n",cursor_pnt.x);
2206 //dbg(0,"yyy44444yyyy=%d\n",cursor_pnt.y); 2561 ////DBG dbg(0,"yyy44444yyyy=%d\n",cursor_pnt.y);
2207 2562
2208 //struct coord *c77; 2563 //struct coord *c77;
2209 //c77=&(t->map_center); 2564 //c77=&(t->map_center);
2210 //transform(global_navit->trans, pro, &c77, &cursor_pnt, 1, 0, 0, NULL); 2565 //transform(global_navit->trans, pro, &c77, &cursor_pnt, 1, 0, 0, NULL);
2211 //dbg(0,"---> cx=%d\n",cursor_pnt.x); 2566 ////DBG dbg(0,"---> cx=%d\n",cursor_pnt.x);
2212 //dbg(0,"---> cy=%d\n",cursor_pnt.y); 2567 ////DBG dbg(0,"---> cy=%d\n",cursor_pnt.y);
2213 2568
2214 2569
2215 // now really draw it 2570 // now really draw it
2216 struct graphics *gra22=display_list->dc.gra; 2571 struct graphics *gra22 = display_list->dc.gra;
2217 struct graphics_gc *gc22=display_list->dc.gc; 2572 struct graphics_gc *gc22 = display_list->dc.gc;
2218 if (! gc22) 2573 if (!gc22)
2219 { 2574 {
2220 gc22=graphics_gc_new(gra22); 2575 gc22 = graphics_gc_new(gra22);
2221 } 2576 }
2222 // graphics_draw_bigmap(gra22, gc22, -t->yaw, display_list->order, g22.lat, g22.lng, c->x, c->y, t->screen_center.x, t->screen_center.y, global_vehicle_pos_onscreen.x, global_vehicle_pos_onscreen.y, valid); 2577 // graphics_draw_bigmap(gra22, gc22, -t->yaw, display_list->order, g22.lat, g22.lng, c->x, c->y, t->screen_center.x, t->screen_center.y, global_vehicle_pos_onscreen.x, global_vehicle_pos_onscreen.y, valid);
2223 graphics_draw_bigmap(gra22, gc22, -t->yaw, display_list->order, g22.lat, g22.lng, cursor_pnt.x, cursor_pnt.y, mcenter_pnt.x, mcenter_pnt.y, global_vehicle_pos_onscreen.x, global_vehicle_pos_onscreen.y, valid); 2578 graphics_draw_bigmap(gra22, gc22, -t->yaw, display_list->order, g22.lat, g22.lng, cursor_pnt.x, cursor_pnt.y, mcenter_pnt.x, mcenter_pnt.y, global_vehicle_pos_onscreen.x, global_vehicle_pos_onscreen.y, valid);
2224 } 2579 }
2225 2580
2581 ////DBG dbg(0, "XXXXXYYYYYYY Draw: 001\n");
2226 2582
2583 // reset value;
2584 cancel_drawing_global = 0;
2227 2585
2228 lays=l->layers; 2586 lays = l->layers;
2229 while (lays) { 2587 while (lays)
2588 {
2230 lay=lays->data; 2589 lay = lays->data;
2231 if (lay->active) 2590 if (lay->active)
2591 {
2232 xdisplay_draw_layer(display_list, gra, lay, order); 2592 xdisplay_draw_layer(display_list, gra, lay, order);
2593 }
2233 lays=g_list_next(lays); 2594 lays = g_list_next(lays);
2595
2596 // stop drawing is requested
2597 if (cancel_drawing_global == 1)
2598 {
2599 //DBG dbg(0, "** STOP MD 003 **\n");
2600 break;
2234 } 2601 }
2602 }
2603
2604 // reset value;
2605 cancel_drawing_global = 0;
2606
2607 ////DBG dbg(0, "XXXXXYYYYYYY Draw: 002\n");
2235 2608
2236#ifdef HAVE_API_ANDROID 2609#ifdef HAVE_API_ANDROID
2237 android_return_generic_int(2, 1); 2610 android_return_generic_int(2, 1);
2238#endif 2611#endif
2239 2612
2242/** 2615/**
2243 * FIXME 2616 * FIXME
2244 * @param <> 2617 * @param <>
2245 * @returns <> 2618 * @returns <>
2246 * @author Martin Schaller (04/2008) 2619 * @author Martin Schaller (04/2008)
2247*/ 2620 */
2248extern void *route_selection; 2621extern void *route_selection;
2249 2622
2250static void
2251displaylist_update_layers(struct displaylist *displaylist, GList *layers, int order) 2623static void displaylist_update_layers(struct displaylist *displaylist, GList *layers, int order)
2252{ 2624{
2253 //dbg(0,"ooo enter ooo\n"); 2625 ////DBG dbg(0,"ooo enter ooo\n");
2254 2626
2255 int order_corrected=order; 2627 int order_corrected = order;
2256 //int saved=displaylist->order; 2628 //int saved=displaylist->order;
2257 if (order < 0) 2629 if (order < limit_order_corrected)
2258 { 2630 {
2259 order_corrected=0; 2631 order_corrected = limit_order_corrected;
2260 // displaylist->order=0; 2632 // displaylist->order=0;
2261 } 2633 }
2634
2262 while (layers) { 2635 while (layers)
2636 {
2263 struct layer *layer=layers->data; 2637 struct layer *layer = layers->data;
2264 GList *itemgras=layer->itemgras; 2638 GList *itemgras = layer->itemgras;
2265 while (itemgras) { 2639 while (itemgras)
2640 {
2266 struct itemgra *itemgra=itemgras->data; 2641 struct itemgra *itemgra = itemgras->data;
2267 GList *types=itemgra->type; 2642 GList *types = itemgra->type;
2268 if (itemgra->order.min <= order_corrected && itemgra->order.max >= order_corrected) 2643 if (itemgra->order.min <= order_corrected && itemgra->order.max >= order_corrected)
2269 { 2644 {
2270 while (types) { 2645 while (types)
2646 {
2271 enum item_type type=(enum item_type) types->data; 2647 enum item_type type = (enum item_type) types->data;
2272 set_hash_entry(displaylist, type); 2648 set_hash_entry(displaylist, type);
2273 types=g_list_next(types); 2649 types = g_list_next(types);
2274 } 2650 }
2275 } 2651 }
2276 itemgras=g_list_next(itemgras); 2652 itemgras = g_list_next(itemgras);
2277 } 2653 }
2278 layers=g_list_next(layers); 2654 layers = g_list_next(layers);
2279 } 2655 }
2280 // displaylist->order=saved; 2656 // displaylist->order=saved;
2281} 2657}
2282 2658
2283static void
2284displaylist_update_hash(struct displaylist *displaylist) 2659static void displaylist_update_hash(struct displaylist *displaylist)
2285{ 2660{
2286 //dbg(0,"ooo enter ooo\n"); 2661 ////DBG dbg(0,"ooo enter ooo\n");
2287 2662
2288 displaylist->max_offset=0; 2663 displaylist->max_offset = 0;
2289 clear_hash(displaylist); 2664 clear_hash(displaylist);
2290 displaylist_update_layers(displaylist, displaylist->layout->layers, displaylist->order); 2665 displaylist_update_layers(displaylist, displaylist->layout->layers, displaylist->order);
2291 dbg(1,"max offset %d\n",displaylist->max_offset); 2666 // dbg(1, "max offset %d\n", displaylist->max_offset);
2292} 2667}
2293 2668
2294static void
2295do_draw(struct displaylist *displaylist, int cancel, int flags) 2669static void do_draw(struct displaylist *displaylist, int cancel, int flags)
2296{ 2670{
2297 struct item *item; 2671 struct item *item;
2298 int count,max=displaylist->dc.maxlen,workload=0; 2672 int count, max = displaylist->dc.maxlen, workload = 0;
2299 struct coord *ca=g_alloca(sizeof(struct coord)*max); 2673 struct coord *ca = g_alloca(sizeof(struct coord) * max);
2300 struct attr attr,attr2; 2674 struct attr attr, attr2;
2301 enum projection pro; 2675 enum projection pro;
2302 int draw_vector_map=1; // do we draw the vecotor map, or not? 0=false, 1=true 2676 int draw_vector_map = 1; // do we draw the vecotor map, or not? 0=false, 1=true
2303 int mapset_counter=0; 2677 int mapset_counter = 0;
2304 int mapset_need_draw=0; 2678 int mapset_need_draw = 0;
2305 2679
2306 //dbg(0,"ooo enter ooo %d\n",displaylist->order); 2680 //DBG dbg(0,"ooo enter ooo %d\n",displaylist->order);
2307 2681
2308 int order_corrected=displaylist->order; 2682 int order_corrected = displaylist->order;
2309 int saved=displaylist->order; 2683 int saved = displaylist->order;
2310 if (order_corrected < 0) 2684 if (order_corrected < limit_order_corrected)
2311 { 2685 {
2312 order_corrected = 0; 2686 order_corrected = limit_order_corrected;
2313 } 2687 }
2314 2688
2315 if (displaylist->order != displaylist->order_hashed || displaylist->layout != displaylist->layout_hashed) 2689 if (displaylist->order != displaylist->order_hashed || displaylist->layout != displaylist->layout_hashed)
2316 { 2690 {
2317 displaylist_update_hash(displaylist); 2691 displaylist_update_hash(displaylist);
2318 displaylist->order_hashed=displaylist->order; 2692 displaylist->order_hashed = displaylist->order;
2319 displaylist->layout_hashed=displaylist->layout; 2693 displaylist->layout_hashed = displaylist->layout;
2320 2694
2321 // dbg(0,"-----====> order (zoom) = %d",displaylist->order); 2695 // //DBG dbg(0,"-----====> order (zoom) = %d",displaylist->order);
2322 // dbg(0,"-----====> order (zoom) = %d",displaylist->order_hashed); 2696 // //DBG dbg(0,"-----====> order (zoom) = %d",displaylist->order_hashed);
2323 // TODO // give new order (zoom) back to Java // TODO 2697 // TODO // give new order (zoom) back to Java // TODO
2324 } 2698 }
2325 2699
2326 profile(0,NULL); 2700 //profile(0, NULL);
2327 pro=transform_get_projection(displaylist->dc.trans); 2701 pro = transform_get_projection(displaylist->dc.trans);
2328 2702
2329 // dbg(0,"ooo xxx ooo1\n"); 2703 // //DBG dbg(0,"ooo xxx ooo1\n");
2330 // dbg(0,"ooo %d %d %d\n",displaylist->order_hashed,ORDER_USE_PRERENDERED_MAP,draw_vector_map); 2704 // //DBG dbg(0,"ooo %d %d %d\n",displaylist->order_hashed,ORDER_USE_PRERENDERED_MAP,draw_vector_map);
2331 2705
2332 // if zoomed out too much then use prerendered map tiles 2706 // if zoomed out too much then use prerendered map tiles
2333 if (displaylist->order_hashed < ORDER_USE_PRERENDERED_MAP ) 2707 if (displaylist->order_hashed < ORDER_USE_PRERENDERED_MAP)
2334 { 2708 {
2335 draw_vector_map=0; 2709 draw_vector_map = 0;
2336 } 2710 }
2337 2711
2338 // dbg(0,"ooo %d %d %d\n",displaylist->order_hashed,ORDER_USE_PRERENDERED_MAP,draw_vector_map); 2712 // //DBG dbg(0,"ooo %d %d %d\n",displaylist->order_hashed,ORDER_USE_PRERENDERED_MAP,draw_vector_map);
2339 // dbg(0,"ooo xxx ooo2\n"); 2713 // //DBG dbg(0,"ooo xxx ooo2\n");
2340 2714
2341 if (!draw_vector_map) 2715 if (!draw_vector_map)
2342 { 2716 {
2343 // draw prerendered big mapimage --- HERE --- 2717 // draw prerendered big mapimage --- HERE ---
2344 2718
2345 //dbg(0,"###### order=%d\n",displaylist->order_hashed); 2719 ////DBG dbg(0,"###### order=%d\n",displaylist->order_hashed);
2346 struct transformation *t; 2720 struct transformation *t;
2347 t=displaylist->dc.trans; 2721 t = displaylist->dc.trans;
2348 //dbg(0,"###### screen center x=%d\n",t->screen_center.x); 2722 ////DBG dbg(0,"###### screen center x=%d\n",t->screen_center.x);
2349 //dbg(0,"###### screen center y=%d\n",t->screen_center.y); 2723 ////DBG dbg(0,"###### screen center y=%d\n",t->screen_center.y);
2350 2724
2351 struct coord *cp; 2725 struct coord *cp;
2352 cp=transform_get_center(t); 2726 cp = transform_get_center(t);
2353 //dbg(0,"###### t center x=%d\n",cp->x); 2727 ////DBG dbg(0,"###### t center x=%d\n",cp->x);
2354 //dbg(0,"###### t center y=%d\n",cp->y); 2728 ////DBG dbg(0,"###### t center y=%d\n",cp->y);
2355 2729
2356 struct attr attr; 2730 struct attr attr;
2357 struct config { 2731 struct config
2732 {
2358 struct attr **attrs; 2733 struct attr **attrs;
2359 struct callback_list *cbl; 2734 struct callback_list *cbl;
2360 } *config; 2735 }*config;
2361 struct point p; 2736 struct point p;
2362 int valid=0; 2737 int valid = 0;
2363 // config_get_attr(config, attr_navit, &attr, NULL); 2738 // config_get_attr(config, attr_navit, &attr, NULL);
2364 if (global_navit) 2739 if (global_navit)
2365 { 2740 {
2366 if ((global_navit->vehicle)&&(global_navit->vehicle->vehicle)) 2741 if ((global_navit->vehicle) && (global_navit->vehicle->vehicle))
2367 { 2742 {
2368 //dbg(0,"###### v x=%d\n",p.x); 2743 ////DBG dbg(0,"###### v x=%d\n",p.x);
2369 //dbg(0,"###### v y=%d\n",p.y); 2744 ////DBG dbg(0,"###### v y=%d\n",p.y);
2370 2745
2371 //dbg(0,"###### v2 x=%d\n",global_vehicle_pos_onscreen.x); 2746 ////DBG dbg(0,"###### v2 x=%d\n",global_vehicle_pos_onscreen.x);
2372 //dbg(0,"###### v2 y=%d\n",global_vehicle_pos_onscreen.y); 2747 ////DBG dbg(0,"###### v2 y=%d\n",global_vehicle_pos_onscreen.y);
2373 2748
2374 //dbg(0,"### vf x=%d\n",global_navit->vehicle->last.x); 2749 ////DBG dbg(0,"### vf x=%d\n",global_navit->vehicle->last.x);
2375 //dbg(0,"### vf y=%d\n",global_navit->vehicle->last.y); 2750 ////DBG dbg(0,"### vf y=%d\n",global_navit->vehicle->last.y);
2376 2751
2377 //dbg(0,"### vff x=%d\n",global_navit->vehicle->coord.x); 2752 ////DBG dbg(0,"### vff x=%d\n",global_navit->vehicle->coord.x);
2378 //dbg(0,"### vff y=%d\n",global_navit->vehicle->coord.y); 2753 ////DBG dbg(0,"### vff y=%d\n",global_navit->vehicle->coord.y);
2379 2754
2380 int a,s; 2755 int a, s;
2381 struct point pnt2; 2756 struct point pnt2;
2382 vehicle_get_cursor_data(global_navit->vehicle->vehicle, &pnt2, &a, &s); 2757 vehicle_get_cursor_data(global_navit->vehicle->vehicle, &pnt2, &a, &s);
2383 //dbg(0,"### vf 2 x=%d\n",pnt2.x); 2758 ////DBG dbg(0,"### vf 2 x=%d\n",pnt2.x);
2384 //dbg(0,"### vf 2 y=%d\n",pnt2.y); 2759 ////DBG dbg(0,"### vf 2 y=%d\n",pnt2.y);
2385 //global_vehicle_pos_onscreen.x=pnt2.x; 2760 //global_vehicle_pos_onscreen.x=pnt2.x;
2386 //global_vehicle_pos_onscreen.y=pnt2.y; 2761 //global_vehicle_pos_onscreen.y=pnt2.y;
2387 2762
2388 struct attr pos_attr; 2763 struct attr pos_attr;
2389 if (vehicle_get_attr(global_navit->vehicle->vehicle,attr_position_coord_geo,&pos_attr,NULL)) 2764 if (vehicle_get_attr(global_navit->vehicle->vehicle, attr_position_coord_geo, &pos_attr, NULL))
2390 { 2765 {
2391 //dbg(0,"1 lat=%f, lng=%f\n",pos_attr.u.coord_geo->lat,pos_attr.u.coord_geo->lng); 2766 ////DBG dbg(0,"1 lat=%f, lng=%f\n",pos_attr.u.coord_geo->lat,pos_attr.u.coord_geo->lng);
2392 } 2767 }
2393 2768
2394 valid=1; 2769 valid = 1;
2395 } 2770 }
2396 } 2771 }
2397 2772
2398 //dbg(0,"###### yaw=%d\n",-t->yaw); 2773 //DBG dbg(0,"###### yaw=%d\n",-t->yaw);
2399 struct coord *c; 2774 struct coord *c;
2400 c=&(t->map_center); 2775 c = &(t->map_center);
2401 //dbg(0,"###### map center x=%d\n",c->x); 2776 //DBG dbg(0,"###### map center x=%d\n",c->x);
2402 //dbg(0,"###### map center y=%d\n",c->y); 2777 //DBG dbg(0,"###### map center y=%d\n",c->y);
2403 2778
2404 enum projection pro=transform_get_projection(global_navit->trans_cursor); 2779 enum projection pro = transform_get_projection(global_navit->trans_cursor);
2405 struct coord_geo g22; 2780 struct coord_geo g22;
2406 struct coord *c22; 2781 struct coord *c22;
2407 struct point mcenter_pnt; 2782 struct point mcenter_pnt;
2408 c22=&(t->map_center); 2783 c22 = &(t->map_center);
2409 transform_to_geo(projection_mg, c22, &g22); 2784 transform_to_geo(projection_mg, c22, &g22);
2410 //dbg(0,"2 lat=%f, lng=%f\n",g22.lat,g22.lng); 2785 ////DBG dbg(0,"2 lat=%f, lng=%f\n",g22.lat,g22.lng);
2411 transform(global_navit->trans, pro, c22, &mcenter_pnt, 1, 0, 0, NULL); 2786 transform(global_navit->trans, pro, c22, &mcenter_pnt, 1, 0, 0, NULL);
2412 //dbg(0,"xxx 5 33333xxxx=%d\n",mcenter_pnt.x); 2787 ////DBG dbg(0,"xxx 5 33333xxxx=%d\n",mcenter_pnt.x);
2413 //dbg(0,"yyy 5 33333yyyy=%d\n",mcenter_pnt.y); 2788 ////DBG dbg(0,"yyy 5 33333yyyy=%d\n",mcenter_pnt.y);
2414 2789
2415 2790
2416 struct coord c99; 2791 struct coord c99;
2417 struct coord_geo g99; 2792 struct coord_geo g99;
2418 struct point cursor_pnt; 2793 struct point cursor_pnt;
2419 struct point p99; 2794 struct point p99;
2420 2795
2421 /* 2796 /*
2422 g99.lat=79.0; 2797 g99.lat=79.0;
2423 g99.lng=-170.0; 2798 g99.lng=-170.0;
2799 transform_from_geo(pro, &g99, &c99);
2800 //DBG dbg(0,"left top lat=%f, lng=%f, x=%d y=%d\n",g99.lat,g99.lng,c99.x,c99.y);
2801 ////DBG dbg(0,"left top lat=%f, lng=%f, x=%f y=%f\n",g99.lat,g99.lng,c99.x,c99.y);
2802 ////DBG dbg(0,"0x%x,0x%x\n",c99.x,c99.y);
2803 transform(global_navit->trans, pro, &c99, &cursor_pnt, 1, 0, 0, NULL);
2804 //DBG dbg(0,"xxxxxxx=%d\n",cursor_pnt.x);
2805 //DBG dbg(0,"yyyyyyy=%d\n",cursor_pnt.y);
2806
2807 g99.lat=-79.0;
2808 g99.lng=170.0;
2809 transform_from_geo(pro, &g99, &c99);
2810 //DBG dbg(0,"right bottom lat=%f, lng=%f, x=%d y=%d\n",g99.lat,g99.lng,c99.x,c99.y);
2811 ////DBG dbg(0,"right bottom lat=%f, lng=%f, x=%f y=%f\n",g99.lat,g99.lng,c99.x,c99.y);
2812 transform(global_navit->trans, pro, &c99, &cursor_pnt, 1, 0, 0, NULL);
2813 //DBG dbg(0,"xxxxxxx=%d\n",cursor_pnt.x);
2814 //DBG dbg(0,"yyyyyyy=%d\n",cursor_pnt.y);
2815 */
2816
2817 g99.lat = 0.0;
2818 g99.lng = 0.0;
2424 transform_from_geo(pro, &g99, &c99); 2819 transform_from_geo(pro, &g99, &c99);
2425 dbg(0,"left top lat=%f, lng=%f, x=%d y=%d\n",g99.lat,g99.lng,c99.x,c99.y); 2820 ////DBG dbg(0,"center center lat=%f, lng=%f, x=%d y=%d\n",g99.lat,g99.lng,c99.x,c99.y);
2426 //dbg(0,"left top lat=%f, lng=%f, x=%f y=%f\n",g99.lat,g99.lng,c99.x,c99.y); 2821 ////DBG dbg(0,"center center lat=%f, lng=%f, x=%f y=%f\n",g99.lat,g99.lng,c99.x,c99.y);
2427 //dbg(0,"0x%x,0x%x\n",c99.x,c99.y);
2428 transform(global_navit->trans, pro, &c99, &cursor_pnt, 1, 0, 0, NULL); 2822 transform(global_navit->trans, pro, &c99, &cursor_pnt, 1, 0, 0, NULL);
2429 dbg(0,"xxxxxxx=%d\n",cursor_pnt.x);
2430 dbg(0,"yyyyyyy=%d\n",cursor_pnt.y);
2431
2432 g99.lat=-79.0;
2433 g99.lng=170.0;
2434 transform_from_geo(pro, &g99, &c99);
2435 dbg(0,"right bottom lat=%f, lng=%f, x=%d y=%d\n",g99.lat,g99.lng,c99.x,c99.y);
2436 //dbg(0,"right bottom lat=%f, lng=%f, x=%f y=%f\n",g99.lat,g99.lng,c99.x,c99.y);
2437 transform(global_navit->trans, pro, &c99, &cursor_pnt, 1, 0, 0, NULL);
2438 dbg(0,"xxxxxxx=%d\n",cursor_pnt.x);
2439 dbg(0,"yyyyyyy=%d\n",cursor_pnt.y);
2440 */
2441
2442 g99.lat=0.0;
2443 g99.lng=0.0;
2444 transform_from_geo(pro, &g99, &c99);
2445 //dbg(0,"center center lat=%f, lng=%f, x=%d y=%d\n",g99.lat,g99.lng,c99.x,c99.y);
2446 //dbg(0,"center center lat=%f, lng=%f, x=%f y=%f\n",g99.lat,g99.lng,c99.x,c99.y);
2447 transform(global_navit->trans, pro, &c99, &cursor_pnt, 1, 0, 0, NULL);
2448 //dbg(0,"xxxx333xxx=%d\n",cursor_pnt.x); 2823 ////DBG dbg(0,"xxxx333xxx=%d\n",cursor_pnt.x);
2449 //dbg(0,"yyyy333yyy=%d\n",cursor_pnt.y); 2824 ////DBG dbg(0,"yyyy333yyy=%d\n",cursor_pnt.y);
2450 2825
2451 //struct coord *c77; 2826 //struct coord *c77;
2452 //c77=&(t->map_center); 2827 //c77=&(t->map_center);
2453 //transform(global_navit->trans, pro, &c77, &cursor_pnt, 1, 0, 0, NULL); 2828 //transform(global_navit->trans, pro, &c77, &cursor_pnt, 1, 0, 0, NULL);
2454 //dbg(0,"---> cx=%d\n",cursor_pnt.x); 2829 ////DBG dbg(0,"---> cx=%d\n",cursor_pnt.x);
2455 //dbg(0,"---> cy=%d\n",cursor_pnt.y); 2830 ////DBG dbg(0,"---> cy=%d\n",cursor_pnt.y);
2456 2831
2457 2832
2458 // now really draw it 2833 // now really draw it
2459 struct graphics *gra22=displaylist->dc.gra; 2834 struct graphics *gra22 = displaylist->dc.gra;
2460 struct graphics_gc *gc22=displaylist->dc.gc; 2835 struct graphics_gc *gc22 = displaylist->dc.gc;
2461 if (! gc22) 2836 if (!gc22)
2462 { 2837 {
2463 gc22=graphics_gc_new(gra22); 2838 gc22 = graphics_gc_new(gra22);
2464 } 2839 }
2840 //DBG dbg(0,"graphics_draw_bigmap s\n");
2465 graphics_draw_bigmap(gra22, gc22, -t->yaw, displaylist->order, g22.lat, g22.lng, cursor_pnt.x, cursor_pnt.y, mcenter_pnt.x, mcenter_pnt.y, global_vehicle_pos_onscreen.x, global_vehicle_pos_onscreen.y, valid); 2841 graphics_draw_bigmap(gra22, gc22, -t->yaw, displaylist->order, g22.lat, g22.lng, cursor_pnt.x, cursor_pnt.y, mcenter_pnt.x, mcenter_pnt.y, global_vehicle_pos_onscreen.x, global_vehicle_pos_onscreen.y, valid);
2842 //DBG dbg(0,"graphics_draw_bigmap e\n");
2466 } 2843 }
2467 2844
2468 //dbg(0,"xxx uuu xxx\n"); 2845 //DBG dbg(0,"xxx uuu xxx\n");
2469 2846
2470 displaylist->order=order_corrected; 2847 displaylist->order = order_corrected;
2848
2849 //DBG dbg(0, "XXXXXYYYYYYY Draw: 003\n");
2850
2851 // reset value;
2852 cancel_drawing_global = 0;
2471 2853
2472 while (!cancel) 2854 while (!cancel)
2473 { 2855 {
2474 if (!displaylist->msh) 2856 if (!displaylist->msh)
2857 {
2475 displaylist->msh=mapset_open(displaylist->ms); 2858 displaylist->msh = mapset_open(displaylist->ms);
2859 }
2860
2476 if (!displaylist->m) { 2861 if (!displaylist->m)
2862 {
2477 displaylist->m=mapset_next(displaylist->msh, 1); 2863 displaylist->m = mapset_next(displaylist->msh, 1);
2478 if (!displaylist->m) { 2864 if (!displaylist->m)
2865 {
2479 mapset_close(displaylist->msh); 2866 mapset_close(displaylist->msh);
2480 displaylist->msh=NULL; 2867 displaylist->msh = NULL;
2481 break; 2868 break;
2482 } 2869 }
2483 2870
2484 mapset_counter++; 2871 mapset_counter++;
2485 mapset_need_draw=1; 2872 mapset_need_draw = 1;
2486 struct attr map_name_attr; 2873 struct attr map_name_attr;
2874
2487 if(map_get_attr(displaylist->m,attr_name, &map_name_attr,NULL)) 2875 if (map_get_attr(displaylist->m, attr_name, &map_name_attr, NULL))
2488 { 2876 {
2489 // dbg(0,"map name=%s",map_name_attr.u.str); 2877 // //DBG dbg(0,"map name=%s",map_name_attr.u.str);
2490 if (strncmp("_ms_sdcard_map:", map_name_attr.u.str, 15) == 0) 2878 if (strncmp("_ms_sdcard_map:", map_name_attr.u.str, 15) == 0)
2491 { 2879 {
2492 if (strncmp("_ms_sdcard_map:/sdcard/zanavi/maps/borders.bin", map_name_attr.u.str, 41) == 0) 2880 if (strncmp("_ms_sdcard_map:/sdcard/zanavi/maps/borders.bin", map_name_attr.u.str, 41) == 0)
2493 { 2881 {
2494 // if its the countryborder map, always draw it 2882 // if its the countryborder map, always draw it
2495 mapset_need_draw=0; // --> now dont even draw borders on low zoom level, we have prerendered image 2883 mapset_need_draw = 0; // --> now dont even draw borders on low zoom level, we have prerendered image
2496 } 2884 }
2497 else 2885 else
2498 { 2886 {
2499 // if its an sdcard street map, don't draw it 2887 // if its an sdcard street map, don't draw it
2500 mapset_need_draw=0; 2888 mapset_need_draw = 0;
2501 } 2889 }
2502 } 2890 }
2503 } 2891 }
2504 2892
2505 //dbg(0,"---------==============>>>>>>>>>> ***** %d ****",mapset_counter); 2893 ////DBG dbg(0,"---------==============>>>>>>>>>> ***** %d ****",mapset_counter);
2506 2894
2507 displaylist->dc.pro=map_projection(displaylist->m); 2895 displaylist->dc.pro = map_projection(displaylist->m);
2508 displaylist->conv=map_requires_conversion(displaylist->m); 2896 displaylist->conv = map_requires_conversion(displaylist->m);
2509 if (route_selection) 2897 if (route_selection)
2510 { 2898 {
2511 displaylist->sel=route_selection; 2899 displaylist->sel = route_selection;
2512 } 2900 }
2513 else 2901 else
2514 { 2902 {
2515 displaylist->sel=transform_get_selection(displaylist->dc.trans, displaylist->dc.pro, displaylist->order); 2903 displaylist->sel = transform_get_selection(displaylist->dc.trans, displaylist->dc.pro, displaylist->order);
2516 } 2904 }
2517 displaylist->mr=map_rect_new(displaylist->m, displaylist->sel); 2905 displaylist->mr = map_rect_new(displaylist->m, displaylist->sel);
2518 } 2906 }
2907
2519 if (displaylist->mr) 2908 if (displaylist->mr)
2520 { 2909 {
2521 // draw vector map, or not? 2910 // draw vector map, or not?
2522 // dbg(0,"draw_vector_map=%d mapset_need_draw=%d\n", draw_vector_map, mapset_need_draw); 2911 //dbg(0,"draw_vector_map=%d mapset_need_draw=%d\n", draw_vector_map, mapset_need_draw);
2523 if ((draw_vector_map) || (mapset_need_draw == 1)) 2912 if ((draw_vector_map) || (mapset_need_draw == 1))
2524 { 2913 {
2914
2915 //dbg(0, "XXXXXYYYYYYY Draw: A.01\n");
2916
2525 while ((item=map_rect_get_item(displaylist->mr))) 2917 while ((item = map_rect_get_item(displaylist->mr)))
2526 { 2918 {
2527 int label_count=0; 2919 int label_count = 0;
2528 char *labels[2]; 2920 char *labels[2];
2529 struct hash_entry *entry; 2921 struct hash_entry *entry;
2922
2923 if (cancel_drawing_global == 1)
2924 {
2925 // stop drawing map is requested
2926 //DBG dbg(0, "** STOP MD 001 **\n");
2927 break;
2928 }
2530 2929
2531 if (item == &busy_item) 2930 if (item == &busy_item)
2532 { 2931 {
2533 if (displaylist->workload) 2932 if (displaylist->workload)
2534 { 2933 {
2535 // restore order :-) 2934 // restore order :-)
2536 displaylist->order=saved; 2935 displaylist->order = saved;
2537 return; 2936 return;
2538 } 2937 }
2539 else 2938 else
2939 {
2540 continue; 2940 continue;
2941 }
2541 } 2942 }
2542 2943
2543 entry=get_hash_entry(displaylist, item->type); 2944 entry = get_hash_entry(displaylist, item->type);
2945
2946 //dbg(0, "XXXXXYYYYYYY Draw: A.item1 %p %i\n", entry, item->type);
2947
2948 // DEBUG -------- zoffzoff
2949 // DEBUG -------- zoffzoff
2950 // DEBUG -------- zoffzoff
2951 //item_dump_attr_stdout(item, displaylist->m);
2952 // DEBUG -------- zoffzoff
2953 // DEBUG -------- zoffzoff
2954 // DEBUG -------- zoffzoff
2544 2955
2545 if (!entry) 2956 if (!entry)
2957 {
2546 continue; 2958 continue;
2959 }
2547 2960
2548 count=item_coord_get_within_selection(item, ca, item->type < type_line ? 1: max, displaylist->sel); 2961 count = item_coord_get_within_selection(item, ca, item->type < type_line ? 1 : max, displaylist->sel);
2549 2962
2550 if (! count) 2963 if (!count)
2964 {
2551 continue; 2965 continue;
2966 }
2967
2968 //dbg(0, "XXXXXYYYYYYY Draw: A.item2\n");
2552 2969
2553 if (displaylist->dc.pro != pro) 2970 if (displaylist->dc.pro != pro)
2554 transform_from_to_count(ca, displaylist->dc.pro, ca, pro, count); 2971 transform_from_to_count(ca, displaylist->dc.pro, ca, pro, count);
2555 2972
2556 if (count == max) 2973 if (count == max)
2557 { 2974 {
2558 dbg(0,"point count overflow %d for %s "ITEM_ID_FMT"\n", count,item_to_name(item->type),ITEM_ID_ARGS(*item)); 2975 //DBG dbg(0,"point count overflow %d for %s "ITEM_ID_FMT"\n", count,item_to_name(item->type),ITEM_ID_ARGS(*item));
2559 displaylist->dc.maxlen=max*2; 2976 displaylist->dc.maxlen = max * 2;
2560 } 2977 }
2561 2978
2562 if (item_is_custom_poi(*item)) 2979 if (item_is_custom_poi(*item))
2563 { 2980 {
2564 if (item_attr_get(item, attr_icon_src, &attr2)) 2981 if (item_attr_get(item, attr_icon_src, &attr2))
2565 labels[1]=map_convert_string(displaylist->m, attr2.u.str); 2982 labels[1] = map_convert_string(displaylist->m, attr2.u.str);
2566 else 2983 else
2567 labels[1]=NULL; 2984 labels[1] = NULL;
2568 label_count=2; 2985 label_count = 2;
2569 } 2986 }
2570 else 2987 else
2571 { 2988 {
2572 labels[1]=NULL; 2989 labels[1] = NULL;
2573 label_count=0; 2990 label_count = 0;
2574 } 2991 }
2575 2992
2576 if (item_attr_get(item, attr_label, &attr)) 2993 if (item_attr_get(item, attr_label, &attr))
2577 { 2994 {
2578 labels[0]=attr.u.str; 2995 labels[0] = attr.u.str;
2579 if (!label_count) 2996 if (!label_count)
2997 {
2580 label_count=2; 2998 label_count = 2;
2999 }
2581 } 3000 }
2582 else 3001 else
2583 { 3002 {
2584 labels[0]=NULL; 3003 labels[0] = NULL;
2585 } 3004 }
2586 3005
2587 3006 // DEBUG -------- zoffzoff
3007 // DEBUG -------- zoffzoff
3008 // DEBUG -------- zoffzoff
2588 //item_dump_attr_stdout(item, displaylist->m); 3009 // item_dump_attr_stdout(item, displaylist->m);
3010 // DEBUG -------- zoffzoff
3011 // DEBUG -------- zoffzoff
3012 // DEBUG -------- zoffzoff
3013
2589 struct attr attr_77; 3014 struct attr attr_77;
2590 if (item_attr_get(item, attr_flags, &attr_77)) 3015 if (item_attr_get(item, attr_flags, &attr_77))
2591 { 3016 {
2592 // dbg(0,"uuuuuuuuuuuuu %s uuuuu %d\n",item_to_name(item->type), attr_77.u.num); 3017 // dbg(0,"uuuuuuuuuuuuu %s uuuuu %d\n",item_to_name(item->type), attr_77.u.num);
2593 item->flags=attr_77.u.num; 3018 item->flags = attr_77.u.num;
2594 } 3019 }
2595 else 3020 else
2596 { 3021 {
2597 item->flags=0; 3022 item->flags = 0;
2598 } 3023 }
2599
2600 3024
2601 //struct attr *attr88; 3025 //struct attr *attr88;
2602 //if (item_attr_get(item, attr_flags, &attr88)) 3026 //if (item_attr_get(item, attr_flags, &attr88))
2603 //{ 3027 //{
2604 //dbg(0,"item flags=%d\n",attr88->u.num); 3028 ////DBG dbg(0,"item flags=%d\n",attr88->u.num);
2605 //} 3029 //}
2606 //attr88=NULL; 3030 //attr88=NULL;
2607 3031
3032
3033 /*
3034 if (item->flags & AF_UNDERGROUND)
3035 {
3036 dbg(0,"is UNDERGROUND\n");
3037 }
3038 else if (item->flags & AF_BRIDGE)
3039 {
3040 dbg(0,"is BRIDGE\n");
3041 }
3042 */
3043
2608 if (displaylist->conv && label_count) 3044 if (displaylist->conv && label_count)
2609 { 3045 {
2610 labels[0]=map_convert_string(displaylist->m, labels[0]); 3046 labels[0] = map_convert_string(displaylist->m, labels[0]);
2611 display_add(entry, item, count, ca, labels, label_count); 3047 display_add(entry, item, count, ca, labels, label_count);
2612 map_convert_free(labels[0]); 3048 map_convert_free(labels[0]);
2613 } 3049 }
2614 else 3050 else
2615 { 3051 {
2624 workload++; 3060 workload++;
2625 3061
2626 if (workload == displaylist->workload) 3062 if (workload == displaylist->workload)
2627 { 3063 {
2628 // restore order :-) 3064 // restore order :-)
2629 displaylist->order=saved; 3065 displaylist->order = saved;
3066 // reset value;
3067 cancel_drawing_global = 0;
2630 return; 3068 return;
2631 } 3069 }
2632 } 3070 } // while item=map_rect_get_item
3071
3072 ////DBG dbg(0, "XXXXXYYYYYYY Draw: A.02\n");
3073
2633 map_rect_destroy(displaylist->mr); 3074 map_rect_destroy(displaylist->mr);
2634 } 3075 }
2635 } 3076 }
2636 3077
2637 if (!route_selection) 3078 if (!route_selection)
2638 { 3079 {
2639 map_selection_destroy(displaylist->sel); 3080 map_selection_destroy(displaylist->sel);
2640 } 3081 }
2641 3082
2642 displaylist->mr=NULL; 3083 displaylist->mr = NULL;
2643 displaylist->sel=NULL; 3084 displaylist->sel = NULL;
2644 displaylist->m=NULL; 3085 displaylist->m = NULL;
2645 } // while ---- 3086 } // while ----
2646 3087
3088 //DBG dbg(0, "XXXXXYYYYYYY Draw: 004\n");
3089
3090 // reset value;
3091 cancel_drawing_global = 0;
3092
2647 // restore order :-) 3093 // restore order :-)
2648 displaylist->order=saved; 3094 displaylist->order = saved;
2649 3095
2650 profile(1,"process_selection\n"); 3096 // profile(1,"process_selection\n");
3097
3098 //DBG dbg(0,"ee s\n");
2651 if (displaylist->idle_ev) 3099 if (displaylist->idle_ev)
3100 {
2652 event_remove_idle(displaylist->idle_ev); 3101 event_remove_idle(displaylist->idle_ev);
3102 }
3103 //DBG dbg(0,"ee e\n");
2653 displaylist->idle_ev=NULL; 3104 displaylist->idle_ev = NULL;
2654 callback_destroy(displaylist->idle_cb); 3105 callback_destroy(displaylist->idle_cb);
2655 displaylist->idle_cb=NULL; 3106 displaylist->idle_cb = NULL;
2656 displaylist->busy=0; 3107 displaylist->busy = 0;
2657 3108
2658 // graphics_process_selection(displaylist->dc.gra, displaylist); 3109 // graphics_process_selection(displaylist->dc.gra, displaylist);
2659 3110
2660 profile(1,"draw\n"); 3111 //profile(1, "draw\n");
3112
3113 //DBG dbg(0, "XXXXXYYYYYYY Draw: 005\n");
3114
2661 if (! cancel) 3115 if (!cancel)
2662 { 3116 {
2663 int flags2 = flags; 3117 int flags2 = flags;
2664 if (!(flags2 & 2)) 3118 if (!(flags2 & 2))
2665 { 3119 {
2666 if (!draw_vector_map) 3120 if (!draw_vector_map)
2667 { 3121 {
2668 // dont clean bg of screen when drawing prerendered tiles 3122 // dont clean bg of screen when drawing prerendered tiles
2669 flags2 = flags2 + 2; 3123 flags2 = flags2 + 2;
2670 } 3124 }
2671 } 3125 }
2672 // dbg(0,"call graphics_displaylist_draw 3") 3126 //DBG dbg(0,"call graphics_displaylist_draw 3")
2673 graphics_displaylist_draw(displaylist->dc.gra, displaylist, displaylist->dc.trans, displaylist->layout, flags2); 3127 graphics_displaylist_draw(displaylist->dc.gra, displaylist, displaylist->dc.trans, displaylist->layout, flags2);
2674 } 3128 }
3129
3130 //DBG dbg(0, "XXXXXYYYYYYY Draw: 006\n");
2675 3131
2676#ifdef HAVE_API_ANDROID 3132#ifdef HAVE_API_ANDROID
2677 android_return_generic_int(2, 0); 3133 android_return_generic_int(2, 0);
2678#endif 3134#endif
2679
2680 3135
2681 map_rect_destroy(displaylist->mr); 3136 map_rect_destroy(displaylist->mr);
2682 if (!route_selection) 3137 if (!route_selection)
2683 map_selection_destroy(displaylist->sel); 3138 map_selection_destroy(displaylist->sel);
2684 mapset_close(displaylist->msh); 3139 mapset_close(displaylist->msh);
2685 displaylist->mr=NULL; 3140 displaylist->mr = NULL;
2686 displaylist->sel=NULL; 3141 displaylist->sel = NULL;
2687 displaylist->m=NULL; 3142 displaylist->m = NULL;
2688 displaylist->msh=NULL; 3143 displaylist->msh = NULL;
2689 profile(1,"callback\n"); 3144 //profile(1, "callback\n");
2690 callback_call_1(displaylist->cb, cancel); 3145 callback_call_1(displaylist->cb, cancel);
2691 profile(0,"end\n"); 3146 //profile(0, "end\n");
3147 //DBG dbg(0,"leave\n");
2692} 3148}
2693 3149
2694/** 3150/**
2695 * FIXME 3151 * FIXME
2696 * @param <> 3152 * @param <>
2697 * @returns <> 3153 * @returns <>
2698 * @author Martin Schaller (04/2008) 3154 * @author Martin Schaller (04/2008)
2699*/ 3155 */
2700void graphics_displaylist_draw(struct graphics *gra, struct displaylist *displaylist, struct transformation *trans, struct layout *l, int flags) 3156void graphics_displaylist_draw(struct graphics *gra, struct displaylist *displaylist, struct transformation *trans, struct layout *l, int flags)
2701{ 3157{
2702 //dbg(0,"ooo enter ooo\n"); 3158 //DBG dbg(0,"ooo enter ooo\n");
2703 3159
2704 int order=transform_get_order(trans); 3160 int order = transform_get_order(trans);
2705 displaylist->dc.trans=trans; 3161 displaylist->dc.trans = trans;
2706 displaylist->dc.gra=gra; 3162 displaylist->dc.gra = gra;
2707 displaylist->dc.mindist=transform_get_scale(trans)/2; 3163 displaylist->dc.mindist = transform_get_scale(trans) / 2;
3164 //DBG dbg(0,"1\n");
2708 // FIXME find a better place to set the background color 3165 // FIXME find a better place to set the background color
2709 if (l) 3166 if (l)
2710 { 3167 {
2711 graphics_gc_set_background(gra->gc[0], &l->color); 3168 graphics_gc_set_background(gra->gc[0], &l->color);
2712 graphics_gc_set_foreground(gra->gc[0], &l->color); 3169 graphics_gc_set_foreground(gra->gc[0], &l->color);
2713 gra->default_font = g_strdup(l->font); 3170 gra->default_font = g_strdup(l->font);
2714 } 3171 }
3172 //DBG dbg(0,"2\n");
2715 graphics_background_gc(gra, gra->gc[0]); 3173 graphics_background_gc(gra, gra->gc[0]);
2716 if (flags & 1) 3174 if (flags & 1)
2717 { 3175 {
3176 //DBG dbg(0,"3\n");
2718 callback_list_call_attr_0(gra->cbl, attr_predraw); 3177 callback_list_call_attr_0(gra->cbl, attr_predraw);
3178 //DBG dbg(0,"4\n");
2719 } 3179 }
2720 gra->meth.draw_mode(gra->priv, (flags & 8)?draw_mode_begin_clear:draw_mode_begin); 3180 gra->meth.draw_mode(gra->priv, (flags & 8) ? draw_mode_begin_clear : draw_mode_begin);
3181 //DBG dbg(0,"5\n");
2721 if (!(flags & 2)) 3182 if (!(flags & 2))
2722 { 3183 {
3184 //DBG dbg(0,"6\n");
2723 // clear the display/screen/whatever here 3185 // clear the display/screen/whatever here
2724 gra->meth.draw_rectangle(gra->priv, gra->gc[0]->priv, &gra->r.lu, gra->r.rl.x-gra->r.lu.x, gra->r.rl.y-gra->r.lu.y); 3186 gra->meth.draw_rectangle(gra->priv, gra->gc[0]->priv, &gra->r.lu, gra->r.rl.x - gra->r.lu.x, gra->r.rl.y - gra->r.lu.y);
2725 } 3187 //DBG dbg(0,"7\n");
3188 }
2726 if (l) 3189 if (l)
2727 { 3190 {
3191 //DBG dbg(0,"8\n");
2728 // dbg(0,"o , l->d = %d , %d\n",order,l->order_delta); 3192 // //DBG dbg(0,"o , l->d = %d , %d\n",order,l->order_delta);
2729 xdisplay_draw(displaylist, gra, l, order+l->order_delta); 3193 xdisplay_draw(displaylist, gra, l, order + l->order_delta);
3194 //DBG dbg(0,"9\n");
2730 } 3195 }
2731 if (flags & 1) 3196 if (flags & 1)
2732 { 3197 {
3198 //DBG dbg(0,"10\n");
2733 callback_list_call_attr_0(gra->cbl, attr_postdraw); 3199 callback_list_call_attr_0(gra->cbl, attr_postdraw);
3200 //DBG dbg(0,"11\n");
2734 } 3201 }
2735 if (!(flags & 4)) 3202 if (!(flags & 4))
3203 {
3204 //DBG dbg(0,"12\n");
2736 gra->meth.draw_mode(gra->priv, draw_mode_end); 3205 gra->meth.draw_mode(gra->priv, draw_mode_end);
3206 //DBG dbg(0,"13\n");
3207 }
3208
3209 //DBG dbg(0,"leave\n");
2737} 3210}
2738 3211
2739static void graphics_load_mapset(struct graphics *gra, struct displaylist *displaylist, struct mapset *mapset, struct transformation *trans, struct layout *l, int async, struct callback *cb, int flags) 3212static void graphics_load_mapset(struct graphics *gra, struct displaylist *displaylist, struct mapset *mapset, struct transformation *trans, struct layout *l, int async, struct callback *cb, int flags)
2740{ 3213{
2741 int order=transform_get_order(trans); 3214 int order = transform_get_order(trans);
2742 3215
2743 //dbg(0,"enter displaylist->busy=%d\n",displaylist->busy); 3216 //DBG dbg(0,"enter displaylist->busy=%d\n",displaylist->busy);
2744 //dbg(0,"async=%d\n",async); 3217 ////DBG dbg(0,"async=%d\n",async);
2745 if (displaylist->busy) 3218 if (displaylist->busy)
2746 { 3219 {
2747 if (async == 1) 3220 if (async == 1)
2748 { 3221 {
2749 return; 3222 return;
2750 } 3223 }
2751 //dbg(0,"**draw 1"); 3224 //DBG dbg(0,"**draw 1");
2752 do_draw(displaylist, 1, flags); 3225 do_draw(displaylist, 1, flags);
2753 } 3226 }
2754 xdisplay_free(displaylist); 3227 xdisplay_free(displaylist);
2755 3228
2756 displaylist->dc.gra=gra; 3229 displaylist->dc.gra = gra;
2757 displaylist->ms=mapset; 3230 displaylist->ms = mapset;
2758 displaylist->dc.trans=trans; 3231 displaylist->dc.trans = trans;
2759 displaylist->workload=async ? 100 : 0; 3232 displaylist->workload = async ? 100 : 0;
2760 displaylist->cb=cb; 3233 displaylist->cb = cb;
2761 displaylist->seq++; 3234 displaylist->seq++;
2762 3235
2763 if (l) 3236 if (l)
2764 { 3237 {
2765 order+=l->order_delta; 3238 order += l->order_delta;
2766 } 3239 }
2767 displaylist->order=order; 3240 displaylist->order = order;
2768 displaylist->busy=1; 3241 displaylist->busy = 1;
2769 displaylist->layout=l; 3242 displaylist->layout = l;
2770 3243
2771 if (async) 3244 if (async)
2772 { 3245 {
2773 //dbg(0,"§§async"); 3246 //DBG dbg(0,"§§async");
2774 if (! displaylist->idle_cb) 3247 if (!displaylist->idle_cb)
2775 { 3248 {
2776 //dbg(0,"§§async --> callback"); 3249 //DBG dbg(0,"§§async --> callback");
2777 displaylist->idle_cb=callback_new_3(callback_cast(do_draw), displaylist, 0, flags); 3250 displaylist->idle_cb = callback_new_3(callback_cast(do_draw), displaylist, 0, flags);
2778 } 3251 }
2779 //dbg(0,"§§async --> add idle"); 3252 //DBG dbg(0,"§§async --> add idle");
2780 displaylist->idle_ev=event_add_idle(50, displaylist->idle_cb); 3253 displaylist->idle_ev = event_add_idle(50, displaylist->idle_cb);
2781 } 3254 }
2782 else 3255 else
2783 { 3256 {
2784 //dbg(0,"@@sync"); 3257 //DBG dbg(0,"@@sync");
2785 do_draw(displaylist, 0, flags); 3258 do_draw(displaylist, 0, flags);
2786 } 3259 }
2787} 3260}
2788 3261
2789
2790/** 3262/**
2791 * FIXME 3263 * FIXME
2792 * @param <> 3264 * @param <>
2793 * @returns <> 3265 * @returns <>
2794 * @author Martin Schaller (04/2008) 3266 * @author Martin Schaller (04/2008)
2795*/ 3267 */
2796void graphics_draw(struct graphics *gra, struct displaylist *displaylist, struct mapset *mapset, struct transformation *trans, struct layout *l, int async, struct callback *cb, int flags) 3268void graphics_draw(struct graphics *gra, struct displaylist *displaylist, struct mapset *mapset, struct transformation *trans, struct layout *l, int async, struct callback *cb, int flags)
2797{ 3269{
2798 //dbg(0,"ooo enter ooo\n"); 3270 //DBG dbg(0,"ooo enter ooo\n");
2799 3271
2800 graphics_load_mapset(gra, displaylist, mapset, trans, l, async, cb, flags); 3272 graphics_load_mapset(gra, displaylist, mapset, trans, l, async, cb, flags);
2801} 3273}
2802 3274
2803int
2804graphics_draw_cancel(struct graphics *gra, struct displaylist *displaylist) 3275int graphics_draw_cancel(struct graphics *gra, struct displaylist *displaylist)
2805{ 3276{
2806 //dbg(0,"ooo enter ooo\n"); 3277 //DBG dbg(0,"ooo enter ooo\n");
2807 3278
2808 if (!displaylist->busy) 3279 if (!displaylist->busy)
2809 return 0; 3280 return 0;
2810 do_draw(displaylist, 1, 0); 3281 do_draw(displaylist, 1, 0);
2811 return 1; 3282 return 1;
2814/** 3285/**
2815 * FIXME 3286 * FIXME
2816 * @param <> 3287 * @param <>
2817 * @returns <> 3288 * @returns <>
2818 * @author Martin Schaller (04/2008) 3289 * @author Martin Schaller (04/2008)
2819*/ 3290 */
2820struct displaylist_handle { 3291struct displaylist_handle
3292{
2821 struct displaylist *dl; 3293 struct displaylist *dl;
2822 struct displayitem *di; 3294 struct displayitem *di;
2823 int hashidx; 3295 int hashidx;
2824}; 3296};
2825 3297
2826/** 3298/**
2827 * FIXME 3299 * FIXME
2828 * @param <> 3300 * @param <>
2829 * @returns <> 3301 * @returns <>
2830 * @author Martin Schaller (04/2008) 3302 * @author Martin Schaller (04/2008)
2831*/ 3303 */
2832struct displaylist_handle * graphics_displaylist_open(struct displaylist *displaylist) 3304struct displaylist_handle * graphics_displaylist_open(struct displaylist *displaylist)
2833{ 3305{
2834 struct displaylist_handle *ret; 3306 struct displaylist_handle *ret;
2835 3307
2836 ret=g_new0(struct displaylist_handle, 1); 3308 ret=g_new0(struct displaylist_handle, 1);
2837 ret->dl=displaylist; 3309 ret->dl = displaylist;
2838 3310
2839 return ret; 3311 return ret;
2840} 3312}
2841 3313
2842/** 3314/**
2843 * FIXME 3315 * FIXME
2844 * @param <> 3316 * @param <>
2845 * @returns <> 3317 * @returns <>
2846 * @author Martin Schaller (04/2008) 3318 * @author Martin Schaller (04/2008)
2847*/ 3319 */
2848struct displayitem * graphics_displaylist_next(struct displaylist_handle *dlh) 3320struct displayitem * graphics_displaylist_next(struct displaylist_handle *dlh)
2849{ 3321{
2850 struct displayitem *ret; 3322 struct displayitem *ret;
2851 if (!dlh) 3323 if (!dlh)
2852 return NULL; 3324 return NULL;
2853 for (;;) { 3325 for (;;)
3326 {
2854 if (dlh->di) { 3327 if (dlh->di)
3328 {
2855 ret=dlh->di; 3329 ret = dlh->di;
2856 dlh->di=ret->next; 3330 dlh->di = ret->next;
2857 break; 3331 break;
2858 } 3332 }
2859 if (dlh->hashidx == HASH_SIZE) { 3333 if (dlh->hashidx == HASH_SIZE_GRAPHICS_)
3334 {
2860 ret=NULL; 3335 ret = NULL;
2861 break; 3336 break;
2862 } 3337 }
2863 if (dlh->dl->hash_entries[dlh->hashidx].type) 3338 if (dlh->dl->hash_entries[dlh->hashidx].type)
2864 dlh->di=dlh->dl->hash_entries[dlh->hashidx].di; 3339 dlh->di = dlh->dl->hash_entries[dlh->hashidx].di;
2865 dlh->hashidx++; 3340 dlh->hashidx++;
2866 } 3341 }
2867 return ret; 3342 return ret;
2868} 3343}
2869 3344
2870/** 3345/**
2871 * FIXME 3346 * FIXME
2872 * @param <> 3347 * @param <>
2873 * @returns <> 3348 * @returns <>
2874 * @author Martin Schaller (04/2008) 3349 * @author Martin Schaller (04/2008)
2875*/ 3350 */
2876void graphics_displaylist_close(struct displaylist_handle *dlh) 3351void graphics_displaylist_close(struct displaylist_handle *dlh)
2877{ 3352{
2878 g_free(dlh); 3353 g_free(dlh);
2879} 3354}
2880 3355
2881/** 3356/**
2882 * FIXME 3357 * FIXME
2883 * @param <> 3358 * @param <>
2884 * @returns <> 3359 * @returns <>
2885 * @author Martin Schaller (04/2008) 3360 * @author Martin Schaller (04/2008)
2886*/ 3361 */
2887struct displaylist * graphics_displaylist_new(void) 3362struct displaylist * graphics_displaylist_new(void)
2888{ 3363{
2889 struct displaylist *ret=g_new0(struct displaylist, 1); 3364 struct displaylist *ret=g_new0(struct displaylist, 1);
2890 3365
2891 ret->dc.maxlen=16384; 3366 ret->dc.maxlen = 16384;
2892 3367
2893 return ret; 3368 return ret;
2894} 3369}
2895 3370
2896/** 3371/**
2897 * FIXME 3372 * FIXME
2898 * @param <> 3373 * @param <>
2899 * @returns <> 3374 * @returns <>
2900 * @author Martin Schaller (04/2008) 3375 * @author Martin Schaller (04/2008)
2901*/ 3376 */
2902struct item * graphics_displayitem_get_item(struct displayitem *di) 3377struct item * graphics_displayitem_get_item(struct displayitem *di)
2903{ 3378{
2904 return &di->item; 3379 return &di->item;
2905} 3380}
2906 3381
2907int
2908graphics_displayitem_get_coord_count(struct displayitem *di) 3382int graphics_displayitem_get_coord_count(struct displayitem *di)
2909{ 3383{
2910 return di->count; 3384 return di->count;
2911} 3385}
2912 3386
2913/** 3387/**
2914 * FIXME 3388 * FIXME
2915 * @param <> 3389 * @param <>
2916 * @returns <> 3390 * @returns <>
2917 * @author Martin Schaller (04/2008) 3391 * @author Martin Schaller (04/2008)
2918*/ 3392 */
2919char * graphics_displayitem_get_label(struct displayitem *di) 3393char * graphics_displayitem_get_label(struct displayitem *di)
2920{ 3394{
2921 return di->label; 3395 return di->label;
2922} 3396}
2923 3397
2924int
2925graphics_displayitem_get_displayed(struct displayitem *di) 3398int graphics_displayitem_get_displayed(struct displayitem *di)
2926{ 3399{
2927 return 1; 3400 return 1;
2928} 3401}
2929 3402
2930/** 3403/**
2931 * FIXME 3404 * FIXME
2932 * @param <> 3405 * @param <>
2933 * @returns <> 3406 * @returns <>
2934 * @author Martin Schaller (04/2008) 3407 * @author Martin Schaller (04/2008)
2935*/ 3408 */
2936static int within_dist_point(struct point *p0, struct point *p1, int dist) 3409static int within_dist_point(struct point *p0, struct point *p1, int dist)
2937{ 3410{
2938 if (p0->x == 32767 || p0->y == 32767 || p1->x == 32767 || p1->y == 32767) 3411 if (p0->x == 32767 || p0->y == 32767 || p1->x == 32767 || p1->y == 32767)
2939 return 0; 3412 return 0;
2940 if (p0->x == -32768 || p0->y == -32768 || p1->x == -32768 || p1->y == -32768) 3413 if (p0->x == -32768 || p0->y == -32768 || p1->x == -32768 || p1->y == -32768)
2941 return 0; 3414 return 0;
2942 if ((p0->x-p1->x)*(p0->x-p1->x) + (p0->y-p1->y)*(p0->y-p1->y) <= dist*dist) { 3415 if ((p0->x - p1->x) * (p0->x - p1->x) + (p0->y - p1->y) * (p0->y - p1->y) <= dist * dist)
2943 return 1; 3416 {
2944 } 3417 return 1;
2945 return 0; 3418 }
3419 return 0;
2946} 3420}
2947 3421
2948/** 3422/**
2949 * FIXME 3423 * FIXME
2950 * @param <> 3424 * @param <>
2951 * @returns <> 3425 * @returns <>
2952 * @author Martin Schaller (04/2008) 3426 * @author Martin Schaller (04/2008)
2953*/ 3427 */
2954static int within_dist_line(struct point *p, struct point *line_p0, struct point *line_p1, int dist) 3428static int within_dist_line(struct point *p, struct point *line_p0, struct point *line_p1, int dist)
2955{ 3429{
2956 int vx,vy,wx,wy; 3430 int vx, vy, wx, wy;
2957 int c1,c2; 3431 int c1, c2;
2958 struct point line_p; 3432 struct point line_p;
2959 3433
2960 if (line_p0->x < line_p1->x) { 3434 if (line_p0->x < line_p1->x)
3435 {
2961 if (p->x < line_p0->x - dist) 3436 if (p->x < line_p0->x - dist)
2962 return 0; 3437 return 0;
2963 if (p->x > line_p1->x + dist) 3438 if (p->x > line_p1->x + dist)
2964 return 0; 3439 return 0;
2965 } else { 3440 }
3441 else
3442 {
2966 if (p->x < line_p1->x - dist) 3443 if (p->x < line_p1->x - dist)
2967 return 0; 3444 return 0;
2968 if (p->x > line_p0->x + dist) 3445 if (p->x > line_p0->x + dist)
2969 return 0; 3446 return 0;
2970 } 3447 }
2971 if (line_p0->y < line_p1->y) { 3448 if (line_p0->y < line_p1->y)
3449 {
2972 if (p->y < line_p0->y - dist) 3450 if (p->y < line_p0->y - dist)
2973 return 0; 3451 return 0;
2974 if (p->y > line_p1->y + dist) 3452 if (p->y > line_p1->y + dist)
2975 return 0; 3453 return 0;
2976 } else { 3454 }
3455 else
3456 {
2977 if (p->y < line_p1->y - dist) 3457 if (p->y < line_p1->y - dist)
2978 return 0; 3458 return 0;
2979 if (p->y > line_p0->y + dist) 3459 if (p->y > line_p0->y + dist)
2980 return 0; 3460 return 0;
2981 } 3461 }
2982 3462
2983 vx=line_p1->x-line_p0->x; 3463 vx = line_p1->x - line_p0->x;
2984 vy=line_p1->y-line_p0->y; 3464 vy = line_p1->y - line_p0->y;
2985 wx=p->x-line_p0->x; 3465 wx = p->x - line_p0->x;
2986 wy=p->y-line_p0->y; 3466 wy = p->y - line_p0->y;
2987 3467
2988 c1=vx*wx+vy*wy; 3468 c1 = vx * wx + vy * wy;
2989 if ( c1 <= 0 ) 3469 if (c1 <= 0)
2990 return within_dist_point(p, line_p0, dist); 3470 return within_dist_point(p, line_p0, dist);
2991 c2=vx*vx+vy*vy; 3471 c2 = vx * vx + vy * vy;
2992 if ( c2 <= c1 ) 3472 if (c2 <= c1)
2993 return within_dist_point(p, line_p1, dist); 3473 return within_dist_point(p, line_p1, dist);
2994 3474
2995 line_p.x=line_p0->x+vx*c1/c2; 3475 line_p.x = line_p0->x + vx * c1 / c2;
2996 line_p.y=line_p0->y+vy*c1/c2; 3476 line_p.y = line_p0->y + vy * c1 / c2;
2997 return within_dist_point(p, &line_p, dist); 3477 return within_dist_point(p, &line_p, dist);
2998} 3478}
2999 3479
3000/** 3480/**
3001 * FIXME 3481 * FIXME
3002 * @param <> 3482 * @param <>
3003 * @returns <> 3483 * @returns <>
3004 * @author Martin Schaller (04/2008) 3484 * @author Martin Schaller (04/2008)
3005*/ 3485 */
3006static int within_dist_polyline(struct point *p, struct point *line_pnt, int count, int dist, int close) 3486static int within_dist_polyline(struct point *p, struct point *line_pnt, int count, int dist, int close)
3007{ 3487{
3008 int i; 3488 int i;
3009 for (i = 0 ; i < count-1 ; i++) { 3489 for (i = 0; i < count - 1; i++)
3490 {
3010 if (within_dist_line(p,line_pnt+i,line_pnt+i+1,dist)) { 3491 if (within_dist_line(p, line_pnt + i, line_pnt + i + 1, dist))
3492 {
3011 return 1; 3493 return 1;
3012 } 3494 }
3013 } 3495 }
3014 if (close) 3496 if (close)
3015 return (within_dist_line(p,line_pnt,line_pnt+count-1,dist)); 3497 return (within_dist_line(p, line_pnt, line_pnt + count - 1, dist));
3016 return 0; 3498 return 0;
3017} 3499}
3018 3500
3019/** 3501/**
3020 * FIXME 3502 * FIXME
3021 * @param <> 3503 * @param <>
3022 * @returns <> 3504 * @returns <>
3023 * @author Martin Schaller (04/2008) 3505 * @author Martin Schaller (04/2008)
3024*/ 3506 */
3025static int within_dist_polygon(struct point *p, struct point *poly_pnt, int count, int dist) 3507static int within_dist_polygon(struct point *p, struct point *poly_pnt, int count, int dist)
3026{ 3508{
3027 int i, j, c = 0; 3509 int i, j, c = 0;
3028 for (i = 0, j = count-1; i < count; j = i++) { 3510 for (i = 0, j = count - 1; i < count; j = i++)
3029 if ((((poly_pnt[i].y <= p->y) && ( p->y < poly_pnt[j].y )) || 3511 {
3030 ((poly_pnt[j].y <= p->y) && ( p->y < poly_pnt[i].y))) && 3512 if ((((poly_pnt[i].y <= p->y) && (p->y < poly_pnt[j].y)) || ((poly_pnt[j].y <= p->y) && (p->y < poly_pnt[i].y))) && (p->x < (poly_pnt[j].x - poly_pnt[i].x) * (p->y - poly_pnt[i].y) / (poly_pnt[j].y - poly_pnt[i].y) + poly_pnt[i].x))
3031 (p->x < (poly_pnt[j].x - poly_pnt[i].x) * (p->y - poly_pnt[i].y) / (poly_pnt[j].y - poly_pnt[i].y) + poly_pnt[i].x)) 3513 c = !c;
3032 c = !c; 3514 }
3033 }
3034 if (! c) 3515 if (!c)
3035 return within_dist_polyline(p, poly_pnt, count, dist, 1); 3516 return within_dist_polyline(p, poly_pnt, count, dist, 1);
3036 return c; 3517 return c;
3037} 3518}
3038 3519
3039/** 3520/**
3040 * FIXME 3521 * FIXME
3041 * @param <> 3522 * @param <>
3042 * @returns <> 3523 * @returns <>
3043 * @author Martin Schaller (04/2008) 3524 * @author Martin Schaller (04/2008)
3044*/ 3525 */
3045int graphics_displayitem_within_dist(struct displaylist *displaylist, struct displayitem *di, struct point *p, int dist) 3526int graphics_displayitem_within_dist(struct displaylist *displaylist, struct displayitem *di, struct point *p, int dist)
3046{ 3527{
3047 struct point *pa=g_alloca(sizeof(struct point)*displaylist->dc.maxlen); 3528 struct point *pa = g_alloca(sizeof(struct point) * displaylist->dc.maxlen);
3048 int count; 3529 int count;
3049 3530
3050 count=transform(displaylist->dc.trans, displaylist->dc.pro, di->c, pa, di->count, 1, 0, NULL); 3531 count = transform(displaylist->dc.trans, displaylist->dc.pro, di->c, pa, di->count, 1, 0, NULL);
3051 3532
3052 if (di->item.type < type_line) { 3533 if (di->item.type < type_line)
3534 {
3053 return within_dist_point(p, &pa[0], dist); 3535 return within_dist_point(p, &pa[0], dist);
3054 } 3536 }
3055 if (di->item.type < type_area) { 3537 if (di->item.type < type_area)
3538 {
3056 return within_dist_polyline(p, pa, count, dist, 0); 3539 return within_dist_polyline(p, pa, count, dist, 0);
3057 } 3540 }
3058 return within_dist_polygon(p, pa, count, dist); 3541 return within_dist_polygon(p, pa, count, dist);
3059} 3542}
3060 3543
3061
3062static void
3063graphics_process_selection_item(struct displaylist *dl, struct item *item) 3544static void graphics_process_selection_item(struct displaylist *dl, struct item *item)
3064{ 3545{
3065#if 0 /* FIXME */ 3546#if 0 /* FIXME */
3066 struct displayitem di,*di_res; 3547 struct displayitem di,*di_res;
3067 GHashTable *h; 3548 GHashTable *h;
3068 int count,max=dl->dc.maxlen; 3549 int count,max=dl->dc.maxlen;
3072 3553
3073 di.item=*item; 3554 di.item=*item;
3074 di.label=NULL; 3555 di.label=NULL;
3075 di.count=0; 3556 di.count=0;
3076 h=g_hash_table_lookup(dl->dl, GINT_TO_POINTER(di.item.type)); 3557 h=g_hash_table_lookup(dl->dl, GINT_TO_POINTER(di.item.type));
3077 if (h) { 3558 if (h)
3559 {
3078 di_res=g_hash_table_lookup(h, &di); 3560 di_res=g_hash_table_lookup(h, &di);
3079 if (di_res) { 3561 if (di_res)
3562 {
3080 di.item.type=(enum item_type)item->priv_data; 3563 di.item.type=(enum item_type)item->priv_data;
3081 display_add(dl, &di.item, di_res->count, di_res->c, NULL, 0); 3564 display_add(dl, &di.item, di_res->count, di_res->c, NULL, 0);
3082 return; 3565 return;
3083 } 3566 }
3084 } 3567 }
3085 mr=map_rect_new(item->map, NULL); 3568 mr=map_rect_new(item->map, NULL);
3086 item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo); 3569 item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
3087 count=item_coord_get(item, ca, item->type < type_line ? 1: max); 3570 count=item_coord_get(item, ca, item->type < type_line ? 1: max);
3088 if (!item_attr_get(item, attr_label, &attr)) 3571 if (!item_attr_get(item, attr_label, &attr))
3089 attr.u.str=NULL; 3572 attr.u.str=NULL;
3090 if (dl->conv && attr.u.str && attr.u.str[0]) { 3573 if (dl->conv && attr.u.str && attr.u.str[0])
3574 {
3091 char *str=map_convert_string(item->map, attr.u.str); 3575 char *str=map_convert_string(item->map, attr.u.str);
3092 display_add(dl, item, count, ca, &str, 1); 3576 display_add(dl, item, count, ca, &str, 1);
3093 map_convert_free(str); 3577 map_convert_free(str);
3578 }
3094 } else 3579 else
3095 display_add(dl, item, count, ca, &attr.u.str, 1); 3580 display_add(dl, item, count, ca, &attr.u.str, 1);
3096 map_rect_destroy(mr); 3581 map_rect_destroy(mr);
3097#endif 3582#endif
3098} 3583}
3099 3584
3100void
3101graphics_add_selection(struct graphics *gra, struct item *item, enum item_type type, struct displaylist *dl) 3585void graphics_add_selection(struct graphics *gra, struct item *item, enum item_type type, struct displaylist *dl)
3102{ 3586{
3103 struct item *item_dup=g_new(struct item, 1); 3587 struct item *item_dup=g_new(struct item, 1);
3104 *item_dup=*item; 3588 *item_dup = *item;
3105 item_dup->priv_data=(void *)type; 3589 item_dup->priv_data = (void *) type;
3106 gra->selection=g_list_append(gra->selection, item_dup); 3590 gra->selection = g_list_append(gra->selection, item_dup);
3107 if (dl) 3591 if (dl)
3108 graphics_process_selection_item(dl, item_dup); 3592 graphics_process_selection_item(dl, item_dup);
3109} 3593}
3110 3594
3111void
3112graphics_remove_selection(struct graphics *gra, struct item *item, enum item_type type, struct displaylist *dl) 3595void graphics_remove_selection(struct graphics *gra, struct item *item, enum item_type type, struct displaylist *dl)
3113{ 3596{
3114 GList *curr; 3597 GList *curr;
3115 int found; 3598 int found;
3116 3599
3117 for (;;) { 3600 for (;;)
3601 {
3118 curr=gra->selection; 3602 curr = gra->selection;
3119 found=0; 3603 found = 0;
3120 while (curr) { 3604 while (curr)
3605 {
3121 struct item *sitem=curr->data; 3606 struct item *sitem = curr->data;
3122 if (item_is_equal(*item,*sitem)) { 3607 if (item_is_equal(*item, *sitem))
3608 {
3123 if (dl) { 3609 if (dl)
3610 {
3124 struct displayitem di; 3611 struct displayitem di;
3125 /* Unused Variable 3612 /* Unused Variable
3126 GHashTable *h; */ 3613 GHashTable *h; */
3127 di.item=*sitem; 3614 di.item = *sitem;
3128 di.label=NULL; 3615 di.label = NULL;
3129 di.count=0; 3616 di.count = 0;
3130 di.item.type=type; 3617 di.item.type = type;
3131#if 0 /* FIXME */ 3618#if 0 /* FIXME */
3132 h=g_hash_table_lookup(dl->dl, GINT_TO_POINTER(di.item.type)); 3619 h=g_hash_table_lookup(dl->dl, GINT_TO_POINTER(di.item.type));
3133 if (h) 3620 if (h)
3134 g_hash_table_remove(h, &di); 3621 g_hash_table_remove(h, &di);
3135#endif 3622#endif
3136 } 3623 }
3137 g_free(sitem); 3624 g_free(sitem);
3138 gra->selection=g_list_remove(gra->selection, curr->data); 3625 gra->selection = g_list_remove(gra->selection, curr->data);
3139 found=1; 3626 found = 1;
3140 break; 3627 break;
3141 } 3628 }
3142 } 3629 }
3143 if (!found) 3630 if (!found)
3144 return; 3631 return;
3145 } 3632 }
3146} 3633}
3147 3634
3148void
3149graphics_clear_selection(struct graphics *gra, struct displaylist *dl) 3635void graphics_clear_selection(struct graphics *gra, struct displaylist *dl)
3150{ 3636{
3151 while (gra->selection) { 3637 while (gra->selection)
3638 {
3152 struct item *item=(struct item *)gra->selection->data; 3639 struct item *item = (struct item *) gra->selection->data;
3153 graphics_remove_selection(gra, item, (enum item_type)item->priv_data,dl); 3640 graphics_remove_selection(gra, item, (enum item_type) item->priv_data, dl);
3154 } 3641 }
3155} 3642}
3156 3643
3157static void
3158graphics_process_selection(struct graphics *gra, struct displaylist *dl) 3644static void graphics_process_selection(struct graphics *gra, struct displaylist *dl)
3159{ 3645{
3160 GList *curr; 3646 GList *curr;
3161 3647
3162 curr=gra->selection; 3648 curr = gra->selection;
3163 while (curr) { 3649 while (curr)
3650 {
3164 struct item *item=curr->data; 3651 struct item *item = curr->data;
3165 graphics_process_selection_item(dl, item); 3652 graphics_process_selection_item(dl, item);
3166 curr=g_list_next(curr); 3653 curr = g_list_next(curr);
3167 } 3654 }
3168} 3655}

Legend:
Removed from v.2  
changed lines
  Added in v.27

   
Visit the ZANavi Wiki