#include #include #include #include "gc-list.h" #include #include void reset_gc_list(gc_list *gcl) { if(gcl->gc)free(gcl->gc); gcl->gc = 0; gcl->ngc = 0; } extern int current_offset_x, current_offset_y; int GC_ONLY_TAGS = 0; void add_gcl(gc_list *gcl, graphic_component gc) { gc.x += current_offset_x; gc.x1 += current_offset_x; gc.x2 += current_offset_x; gc.y += current_offset_y; gc.y1 += current_offset_y; gc.y2 += current_offset_y; gcl->ngc++; gcl->gc = realloc(gcl->gc, sizeof(graphic_component) * gcl->ngc); gcl->gc[gcl->ngc-1] = gc; } void add_text_gcl(gc_list *gcl, int dx, int x, int y, char *t, font_info *f) { graphic_component gc; gc.type = graphicText; gc.text = t; gc.font = f; gc.x = x; gc.y = y; gc.x1 = x-3; gc.x2 = x+dx+3; gc.y1 = y-f->size; gc.y2 = y+f->size*0.5; gc.color1 = gc.color2 = gc.color3 = f->color; gc.item = 0; add_gcl(gcl, gc); } void add_tag_gcl(gc_list *gcl, int x1, int y1, int x2, int y2, int x, int y, char *t, void *tag, font_info *f, color_t text_color, color_t back_color, color_t outline_color) { graphic_component gc; gc.type = graphicTag; gc.text = t; gc.font = f; gc.x = x; gc.y = y; gc.x1 = x1; gc.x2 = x2; gc.y1 = y1; gc.y2 = y2; gc.color1 = text_color; gc.color2 = back_color; gc.color3 = outline_color; gc.item = tag; add_gcl(gcl, gc); } void add_line_gcl(gc_list *gcl, int x1, int y1, int x2, int y2, color_t color) { graphic_component gc; gc.type = graphicLine; gc.text = 0; gc.font = 0; gc.x = 0; gc.y = 0; gc.x1 = x1; gc.x2 = x2; gc.y1 = y1; gc.y2 = y2; gc.color1 = color; gc.color2 = color; gc.color3 = color; gc.item = 0; add_gcl(gcl, gc); } void add_rect_gcl(gc_list *gcl, int x1, int y1, int x2, int y2, color_t color) { graphic_component gc; gc.type = graphicRect; gc.text = 0; gc.font = 0; gc.x = 0; gc.y = 0; gc.x1 = x1; gc.x2 = x2; gc.y1 = y1; gc.y2 = y2; gc.color1 = color; gc.color2 = color; gc.color3 = color; gc.item = 0; add_gcl(gcl, gc); } void add_circle_gcl(gc_list *gcl, int x, int y, int r, color_t color) { graphic_component gc; gc.type = graphicCircle; gc.text = 0; gc.font = 0; gc.x = x; gc.y = y; gc.x1 = x-r; gc.x2 = x+r; gc.y1 = y-r; gc.y2 = y+r; gc.color1 = color; gc.color2 = color; gc.color3 = color; gc.item = 0; add_gcl(gcl, gc); } extern void *hilite_avm; extern char *hilite_tag; color_t hilite_tag_color = {40000, 40000, 65535}; color_t colocated_tag_color = {20000, 45535, 20000}, colocated_text_color = {0,0,0}; font_info small_font = {"courier", 8, fsRoman, {0,0,0}, 0}; void draw_gc_list(gc_list *gcl, int x1, int y1, int x2, int y2, int clear_bg) { int i; int gcx, gcx1, gcx2, gcy, gcy1, gcy2; graphic_component *gc; if(!GC_ONLY_TAGS && clear_bg) { // clear the space we're updating, because redrawing a string of text on top of where it already exists causes it to get ugly. yzPenColor(65535,65535,65535); yzRect(x1,y1,x2,y2); } //fprintf(stderr, "gc-draw %d %d %d %d\n", x1, y1, x2, y2); for(i=0;ingc;i++) { gc = gcl->gc + i; if(GC_ONLY_TAGS && gc->type != graphicTag)continue; gcx1 = gc->x1 * gcl->scale; gcy1 = gc->y1 * gcl->scale; gcx2 = gc->x2 * gcl->scale; gcy2 = gc->y2 * gcl->scale; if(gcx2 < x1-5 && gcx1 < x1-5)continue; if(gcx2 > x2+5 && gcx1 > x2+5)continue; if(gcy1 < y1-5 && gcy2 < y1-5)continue; if(gcy1 > y2+5 && gcy2 > y2+5)continue; gcx = gc->x * gcl->scale; gcy = gc->y * gcl->scale; switch(gc->type) { case graphicText: if(gcl->scale < 1 && strlen(gc->text)*5 > (gcx2-gcx1))break; if(gcl->scale<1) { small_font.color = gc->font->color; use_font(small_font); } else use_font(gc->font); yzText(gcx, gcy, gc->text); break; case graphicLine: yzPenColor1c(gc->color1); yzLine(gcx1, gcy1, gcx2, gcy2); break; case graphicRect: yzPenColor1c(gc->color1); yzRect(gcx1, gcy1, gcx2, gcy2); break; case graphicCircle: yzPenColor1c(gc->color1); yzCircle3i((gcx1+gcx2)/2, (gcy1+gcy2)/2, (gcx2-gcx1)/2); //yzOvalInRect(gcx1, gcy1, gcx2, gcy2); break; case graphicTag: if(gcl->scale < 1)break; if(hilite_tag && !strcmp(gc->text, hilite_tag)) yzPenColor1c(colocated_tag_color); else if(gc->item == hilite_avm)yzPenColor1c(hilite_tag_color); else yzPenColor1c(gc->color2); yzRect(gcx1, gcy1, gcx2, gcy2); yzPenColor1c(gc->color3); yzOutlineRect(gcx1, gcy1, gcx2, gcy2); use_font(gc->font); if(hilite_tag && !strcmp(gc->text, hilite_tag)) yzPenColor1c(colocated_text_color); else yzPenColor1c(gc->color1); yzText(gcx, gcy, gc->text); break; } } }