Index: trunk/src/board.c =================================================================== --- trunk/src/board.c (revision 21672) +++ trunk/src/board.c (revision 21673) @@ -170,10 +170,8 @@ /* copy default settings */ for (i = 0; i < PCB_MAX_LAYER; i++) - if (force || (ptr->Data->Layer[i].meta.real.color == NULL) || (ptr->Data->Layer[i].meta.real.color[0] == '\0')) { - free(ptr->Data->Layer[i].meta.real.color); - ptr->Data->Layer[i].meta.real.color = pcb_strdup(pcb_layer_default_color(i, pcb_layer_flags(ptr, i))); - } + if (force || (ptr->Data->Layer[i].meta.real.color.str[0] == '\0')) + memcpy(&ptr->Data->Layer[i].meta.real.color, pcb_layer_default_color(i, pcb_layer_flags(ptr, i)), sizeof(pcb_color_t)); } typedef struct { Index: trunk/src/color.h =================================================================== --- trunk/src/color.h (revision 21672) +++ trunk/src/color.h (revision 21673) @@ -56,6 +56,9 @@ void pcb_color_init(void); +/* temporary hack */ +#define pcb_color_is_drill(clr) (strcmp((clr)->str, "drill") == 0) + /*** color vector ***/ #define GVT(x) vtclr_ ## x Index: trunk/src/conf.c =================================================================== --- trunk/src/conf.c (revision 21672) +++ trunk/src/conf.c (revision 21673) @@ -541,7 +541,10 @@ dst->unit[idx] = u; break; case CFN_COLOR: - dst->color[idx] = text; /* let the HID check validity to support flexibility of the format */ + if (pcb_color_load_str(&dst->color[idx], text) != 0) { + pcb_hid_cfg_error(err_node, "Invalid color value: '%s'\n", text); + return -1; + } break; default: /* unknown field type registered in the fields hash: internal error */ @@ -1972,7 +1975,7 @@ case CFN_REAL: ret += pfn(ctx, "%f", val->real[idx]); break; case CFN_COORD: ret += pfn(ctx, "%$mS", val->coord[idx]); break; case CFN_UNIT: print_str_or_null(pfn, ctx, verbose, val->unit[idx], val->unit[idx]->suffix); break; - case CFN_COLOR: print_str_or_null(pfn, ctx, verbose, val->color[idx], val->color[idx]); break; + case CFN_COLOR: print_str_or_null(pfn, ctx, verbose, val->color[idx].str, val->color[idx].str); break; case CFN_LIST: { conf_listitem_t *n; Index: trunk/src/conf.h =================================================================== --- trunk/src/conf.h (revision 21672) +++ trunk/src/conf.h (revision 21673) @@ -60,7 +60,7 @@ typedef double CFT_REAL; typedef pcb_coord_t CFT_COORD; typedef pcb_unit_t * CFT_UNIT; -typedef char * CFT_COLOR; +typedef pcb_color_t CFT_COLOR; typedef conflist_t CFT_LIST; typedef enum { @@ -82,7 +82,7 @@ double *real; pcb_coord_t *coord; const pcb_unit_t **unit; - const char **color; + pcb_color_t *color; conflist_t *list; void *any; }; Index: trunk/src/conf_core.h =================================================================== --- trunk/src/conf_core.h (revision 21672) +++ trunk/src/conf_core.h (revision 21673) @@ -3,6 +3,7 @@ #include "conf.h" #include "globalconst.h" +#include "color.h" /* NOTE: this struct has a strict format because a code generator needs to read it. Please always keep the format (preferably even whitespace style). Index: trunk/src/crosshair.c =================================================================== --- trunk/src/crosshair.c (revision 21672) +++ trunk/src/crosshair.c (revision 21673) @@ -286,11 +286,11 @@ /* Draw the DRC outline if it is enabled */ if (conf_core.editor.show_drc) { - pcb_gui->set_color(pcb_crosshair.GC, conf_core.appearance.color.cross); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.cross); pcb_draw_wireframe_line(pcb_crosshair.GC,line.Point1.X, line.Point1.Y, line.Point2.X, line.Point2.Y, line.Thickness + 2 * (conf_core.design.bloat + 1), 0); - pcb_gui->set_color(pcb_crosshair.GC, conf_core.appearance.color.crosshair); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.crosshair); } break; } @@ -309,10 +309,10 @@ /* Draw the DRC outline if it is enabled */ if (conf_core.editor.show_drc) { - pcb_gui->set_color(pcb_crosshair.GC, conf_core.appearance.color.cross); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.cross); arc.Thickness += 2 * (conf_core.design.bloat + 1); pcb_draw_wireframe_arc(pcb_crosshair.GC, &arc, arc.Thickness); - pcb_gui->set_color(pcb_crosshair.GC, conf_core.appearance.color.crosshair); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.crosshair); } break; } @@ -352,10 +352,10 @@ /* Draw the DRC outline if it is enabled */ if (conf_core.editor.show_drc) { - pcb_gui->set_color(pcb_crosshair.GC, conf_core.appearance.color.cross); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.cross); pcb_draw_wireframe_line(pcb_crosshair.GC,point1->X, point1->Y, point2.X, point2.Y,line->Thickness + 2 * (conf_core.design.bloat + 1), 0); - pcb_gui->set_color(pcb_crosshair.GC, conf_core.appearance.color.crosshair); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.crosshair); } } else { @@ -407,10 +407,10 @@ /* Draw the DRC outline if it is enabled */ if (conf_core.editor.show_drc) { - pcb_gui->set_color(pcb_crosshair.GC, conf_core.appearance.color.cross); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.cross); arc.Thickness += 2 * (conf_core.design.bloat + 1); pcb_draw_wireframe_arc(pcb_crosshair.GC, &arc, arc.Thickness); - pcb_gui->set_color(pcb_crosshair.GC, conf_core.appearance.color.crosshair); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.crosshair); } /* Get the new arc point positions, calculate the movement deltas and send them @@ -1050,7 +1050,7 @@ { pcb_crosshair.GC = pcb_hid_make_gc(); - pcb_gui->set_color(pcb_crosshair.GC, conf_core.appearance.color.crosshair); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.crosshair); pcb_hid_set_draw_xor(pcb_crosshair.GC, 1); pcb_hid_set_line_cap(pcb_crosshair.GC, pcb_cap_round); pcb_hid_set_line_width(pcb_crosshair.GC, 1); Index: trunk/src/draw.c =================================================================== --- trunk/src/draw.c (revision 21672) +++ trunk/src/draw.c (revision 21673) @@ -99,22 +99,9 @@ TODO("cleanup: this should be cached") -void pcb_lighten_color(const char *orig, char buf[8], double factor) +void pcb_lighten_color(const pcb_color_t *orig, pcb_color_t *dst, double factor) { - unsigned int r, g, b; - - if (orig[0] == '#') { - sscanf(&orig[1], "%2x%2x%2x", &r, &g, &b); - r = MIN(255, r * factor); - g = MIN(255, g * factor); - b = MIN(255, b * factor); - } - else { - r = 0xff; - g = 0xff; - b = 0xff; - } - pcb_snprintf(buf, sizeof("#XXXXXX"), "#%02x%02x%02x", r, g, b); + pcb_color_load_int(dst, MIN(255, orig->r * factor), MIN(255, orig->g * factor), MIN(255, orig->b * factor), 255); } void pcb_draw_dashed_line(pcb_draw_info_t *info, pcb_hid_gc_t GC, pcb_coord_t x1, pcb_coord_t y1, pcb_coord_t x2, pcb_coord_t y2, unsigned int segs, pcb_bool_t cheap) @@ -322,7 +309,7 @@ static void draw_everything(pcb_draw_info_t *info) { pcb_layer_t *backsilk; - char *old_silk_color; + pcb_color_t old_silk_color; int i, ngroups; pcb_layergrp_id_t component, solder, gid, side_copper_grp; /* This is the list of layer groups we will draw. */ @@ -603,7 +590,7 @@ unsigned int lflg = 0; int may_have_delayed = 0; pcb_xform_t xform; - char *orig_color, new_color[8]; + pcb_color_t orig_color; pcb_layer_t *Layer = (pcb_layer_t *)Layer_; /* ugly hack until layer color is moved into info */ xform_setup(info, &xform, Layer); @@ -610,8 +597,7 @@ if ((info->xform != NULL) && (info->xform->layer_faded)) { orig_color = Layer->meta.real.color; - pcb_lighten_color(orig_color, new_color, 0.5); - Layer->meta.real.color = new_color; + pcb_lighten_color(&orig_color, &Layer->meta.real.color, 0.5); } lflg = pcb_layer_flags_(Layer); @@ -937,11 +923,11 @@ else pcb_draw_out.direct = 1; - hid->set_color(pcb_draw_out.pmGC, "#00FFFF"); - hid->set_color(pcb_draw_out.drillGC, "drill"); - hid->set_color(pcb_draw_out.padGC, conf_core.appearance.color.pin); - hid->set_color(pcb_draw_out.backpadGC, conf_core.appearance.color.invisible_objects); - hid->set_color(pcb_draw_out.padselGC, conf_core.appearance.color.selected); + hid->set_color(pcb_draw_out.pmGC, pcb_color_cyan); + hid->set_color(pcb_draw_out.drillGC, pcb_color_drill); + hid->set_color(pcb_draw_out.padGC, &conf_core.appearance.color.pin); + hid->set_color(pcb_draw_out.backpadGC, &conf_core.appearance.color.invisible_objects); + hid->set_color(pcb_draw_out.padselGC, &conf_core.appearance.color.selected); pcb_hid_set_line_width(pcb_draw_out.backpadGC, -1); pcb_hid_set_line_cap(pcb_draw_out.backpadGC, pcb_cap_square); pcb_hid_set_line_width(pcb_draw_out.padselGC, -1); @@ -1047,7 +1033,7 @@ mirror = (flip_x ^ flip_y); direction = (vert ? 1 : 0) + (flip_x ? 2 : 0); - pcb_gui->set_color(pcb_draw_out.fgGC, conf_core.appearance.color.pin_name); + pcb_gui->set_color(pcb_draw_out.fgGC, &conf_core.appearance.color.pin_name); if (pcb_gui->gui) pcb_draw_force_termlab++; Index: trunk/src/draw.h =================================================================== --- trunk/src/draw.h (revision 21672) +++ trunk/src/draw.h (revision 21673) @@ -110,7 +110,7 @@ extern int pcb_draw_force_termlab; /* force drawing terminal lables - useful for pinout previews */ extern pcb_bool pcb_draw_doing_assy; -void pcb_lighten_color(const char *orig, char buf[8], double factor); +void pcb_lighten_color(const pcb_color_t *orig, pcb_color_t *dst, double factor); /* Draw a series of short line segments emulating a dashed line. segs is the number of on/off segment pairs. It is guaranteed that the line starts @@ -131,7 +131,7 @@ void pcb_draw_layer_under(pcb_board_t *pcb, const pcb_layer_t *Layer, const pcb_box_t *screen, pcb_data_t *data); /* Composite draw all layer groups matching lyt/purpi/purpose */ -void pcb_draw_groups(pcb_board_t *pcb, pcb_layer_type_t lyt, int purpi, char *purpose, const pcb_box_t *screen, const char *default_color, pcb_layer_type_t pstk_lyt_match, int thin_draw, int invert); +void pcb_draw_groups(pcb_board_t *pcb, pcb_layer_type_t lyt, int purpi, char *purpose, const pcb_box_t *screen, const pcb_color_t *default_color, pcb_layer_type_t pstk_lyt_match, int thin_draw, int invert); void pcb_erase_obj(int, void *, void *); Index: trunk/src/draw_composite.c =================================================================== --- trunk/src/draw_composite.c (revision 21672) +++ trunk/src/draw_composite.c (revision 21673) @@ -33,7 +33,7 @@ pcb_draw_info_t *info; const pcb_layergrp_t *grp; pcb_layergrp_id_t gid; - const char *color; + const pcb_color_t *color; unsigned thin:1; unsigned invert:1; @@ -185,7 +185,7 @@ pcb_draw_pstks(ctx->info, ctx->gid, 0, *pstk_lyt_match); } -void pcb_draw_groups(pcb_board_t *pcb, pcb_layer_type_t lyt, int purpi, char *purpose, const pcb_box_t *screen, const char *default_color, pcb_layer_type_t pstk_lyt_match, int thin_draw, int invert) +void pcb_draw_groups(pcb_board_t *pcb, pcb_layer_type_t lyt, int purpi, char *purpose, const pcb_box_t *screen, const pcb_color_t *default_color, pcb_layer_type_t pstk_lyt_match, int thin_draw, int invert) { pcb_draw_info_t info; pcb_layergrp_id_t gid; @@ -214,7 +214,7 @@ cctx.grp = g; cctx.info = &info; cctx.gid = gid; - cctx.color = ly != NULL ? ly->meta.real.color : default_color; + cctx.color = ly != NULL ? &ly->meta.real.color : default_color; cctx.thin = thin_draw; cctx.invert = invert; Index: trunk/src/draw_ly_spec.c =================================================================== --- trunk/src/draw_ly_spec.c (revision 21672) +++ trunk/src/draw_ly_spec.c (revision 21673) @@ -55,7 +55,7 @@ cctx.info = info; cctx.gid = gid; - cctx.color = ly != NULL ? ly->meta.real.color : conf_core.appearance.color.paste; + cctx.color = ly != NULL ? &ly->meta.real.color : &conf_core.appearance.color.paste; cctx.thin = conf_core.editor.thin_draw || conf_core.editor.thin_draw_poly || conf_core.editor.wireframe_draw; cctx.invert = 0; @@ -93,7 +93,7 @@ cctx.info = info; cctx.gid = gid; - cctx.color = ly != NULL ? ly->meta.real.color : conf_core.appearance.color.mask; + cctx.color = ly != NULL ? &ly->meta.real.color : &conf_core.appearance.color.mask; cctx.thin = conf_core.editor.thin_draw || conf_core.editor.thin_draw_poly || conf_core.editor.wireframe_draw; cctx.invert = pcb_gui->mask_invert; @@ -157,7 +157,7 @@ if (cctx.grp->len == 0) continue; lid = cctx.grp->lid[0]; - cctx.color = invis ? conf_core.appearance.color.invisible_objects : info->pcb->Data->Layer[lid].meta.real.color; + cctx.color = invis ? &conf_core.appearance.color.invisible_objects : &info->pcb->Data->Layer[lid].meta.real.color; cctx.thin = conf_core.editor.thin_draw || conf_core.editor.thin_draw_poly || conf_core.editor.wireframe_draw; cctx.invert = 0; @@ -267,7 +267,7 @@ pcb_gui->set_drawing_mode(PCB_HID_COMP_RESET, pcb_draw_out.direct, info->drawn_area); pcb_gui->set_drawing_mode(PCB_HID_COMP_POSITIVE, pcb_draw_out.direct, info->drawn_area); - pcb_gui->set_color(pcb_draw_out.fgGC, PCB->Data->Layer[goutl->lid[0]].meta.real.color); + pcb_gui->set_color(pcb_draw_out.fgGC, &PCB->Data->Layer[goutl->lid[0]].meta.real.color); pcb_hid_set_line_cap(pcb_draw_out.fgGC, pcb_cap_round); pcb_hid_set_line_width(pcb_draw_out.fgGC, conf_core.design.min_wid); pcb_gui->draw_rect(pcb_draw_out.fgGC, 0, 0, PCB->MaxWidth, PCB->MaxHeight); Index: trunk/src/hid.h =================================================================== --- trunk/src/hid.h (revision 21672) +++ trunk/src/hid.h (revision 21673) @@ -120,8 +120,8 @@ const char *tip; /* tooltip */ const char *checked; const char *update_on; - const char *foreground; - const char *background; + const pcb_color_t *foreground; + const pcb_color_t *background; const char *cookie; /* used for cookie based removal */ } pcb_menu_prop_t; @@ -241,11 +241,11 @@ A GUI hid should set the coord_per_pix value here for proper optimization. */ void (*render_burst)(pcb_burst_op_t op, const pcb_box_t *screen); - /* Sets a color. Names can be like "red" or "#rrggbb" or special - names like "drill". Always use the "drill" color to draw holes. + /* Sets a color. Can be one of the special colors like pcb_color_drill. + (Always use the drill color to draw holes and slots). You may assume this is cheap enough to call inside the redraw callback, but not cheap enough to call for each item drawn. */ - void (*set_color)(pcb_hid_gc_t gc, const char *name); + void (*set_color)(pcb_hid_gc_t gc, const pcb_color_t *color); /* Sets the line style. While calling this is cheap, calling it with different values each time may be expensive, so grouping items by Index: trunk/src/hid_nogui.c =================================================================== --- trunk/src/hid_nogui.c (revision 21672) +++ trunk/src/hid_nogui.c (revision 21673) @@ -109,7 +109,7 @@ /* the HID may decide to ignore this hook */ } -static void nogui_set_color(pcb_hid_gc_t gc, const char *name) +static void nogui_set_color(pcb_hid_gc_t gc, const pcb_color_t *name) { CRASH("set_color"); } Index: trunk/src/layer.c =================================================================== --- trunk/src/layer.c (revision 21672) +++ trunk/src/layer.c (revision 21673) @@ -147,7 +147,6 @@ pcb_r_destroy_tree(&layer->text_tree); if (layer->polygon_tree) pcb_r_destroy_tree(&layer->polygon_tree); - free(layer->meta.real.color); } free((char *)layer->name); memset(layer, 0, sizeof(pcb_layer_t)); @@ -523,7 +522,7 @@ pcb->Data->Layer[id].meta.real.vis = pcb->Data->Layer[pcb->LayerGroups.grp[grp].lid[0]].meta.real.vis; } pcb->Data->Layer[id].meta.real.grp = grp; - pcb->Data->Layer[id].meta.real.color = pcb_strdup(pcb_layer_default_color(id, (grp < 0) ? 0 : pcb->LayerGroups.grp[grp].ltype)); + pcb->Data->Layer[id].meta.real.color = *pcb_layer_default_color(id, (grp < 0) ? 0 : pcb->LayerGroups.grp[grp].ltype); pcb->Data->Layer[id].parent_type = PCB_PARENT_DATA; pcb->Data->Layer[id].parent.data = pcb->Data; @@ -548,12 +547,11 @@ return pcb_layer_rename_(&data->Layer[layer], pcb_strdup(lname)); } -int pcb_layer_recolor_(pcb_layer_t *Layer, char *color) +int pcb_layer_recolor_(pcb_layer_t *Layer, const pcb_color_t *color) { if (Layer->is_bound) return -1; - free(Layer->meta.real.color); - Layer->meta.real.color = color; + Layer->meta.real.color = *color; pcb_event(PCB_EVENT_LAYERS_CHANGED, NULL); return 0; } @@ -560,7 +558,9 @@ int pcb_layer_recolor(pcb_data_t *data, pcb_layer_id_t layer, const char *color) { - return pcb_layer_rename_(&data->Layer[layer], pcb_strdup(color)); + pcb_color_t clr; + pcb_color_load_str(&clr, color); + return pcb_layer_recolor_(&data->Layer[layer], &clr); } #undef APPEND @@ -604,18 +604,18 @@ ar->link.parent = &dst->Arc.lst; } -const char *pcb_layer_default_color(int idx, pcb_layer_type_t lyt) +const pcb_color_t *pcb_layer_default_color(int idx, pcb_layer_type_t lyt) { const int clrs = sizeof(conf_core.appearance.color.layer) / sizeof(conf_core.appearance.color.layer[0]); if (lyt & PCB_LYT_MASK) - return conf_core.appearance.color.mask; + return &conf_core.appearance.color.mask; if (lyt & PCB_LYT_PASTE) - return conf_core.appearance.color.paste; + return &conf_core.appearance.color.paste; if (lyt & PCB_LYT_SILK) - return conf_core.appearance.color.element; + return &conf_core.appearance.color.element; - return conf_core.appearance.color.layer[idx % clrs]; + return &conf_core.appearance.color.layer[idx % clrs]; } /* Initialize a new layer with safe initial values */ @@ -625,7 +625,7 @@ lp->meta.real.grp = gid; lp->meta.real.vis = 1; lp->name = pcb_strdup("New Layer"); - lp->meta.real.color = pcb_strdup(pcb_layer_default_color(idx, (gid >= 0) ? pcb->LayerGroups.grp[gid].ltype : 0)); + lp->meta.real.color = *pcb_layer_default_color(idx, (gid >= 0) ? pcb->LayerGroups.grp[gid].ltype : 0); if ((gid >= 0) && (pcb->LayerGroups.grp[gid].len == 0)) { /*When adding the first layer in a group, set up comb flags automatically */ switch((pcb->LayerGroups.grp[gid].ltype) & PCB_LYT_ANYTHING) { case PCB_LYT_MASK: lp->comb = PCB_LYC_AUTO | PCB_LYC_SUB; break; Index: trunk/src/layer.h =================================================================== --- trunk/src/layer.h (revision 21672) +++ trunk/src/layer.h (revision 21673) @@ -110,6 +110,7 @@ #include "globalconst.h" #include "global_typedefs.h" #include "attrib.h" +#include "color.h" #include "obj_common.h" #include "obj_arc_list.h" #include "obj_line_list.h" @@ -135,7 +136,7 @@ struct { /* A real board layer */ pcb_layergrp_id_t grp; /* the group this layer is in (cross-reference) */ pcb_bool vis; /* visible flag */ - char *color; /* strdup'd */ + pcb_color_t color; /* copied */ int no_drc; /* whether to ignore the layer when checking the design rules */ const char *cookie; /* for UI layers: registration cookie; NULL for unused UI layers */ pcb_xform_t xform; /* layer specified rendering transformation */ @@ -179,7 +180,7 @@ typedef struct { const char *name, *abbrev; - char * const *force_color; + pcb_color_t const *force_color; const char *select_name; int vis_offs, sel_offs; } pcb_menu_layers_t; @@ -278,16 +279,18 @@ const char *pcb_layer_name(pcb_data_t *data, pcb_layer_id_t id); /* Return the default color for a new layer from the config */ -const char *pcb_layer_default_color(int idx, pcb_layer_type_t lyt); +const pcb_color_t *pcb_layer_default_color(int idx, pcb_layer_type_t lyt); /* Rename/recolor an existing layer by idx */ int pcb_layer_rename(pcb_data_t *data, pcb_layer_id_t layer, const char *lname); int pcb_layer_recolor(pcb_data_t *data, pcb_layer_id_t layer, const char *lcolor); -/* changes the name/color of a layer; string has to be allocated by the caller (pcb_strdup) */ +/* changes the color of a layer; string has to be allocated by the caller (pcb_strdup) */ int pcb_layer_rename_(pcb_layer_t *Layer, char *Name); -int pcb_layer_recolor_(pcb_layer_t *Layer, char *color); +/* Low level layer color change, parsed color must be available */ +int pcb_layer_recolor_(pcb_layer_t *Layer, const pcb_color_t *color); + /* index is 0..PCB_MAX_LAYER-1. If old_index is -1, a new layer is inserted at that index. If new_index is -1, the specified layer is deleted. Returns non-zero on error, zero if OK. */ Index: trunk/src/layer_ui.c =================================================================== --- trunk/src/layer_ui.c (revision 21672) +++ trunk/src/layer_ui.c (revision 21673) @@ -39,7 +39,7 @@ vtp0_t pcb_uilayers; -pcb_layer_t *pcb_uilayer_alloc(const char *cookie, const char *name, const char *color) +pcb_layer_t *pcb_uilayer_alloc(const char *cookie, const char *name, const pcb_color_t *color) { int n; pcb_layer_t *l; @@ -62,7 +62,7 @@ *p = l; found:; l->meta.real.cookie = cookie; - l->meta.real.color = pcb_strdup(color); + l->meta.real.color = *color; l->name = pcb_strdup(name); l->meta.real.vis = 1; l->parent_type = PCB_PARENT_UI; Index: trunk/src/layer_ui.h =================================================================== --- trunk/src/layer_ui.h (revision 21672) +++ trunk/src/layer_ui.h (revision 21673) @@ -39,7 +39,7 @@ /* list of all UI layers - each item is a persistent pointer to a layer struct */ extern vtp0_t pcb_uilayers; -pcb_layer_t *pcb_uilayer_alloc(const char *cookie, const char *name, const char *color); +pcb_layer_t *pcb_uilayer_alloc(const char *cookie, const char *name, const pcb_color_t *color); void pcb_uilayer_free(pcb_layer_t *l); void pcb_uilayer_free_all_cookie(const char *cookie); void pcb_uilayer_uninit(void); Index: trunk/src/obj_arc.c =================================================================== --- trunk/src/obj_arc.c (revision 21672) +++ trunk/src/obj_arc.c (revision 21673) @@ -967,8 +967,8 @@ static void pcb_arc_draw(pcb_draw_info_t *info, pcb_arc_t *arc, int allow_term_gfx) { - const char *color; - char buf[sizeof("#XXXXXX")]; + const pcb_color_t *color; + pcb_color_t buf; const pcb_layer_t *layer = info->layer != NULL ? info->layer : pcb_layer_get_real(arc->parent.layer); if (layer == NULL) /* if the layer is inbound, e.g. in preview, fall back using the layer recipe */ @@ -975,29 +975,28 @@ layer = arc->parent.layer; if (PCB_FLAG_TEST(PCB_FLAG_WARN, arc)) - color = conf_core.appearance.color.warn; + color = &conf_core.appearance.color.warn; else if (PCB_FLAG_TEST(PCB_FLAG_SELECTED | PCB_FLAG_FOUND, arc)) { if (PCB_FLAG_TEST(PCB_FLAG_SELECTED, arc)) { if (layer->is_bound) PCB_OBJ_COLOR_ON_BOUND_LAYER(color, layer, 1); else - color = conf_core.appearance.color.selected; + color = &conf_core.appearance.color.selected; } else - color = conf_core.appearance.color.connected; + color = &conf_core.appearance.color.connected; } else if (PCB_HAS_COLOROVERRIDE(arc)) { - color = (arc->override_color); + color = arc->override_color; } else if (layer->is_bound) PCB_OBJ_COLOR_ON_BOUND_LAYER(color, layer, 0); else - color = layer->meta.real.color; + color = &layer->meta.real.color; if (PCB_FLAG_TEST(PCB_FLAG_ONPOINT, arc)) { - assert(color != NULL); - pcb_lighten_color(color, buf, 1.75); - color = buf; + pcb_lighten_color(color, &buf, 1.75); + color = &buf; } pcb_gui->set_color(pcb_draw_out.fgGC, color); pcb_arc_draw_(info, arc, allow_term_gfx); Index: trunk/src/obj_common.h =================================================================== --- trunk/src/obj_common.h (revision 21672) +++ trunk/src/obj_common.h (revision 21673) @@ -187,7 +187,7 @@ void *ratconn; \ unsigned char thermal; \ unsigned char intconn, intnoconn; \ - char override_color[sizeof("#XXXXXX")] + const pcb_color_t *override_color /* Lines, pads, and rats all use this so they can be cross-cast. */ #define PCB_ANYLINEFIELDS \ @@ -248,18 +248,18 @@ pcb_layergrp_id_t grp = -1; \ if (layer->meta.bound.type & PCB_LYT_SILK) { \ if (sel) {\ - dst = conf_core.appearance.color.selected; \ + dst = &conf_core.appearance.color.selected; \ } \ else {\ if (layer != NULL) { \ pcb_layer_t *ly = pcb_layer_get_real(layer); \ if (ly != NULL) \ - dst = ly->meta.real.color; \ + dst = &ly->meta.real.color; \ else \ - dst = conf_core.appearance.color.element; \ + dst = &conf_core.appearance.color.element; \ } \ else \ - dst = conf_core.appearance.color.element; \ + dst = &conf_core.appearance.color.element; \ } \ break; \ } \ @@ -270,25 +270,25 @@ lid = g->lid[0]; \ if ((lid >= 0) && (lid <= PCB_MAX_LAYER)) { \ if (sel) \ - dst = conf_core.appearance.color.selected; \ + dst = &conf_core.appearance.color.selected; \ else {\ if (layer != NULL) { \ pcb_layer_t *ly = pcb_layer_get_real(layer); \ if (ly != NULL) \ - dst = ly->meta.real.color; \ + dst = &ly->meta.real.color; \ else \ - dst = conf_core.appearance.color.layer[lid]; \ + dst = &conf_core.appearance.color.layer[lid]; \ } \ else \ - dst = conf_core.appearance.color.layer[lid]; \ + dst = &conf_core.appearance.color.layer[lid]; \ } \ break; \ } \ } \ if (sel) \ - dst = conf_core.appearance.color.selected; \ + dst = &conf_core.appearance.color.selected; \ else \ - dst = conf_core.appearance.color.invisible_objects; \ + dst = &conf_core.appearance.color.invisible_objects; \ } while(0) /* check if an object has clearance to polygon */ @@ -304,10 +304,7 @@ PCB_POLY_HAS_CLEARANCE(obj) : PCB_NONPOLY_HAS_CLEARANCE(obj) \ ) -#define PCB_HAS_COLOROVERRIDE(obj) \ - ( \ - (obj->override_color[0] == '#') \ - ) +#define PCB_HAS_COLOROVERRIDE(obj) ((obj)->override_color != NULL) /* a pointer is created from index addressing because the base pointer * may change when new memory is allocated; Index: trunk/src/obj_line.c =================================================================== --- trunk/src/obj_line.c (revision 21672) +++ trunk/src/obj_line.c (revision 21673) @@ -1110,8 +1110,8 @@ static void pcb_line_draw(pcb_draw_info_t *info, pcb_line_t *line, int allow_term_gfx) { - const char *color; - char buf[sizeof("#XXXXXX")]; + const pcb_color_t *color; + pcb_color_t buf; const pcb_layer_t *layer = info->layer != NULL ? info->layer : pcb_layer_get_real(line->parent.layer); if (layer == NULL) /* if the layer is inbound, e.g. in preview, fall back using the layer recipe */ @@ -1118,29 +1118,28 @@ layer = line->parent.layer; if (PCB_FLAG_TEST(PCB_FLAG_WARN, line)) - color = conf_core.appearance.color.warn; + color = &conf_core.appearance.color.warn; else if (PCB_FLAG_TEST(PCB_FLAG_SELECTED | PCB_FLAG_FOUND, line)) { if (PCB_FLAG_TEST(PCB_FLAG_SELECTED, line)) { if (layer->is_bound) PCB_OBJ_COLOR_ON_BOUND_LAYER(color, layer, 1); else - color = conf_core.appearance.color.selected; + color = &conf_core.appearance.color.selected; } else - color = conf_core.appearance.color.connected; + color = &conf_core.appearance.color.connected; } else if (PCB_HAS_COLOROVERRIDE(line)) { - color = (line->override_color); + color = line->override_color; } else if (layer->is_bound) PCB_OBJ_COLOR_ON_BOUND_LAYER(color, layer, 0); else - color = layer->meta.real.color; + color = &layer->meta.real.color; if (PCB_FLAG_TEST(PCB_FLAG_ONPOINT, line)) { - assert(color != NULL); - pcb_lighten_color(color, buf, 1.75); - color = buf; + pcb_lighten_color(color, &buf, 1.75); + color = &buf; } pcb_gui->set_color(pcb_draw_out.fgGC, color); Index: trunk/src/obj_poly.c =================================================================== --- trunk/src/obj_poly.c (revision 21672) +++ trunk/src/obj_poly.c (revision 21673) @@ -1202,8 +1202,8 @@ static void pcb_poly_draw(pcb_draw_info_t *info, pcb_poly_t *polygon, int allow_term_gfx) { - static const char *color; - char buf[sizeof("#XXXXXX")]; + static const pcb_color_t *color; + pcb_color_t buf; const pcb_layer_t *layer = info->layer != NULL ? info->layer : pcb_layer_get_real(polygon->parent.layer); if (layer == NULL) /* if the layer is inbound, e.g. in preview, fall back using the layer recipe */ @@ -1210,27 +1210,26 @@ layer = polygon->parent.layer; if (PCB_FLAG_TEST(PCB_FLAG_WARN, polygon)) - color = conf_core.appearance.color.warn; + color = &conf_core.appearance.color.warn; else if (PCB_FLAG_TEST(PCB_FLAG_SELECTED, polygon)) { if (layer->is_bound) PCB_OBJ_COLOR_ON_BOUND_LAYER(color, layer, 1); else - color = conf_core.appearance.color.selected; + color = &conf_core.appearance.color.selected; } else if (PCB_FLAG_TEST(PCB_FLAG_FOUND, polygon)) - color = conf_core.appearance.color.connected; + color = &conf_core.appearance.color.connected; else if (PCB_FLAG_TEST(PCB_FLAG_ONPOINT, polygon)) { - assert(color != NULL); - pcb_lighten_color(color, buf, 1.75); - color = buf; + pcb_lighten_color(color, &buf, 1.75); + color = &buf; } else if (PCB_HAS_COLOROVERRIDE(polygon)) { - color = (polygon->override_color); + color = polygon->override_color; } else if (layer->is_bound) PCB_OBJ_COLOR_ON_BOUND_LAYER(color, layer, 0); else - color = layer->meta.real.color; + color = &layer->meta.real.color; pcb_gui->set_color(pcb_draw_out.fgGC, color); pcb_poly_draw_(info, polygon, allow_term_gfx); Index: trunk/src/obj_pstk.c =================================================================== --- trunk/src/obj_pstk.c (revision 21672) +++ trunk/src/obj_pstk.c (revision 21673) @@ -330,14 +330,14 @@ static void set_ps_color(pcb_pstk_t *ps, int is_current, pcb_layer_type_t lyt, const pcb_layer_t *ly1) { - const char *color, *layer_color = NULL; - char buf[sizeof("#XXXXXX")]; + const pcb_color_t *color, *layer_color = NULL; + pcb_color_t buf; if ((lyt & PCB_LYT_PASTE) || (lyt & PCB_LYT_MASK) || (lyt & PCB_LYT_SILK)) { if (ly1 == NULL) layer_color = pcb_layer_default_color(0, lyt); else - layer_color = ly1->meta.real.color; + layer_color = &ly1->meta.real.color; } if (ps->term == NULL) { @@ -344,16 +344,15 @@ /* normal via, not a terminal */ if (!pcb_draw_force_termlab && PCB_FLAG_TEST(PCB_FLAG_WARN | PCB_FLAG_SELECTED | PCB_FLAG_FOUND, ps)) { if (PCB_FLAG_TEST(PCB_FLAG_WARN, ps)) - color = conf_core.appearance.color.warn; + color = &conf_core.appearance.color.warn; else if (PCB_FLAG_TEST(PCB_FLAG_SELECTED, ps)) - color = conf_core.appearance.color.selected; + color = &conf_core.appearance.color.selected; else - color = conf_core.appearance.color.connected; + color = &conf_core.appearance.color.connected; if (PCB_FLAG_TEST(PCB_FLAG_ONPOINT, ps)) { - assert(color != NULL); - pcb_lighten_color(color, buf, 1.75); - color = buf; + pcb_lighten_color(color, &buf, 1.75); + color = &buf; } } else { @@ -362,9 +361,9 @@ else if (PCB_HAS_COLOROVERRIDE(ps)) color = ps->override_color; else if (is_current) - color = conf_core.appearance.color.via; + color = &conf_core.appearance.color.via; else - color = conf_core.appearance.color.via_far; + color = &conf_core.appearance.color.via_far; } } else { @@ -371,16 +370,15 @@ /* terminal */ if (!pcb_draw_force_termlab && PCB_FLAG_TEST(PCB_FLAG_WARN | PCB_FLAG_SELECTED | PCB_FLAG_FOUND, ps)) { if (PCB_FLAG_TEST(PCB_FLAG_WARN, ps)) - color = conf_core.appearance.color.warn; + color = &conf_core.appearance.color.warn; else if (PCB_FLAG_TEST(PCB_FLAG_SELECTED, ps)) - color = conf_core.appearance.color.selected; + color = &conf_core.appearance.color.selected; else - color = conf_core.appearance.color.connected; + color = &conf_core.appearance.color.connected; if (PCB_FLAG_TEST(PCB_FLAG_ONPOINT, ps)) { - assert(color != NULL); - pcb_lighten_color(color, buf, 1.75); - color = buf; + pcb_lighten_color(color, &buf, 1.75); + color = &buf; } } else @@ -389,9 +387,9 @@ else if (PCB_HAS_COLOROVERRIDE(ps)) color = ps->override_color; else if (is_current) - color = conf_core.appearance.color.pin; + color = &conf_core.appearance.color.pin; else - color = conf_core.appearance.color.pin_far; + color = &conf_core.appearance.color.pin_far; } @@ -401,7 +399,7 @@ static void set_ps_annot_color(pcb_hid_gc_t gc, pcb_pstk_t *ps) { pcb_gui->set_color(pcb_draw_out.fgGC, PCB_FLAG_TEST(PCB_FLAG_SELECTED, ps) ? - conf_core.appearance.color.selected : conf_core.appearance.color.padstackmark); + &conf_core.appearance.color.selected : &conf_core.appearance.color.padstackmark); } static void pcb_pstk_draw_poly(pcb_draw_info_t *info, pcb_hid_gc_t gc, pcb_pstk_t *ps, pcb_pstk_shape_t *shape, int fill, pcb_coord_t dthick) @@ -651,7 +649,7 @@ if (!proto->hplated) { pcb_coord_t r = proto->hdia / 2; r -= r/8; /* +12.5% */ - pcb_gui->set_color(pcb_draw_out.fgGC, PCB_FLAG_TEST(PCB_FLAG_SELECTED, ps) ? conf_core.appearance.color.selected : conf_core.appearance.color.subc); + pcb_gui->set_color(pcb_draw_out.fgGC, PCB_FLAG_TEST(PCB_FLAG_SELECTED, ps) ? &conf_core.appearance.color.selected : &conf_core.appearance.color.subc); pcb_hid_set_line_width(pcb_draw_out.fgGC, 0); pcb_gui->draw_arc(pcb_draw_out.fgGC, ps->x, ps->y, r, r, 20, 290); } Index: trunk/src/obj_rat.c =================================================================== --- trunk/src/obj_rat.c (revision 21672) +++ trunk/src/obj_rat.c (revision 21673) @@ -239,15 +239,15 @@ if (PCB_FLAG_TEST(PCB_FLAG_SELECTED | PCB_FLAG_FOUND, rat)) { if (PCB_FLAG_TEST(PCB_FLAG_SELECTED, rat)) - pcb_gui->set_color(pcb_draw_out.fgGC, conf_core.appearance.color.selected); + pcb_gui->set_color(pcb_draw_out.fgGC, &conf_core.appearance.color.selected); else - pcb_gui->set_color(pcb_draw_out.fgGC, conf_core.appearance.color.connected); + pcb_gui->set_color(pcb_draw_out.fgGC, &conf_core.appearance.color.connected); } else if (PCB_HAS_COLOROVERRIDE(rat)) { pcb_gui->set_color(pcb_draw_out.fgGC, rat->override_color); } else - pcb_gui->set_color(pcb_draw_out.fgGC, conf_core.appearance.color.rat); + pcb_gui->set_color(pcb_draw_out.fgGC, &conf_core.appearance.color.rat); if (conf_core.appearance.rat_thickness < 20) rat->Thickness = pcb_pixel_slop * conf_core.appearance.rat_thickness; Index: trunk/src/obj_subc.c =================================================================== --- trunk/src/obj_subc.c (revision 21672) +++ trunk/src/obj_subc.c (revision 21673) @@ -1592,7 +1592,7 @@ pcb_box_t *bb = &subc->BoundingBox; int selected = PCB_FLAG_TEST(PCB_FLAG_SELECTED, subc); int freq = conf_core.appearance.subc.dash_freq; - const char *nnclr; + const pcb_color_t *nnclr; draw_subc_per_layer(); @@ -1599,8 +1599,8 @@ if (freq > 32) freq = 32; - nnclr = (PCB_FLAG_TEST(PCB_FLAG_NONETLIST, subc)) ? conf_core.appearance.color.subc_nonetlist : conf_core.appearance.color.subc; - pcb_gui->set_color(pcb_draw_out.fgGC, selected ? conf_core.appearance.color.selected : nnclr); + nnclr = (PCB_FLAG_TEST(PCB_FLAG_NONETLIST, subc)) ? &conf_core.appearance.color.subc_nonetlist : &conf_core.appearance.color.subc; + pcb_gui->set_color(pcb_draw_out.fgGC, selected ? &conf_core.appearance.color.selected : nnclr); pcb_subc_draw_origin(pcb_draw_out.fgGC, subc, 0, 0); if (freq >= 0) { Index: trunk/src/obj_text.c =================================================================== --- trunk/src/obj_text.c (revision 21672) +++ trunk/src/obj_text.c (revision 21673) @@ -1230,23 +1230,23 @@ if (PCB_FLAG_TEST(PCB_FLAG_SELECTED, text)) { if (layer->is_bound) { - const char *color; + const pcb_color_t *color; PCB_OBJ_COLOR_ON_BOUND_LAYER(color, layer, 1); pcb_gui->set_color(pcb_draw_out.fgGC, color); } else - pcb_gui->set_color(pcb_draw_out.fgGC, conf_core.appearance.color.selected); + pcb_gui->set_color(pcb_draw_out.fgGC, &conf_core.appearance.color.selected); } else if (PCB_HAS_COLOROVERRIDE(text)) { pcb_gui->set_color(pcb_draw_out.fgGC, text->override_color); } else if (layer->is_bound) { - const char *color; + const pcb_color_t *color; PCB_OBJ_COLOR_ON_BOUND_LAYER(color, layer, 0); pcb_gui->set_color(pcb_draw_out.fgGC, color); } else - pcb_gui->set_color(pcb_draw_out.fgGC, layer->meta.real.color); + pcb_gui->set_color(pcb_draw_out.fgGC, &layer->meta.real.color); if ((!layer->is_bound) && (layer->meta.real.grp >= 0)) flg = pcb_layergrp_flags(PCB, layer->meta.real.grp); Index: trunk/src/route.c =================================================================== --- trunk/src/route.c (revision 21672) +++ trunk/src/route.c (revision 21673) @@ -676,7 +676,7 @@ pcb_layer_t *layer = pcb_get_layer(PCB->Data, p_obj->layer); if (layer) - pcb_gui->set_color(GC, layer->meta.real.color); + pcb_gui->set_color(GC, &layer->meta.real.color); switch (p_obj->type) { case PCB_OBJ_LINE: @@ -701,7 +701,7 @@ pcb_coord_t thickness = p_route->thickness + 2 * conf_core.design.bloat; int i; - pcb_gui->set_color(GC, conf_core.appearance.color.cross); + pcb_gui->set_color(GC, &conf_core.appearance.color.cross); for(i = 0; i < p_route->size; ++i) { const pcb_route_object_t *p_obj = &p_route->objects[i]; Index: trunk/src/stub_draw.c =================================================================== --- trunk/src/stub_draw.c (revision 21672) +++ trunk/src/stub_draw.c (revision 21673) @@ -35,7 +35,7 @@ { pcb_text_t t; - pcb_gui->set_color(gc, "#FF0000"); + pcb_gui->set_color(gc, pcb_color_red); memset(&t, 0, sizeof(t)); t.TextString = (char *)str; Index: trunk/src/tool_arc.c =================================================================== --- trunk/src/tool_arc.c (revision 21672) +++ trunk/src/tool_arc.c (revision 21673) @@ -137,15 +137,15 @@ if (pcb_crosshair.AttachedBox.State != PCB_CH_STATE_FIRST) { pcb_xordraw_attached_arc(conf_core.design.line_thickness); if (conf_core.editor.show_drc) { - pcb_gui->set_color(pcb_crosshair.GC, conf_core.appearance.color.cross); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.cross); pcb_xordraw_attached_arc(conf_core.design.line_thickness + 2 * (conf_core.design.bloat + 1)); - pcb_gui->set_color(pcb_crosshair.GC, conf_core.appearance.color.crosshair); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.crosshair); } } else { /* Draw a circle (0 length line) to show where the arc will start when placed */ if(CURRENT) - pcb_gui->set_color(pcb_crosshair.GC,CURRENT->meta.real.color); + pcb_gui->set_color(pcb_crosshair.GC, &CURRENT->meta.real.color); pcb_draw_wireframe_line(pcb_crosshair.GC, pcb_crosshair.X, pcb_crosshair.Y, @@ -153,12 +153,12 @@ conf_core.design.line_thickness, 0); if(conf_core.editor.show_drc) { - pcb_gui->set_color(pcb_crosshair.GC,conf_core.appearance.color.cross); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.cross); pcb_draw_wireframe_line(pcb_crosshair.GC, pcb_crosshair.X, pcb_crosshair.Y, pcb_crosshair.X, pcb_crosshair.Y, conf_core.design.line_thickness + (2 * conf_core.design.bloat), 0); - pcb_gui->set_color(pcb_crosshair.GC, conf_core.appearance.color.crosshair); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.crosshair); } } Index: trunk/src/tool_line.c =================================================================== --- trunk/src/tool_line.c (revision 21672) +++ trunk/src/tool_line.c (revision 21673) @@ -347,12 +347,12 @@ pcb_route_draw(&pcb_crosshair.Route,pcb_crosshair.GC); if (conf_core.editor.show_drc) pcb_route_draw_drc(&pcb_crosshair.Route,pcb_crosshair.GC); - pcb_gui->set_color(pcb_crosshair.GC, conf_core.appearance.color.crosshair); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.crosshair); } else { /* Draw a circle (0 length line) to show where the line will be placed */ if (CURRENT) - pcb_gui->set_color(pcb_crosshair.GC,CURRENT->meta.real.color); + pcb_gui->set_color(pcb_crosshair.GC, &CURRENT->meta.real.color); pcb_draw_wireframe_line(pcb_crosshair.GC, pcb_crosshair.X, pcb_crosshair.Y, @@ -360,12 +360,12 @@ conf_core.design.line_thickness,0 ); if (conf_core.editor.show_drc) { - pcb_gui->set_color(pcb_crosshair.GC,conf_core.appearance.color.cross); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.cross); pcb_draw_wireframe_line(pcb_crosshair.GC, pcb_crosshair.X, pcb_crosshair.Y, pcb_crosshair.X, pcb_crosshair.Y, conf_core.design.line_thickness + (2 * conf_core.design.bloat), 0); - pcb_gui->set_color(pcb_crosshair.GC, conf_core.appearance.color.crosshair); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.crosshair); } } } Index: trunk/src/tool_via.c =================================================================== --- trunk/src/tool_via.c (revision 21672) +++ trunk/src/tool_via.c (revision 21673) @@ -96,9 +96,9 @@ xor_draw_fake_via(pcb_crosshair.X, pcb_crosshair.Y, conf_core.design.via_thickness, 0); if (conf_core.editor.show_drc) { /* XXX: Naughty cheat - use the mask to draw DRC clearance! */ - pcb_gui->set_color(pcb_crosshair.GC, conf_core.appearance.color.cross); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.cross); xor_draw_fake_via(pcb_crosshair.X, pcb_crosshair.Y, conf_core.design.via_thickness, conf_core.design.clearance); - pcb_gui->set_color(pcb_crosshair.GC, conf_core.appearance.color.crosshair); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.crosshair); } } Index: trunk/src/vtpadstack_t.c =================================================================== --- trunk/src/vtpadstack_t.c (revision 21672) +++ trunk/src/vtpadstack_t.c (revision 21673) @@ -1,5 +1,6 @@ #include #include +#include "color.h" #define GVT_DONT_UNDEF #include "vtpadstack_t.h" #include Index: trunk/src_plugins/acompnet/acompnet.c =================================================================== --- trunk/src_plugins/acompnet/acompnet.c (revision 21672) +++ trunk/src_plugins/acompnet/acompnet.c (revision 21673) @@ -110,9 +110,15 @@ #include "dolists.h" int pplg_init_acompnet(void) { + static pcb_color_t clr; + PCB_API_CHK_VER; + + if (clr.str[0] != '#') + pcb_color_load_str(&clr, "#c09920"); + PCB_REGISTER_ACTIONS(acompnet_action_list, acompnet_cookie) - ly = pcb_uilayer_alloc(acompnet_cookie, "autocomp-net", "#c09920"); + ly = pcb_uilayer_alloc(acompnet_cookie, "autocomp-net", &clr); return 0; } Index: trunk/src_plugins/asm/asm.c =================================================================== --- trunk/src_plugins/asm/asm.c (revision 21672) +++ trunk/src_plugins/asm/asm.c (revision 21673) @@ -88,7 +88,7 @@ typedef struct{ PCB_DAD_DECL_NOINIT(dlg) vtp0_t grps; - vtp0_t layer_colors; /* saved before greying out */ + vtclr_t layer_colors; /* saved before greying out */ int wtbl, wskipg, wdoneg, wskipp, wdonep; int active; /* already open - allow only one instance */ } asm_ctx_t; @@ -272,19 +272,6 @@ } /*** Gray out all layers to make selection stick out more ***/ -static unsigned int chr2rgb(char s) -{ - if ((s >= '0') && (s <= '9')) return s - '0'; - if ((s >= 'a') && (s <= 'f')) return s - 'a' + 10; - if ((s >= 'A') && (s <= 'F')) return s - 'A' + 10; - return 0; -} - -static int str2rgb(const char *s) -{ - return chr2rgb(s[0]) << 4 | chr2rgb(s[1]); -} - static int fade(int c, int factor) { if (c > 127) @@ -299,27 +286,25 @@ pcb_layer_t *ly; if (grey) { - vtp0_init(&asm_ctx.layer_colors); - vtp0_enlarge(&asm_ctx.layer_colors, data->LayerN); + vtclr_init(&asm_ctx.layer_colors); + vtclr_enlarge(&asm_ctx.layer_colors, data->LayerN); for(n = 0, ly = data->Layer; n < data->LayerN; n++,ly++) { int r, g, b; - vtp0_set(&asm_ctx.layer_colors, n, ly->meta.real.color); - r = str2rgb(ly->meta.real.color+1); - g = str2rgb(ly->meta.real.color+3); - b = str2rgb(ly->meta.real.color+5); + vtclr_set(&asm_ctx.layer_colors, n, ly->meta.real.color); + r = ly->meta.real.color.r; + g = ly->meta.real.color.g; + b = ly->meta.real.color.b; r = fade(r, 4); g = fade(g, 4); b = fade(b, 4); - ly->meta.real.color = pcb_strdup_printf("#%02x%02x%02x", r, g, b); + pcb_color_load_int(&ly->meta.real.color, r, g, b, 255); } } else { - for(n = 0, ly = data->Layer; n < data->LayerN; n++,ly++) { - free(ly->meta.real.color); + for(n = 0, ly = data->Layer; n < data->LayerN; n++,ly++) ly->meta.real.color = asm_ctx.layer_colors.array[n]; - } - vtp0_uninit(&asm_ctx.layer_colors); + vtclr_uninit(&asm_ctx.layer_colors); } pcb_redraw(); } Index: trunk/src_plugins/ddraft/ddraft.c =================================================================== --- trunk/src_plugins/ddraft/ddraft.c (revision 21672) +++ trunk/src_plugins/ddraft/ddraft.c (revision 21673) @@ -378,7 +378,7 @@ int n; pcb_gui->set_line_cap(pcb_crosshair.GC, pcb_cap_round); pcb_gui->set_line_width(pcb_crosshair.GC, 1); - pcb_gui->set_color(pcb_crosshair.GC, "#333333"); + pcb_gui->set_color(pcb_crosshair.GC, pcb_color_grey33); for(n = 0; n < vtc0_len(&pcb_ddraft_attached.annot_lines); n += 4) { pcb_coord_t *c = &pcb_ddraft_attached.annot_lines.array[n]; pcb_gui->draw_line(pcb_crosshair.GC, c[0], c[1], c[2], c[3]); @@ -385,7 +385,7 @@ } if (pcb_ddraft_attached.line_valid) { - pcb_gui->set_color(pcb_crosshair.GC, CURRENT->meta.real.color); + pcb_gui->set_color(pcb_crosshair.GC, &CURRENT->meta.real.color); pcb_draw_wireframe_line(pcb_crosshair.GC, pcb_ddraft_attached.line.Point1.X, pcb_ddraft_attached.line.Point1.Y, pcb_ddraft_attached.line.Point2.X, pcb_ddraft_attached.line.Point2.Y, conf_core.design.line_thickness, 0); Index: trunk/src_plugins/diag/diag.c =================================================================== --- trunk/src_plugins/diag/diag.c (revision 21672) +++ trunk/src_plugins/diag/diag.c (revision 21673) @@ -424,12 +424,16 @@ void *ptr1, *ptr2, *ptr3; const char *new_color; + pcb_message(PCB_MSG_ERROR, "pcb_acth_forcecolor() is temporarily disabled.\n"); + return -1; + PCB_ACT_CONVARG(1, FGW_STR, forcecolor, new_color = argv[1].val.str); pcb_hid_get_coords("Click on object to change", &x, &y, 0); if ((type = pcb_search_screen(x, y, PCB_FORCECOLOR_TYPES, &ptr1, &ptr2, &ptr3)) != PCB_OBJ_VOID){ - strncpy(((pcb_any_obj_t *)ptr2)->override_color, new_color, sizeof(((pcb_any_obj_t *)ptr2)->override_color)-1); +TODO("color: figure where to store this"); +/* strncpy(((pcb_any_obj_t *)ptr2)->override_color, new_color, sizeof(((pcb_any_obj_t *)ptr2)->override_color)-1);*/ } PCB_ACT_IRES(0); Index: trunk/src_plugins/dialogs/dlg_lib_pstk.c =================================================================== --- trunk/src_plugins/dialogs/dlg_lib_pstk.c (revision 21672) +++ trunk/src_plugins/dialogs/dlg_lib_pstk.c (revision 21673) @@ -165,7 +165,7 @@ pcb_pstk_draw_preview(PCB, &ps, layers, 0, 0, &e->view); - pcb_gui->set_color(gc, "#000000"); + pcb_gui->set_color(gc, pcb_color_black); pcb_hid_set_line_cap(gc, pcb_cap_round); pcb_hid_set_line_width(gc, -1); Index: trunk/src_plugins/dialogs/dlg_pinout.c =================================================================== --- trunk/src_plugins/dialogs/dlg_pinout.c (revision 21672) +++ trunk/src_plugins/dialogs/dlg_pinout.c (revision 21673) @@ -74,7 +74,7 @@ bbox.X1 = bbox.Y1 = 0; bbox.X2 = bbox.Y2 = PCB_MM_TO_COORD(10); pcb_dad_preview_zoomto(attrib, &bbox); - pcb_gui->set_color(gc, "#FF0000"); + pcb_gui->set_color(gc, pcb_color_red); pcb_text_draw_string_simple(NULL, tmp, PCB_MM_TO_COORD(1), PCB_MM_TO_COORD(20), 100, 0, 0, 0, 0, 0, 0); } } Index: trunk/src_plugins/dialogs/dlg_pref_conf.c =================================================================== --- trunk/src_plugins/dialogs/dlg_pref_conf.c (revision 21672) +++ trunk/src_plugins/dialogs/dlg_pref_conf.c (revision 21673) @@ -210,7 +210,7 @@ case CFN_REAL: sprintf(buf, "%f", *val->real); break; case CFN_COORD: pcb_snprintf(buf, sizebuf, "%mH\n%mm\n%ml", *val->coord, *val->coord, *val->coord); break; case CFN_UNIT: strcpy(buf, (*val->unit)->suffix); break; - case CFN_COLOR: strcpy(buf, *val->color); break; + case CFN_COLOR: strcpy(buf, val->color->str); break; case CFN_LIST: strcpy(buf, ""); break; case CFN_max: strcpy(buf, ""); break; } Index: trunk/src_plugins/dialogs/dlg_pref_confedit.c =================================================================== --- trunk/src_plugins/dialogs/dlg_pref_confedit.c (revision 21672) +++ trunk/src_plugins/dialogs/dlg_pref_confedit.c (revision 21673) @@ -116,7 +116,7 @@ return; } - if (ctx->idx >= pctx->conf.selected_nat->array_size) { + if (pctx->conf.selected_idx >= pctx->conf.selected_nat->array_size) { pcb_message(PCB_MSG_ERROR, "Internal error: array index out of bounds\n"); return; } Index: trunk/src_plugins/dialogs/dlg_test.c =================================================================== --- trunk/src_plugins/dialogs/dlg_test.c (revision 21672) +++ trunk/src_plugins/dialogs/dlg_test.c (revision 21673) @@ -325,7 +325,7 @@ static void prv_expose(pcb_hid_attribute_t *attrib, pcb_hid_preview_t *prv, pcb_hid_gc_t gc, const pcb_hid_expose_ctx_t *e) { - pcb_gui->set_color(gc, "#FF0000"); + pcb_gui->set_color(gc, pcb_color_red); pcb_text_draw_string_simple(NULL, "foo", PCB_MM_TO_COORD(1), PCB_MM_TO_COORD(20), 500, 10.0, 0, 0, 0, 0, 0); printf("expose in dlg_test!\n"); Index: trunk/src_plugins/dialogs/dlg_view.c =================================================================== --- trunk/src_plugins/dialogs/dlg_view.c (revision 21672) +++ trunk/src_plugins/dialogs/dlg_view.c (revision 21673) @@ -201,7 +201,7 @@ view_ctx_t *ctx = prv->user_ctx; pcb_xform_t xform; int old_termlab, g; - static const char *offend_color[] = {"#ff0000", "#0000ff"}; + static const pcb_color_t *offend_color[2]; pcb_view_t *v = pcb_view_by_uid(ctx->lst, ctx->selected); size_t n; void **p; @@ -209,6 +209,9 @@ if (v == NULL) return; + offend_color[0] = pcb_color_red; + offend_color[1] = pcb_color_blue; + /* NOTE: zoom box was already set on select */ /* save offending object colors */ @@ -219,13 +222,11 @@ pcb_any_obj_t *obj = pcb_idpath2obj(ctx->pcb->Data, i); if ((obj != NULL) && (obj->type & PCB_OBJ_CLASS_REAL)) { vtp0_append(&view_color_save, obj); - if (obj->override_color != NULL) { - char *save = pcb_strdup(obj->override_color); - vtp0_append(&view_color_save, save); - } + if (obj->override_color != NULL) + vtp0_append(&view_color_save, obj->override_color); else vtp0_append(&view_color_save, NULL); - strcpy(obj->override_color, offend_color[g]); + obj->override_color = offend_color[g]; } } } @@ -241,13 +242,8 @@ /* restore object color */ for(n = 0, p = view_color_save.array; n < view_color_save.used; n+=2,p+=2) { pcb_any_obj_t *obj = p[0]; - char *s = p[1]; - if (s != NULL) { - strcpy(obj->override_color, s); - free(s); - } - else - *obj->override_color = '\0'; + pcb_color_t *s = p[1]; + obj->override_color = s; } vtp0_truncate(&view_color_save, 0); } Index: trunk/src_plugins/draw_csect/draw_csect.c =================================================================== --- trunk/src_plugins/draw_csect/draw_csect.c (revision 21672) +++ trunk/src_plugins/draw_csect/draw_csect.c (revision 21673) @@ -43,17 +43,22 @@ extern pcb_layergrp_id_t pcb_actd_EditGroup_gid; -static const char *COLOR_ANNOT = "#000000"; -static const char *COLOR_BG = "#f0f0f0"; +static const char *COLOR_ANNOT_ = "#000000"; +static const char *COLOR_BG_ = "#f0f0f0"; -static const char *COLOR_COPPER = "#C05020"; -static const char *COLOR_SUBSTRATE = "#E0D090"; -static const char *COLOR_SILK = "#000000"; -static const char *COLOR_MASK = "#30d030"; -static const char *COLOR_PASTE = "#60e0e0"; -static const char *COLOR_MISC = "#e0e000"; -static const char *COLOR_OUTLINE = "#000000"; +static const char *COLOR_COPPER_ = "#C05020"; +static const char *COLOR_SUBSTRATE_ = "#E0D090"; +static const char *COLOR_SILK_ = "#000000"; +static const char *COLOR_MASK_ = "#30d030"; +static const char *COLOR_PASTE_ = "#60e0e0"; +static const char *COLOR_MISC_ = "#e0e000"; +static const char *COLOR_OUTLINE_ = "#000000"; + +static pcb_color_t + COLOR_ANNOT, COLOR_BG, COLOR_COPPER, COLOR_SUBSTRATE, COLOR_SILK, COLOR_MASK, + COLOR_PASTE, COLOR_MISC, COLOR_OUTLINE; + static pcb_layer_id_t drag_lid = -1; static pcb_layergrp_id_t drag_gid = -1, drag_gid_subst = -1; @@ -96,7 +101,7 @@ } /* Draw a text at x;y with a background */ -static pcb_text_t *dtext_bg(pcb_hid_gc_t gc, int x, int y, int scale, int dir, const char *txt, const char *bgcolor, const char *fgcolor) +static pcb_text_t *dtext_bg(pcb_hid_gc_t gc, int x, int y, int scale, int dir, const char *txt, const pcb_color_t *bgcolor, const pcb_color_t *fgcolor) { static pcb_text_t t; @@ -308,7 +313,7 @@ static pcb_coord_t create_button(pcb_hid_gc_t gc, int x, int y, const char *label, pcb_box_t *box) { pcb_text_t *t; - t = dtext_bg(gc, x, y, 200, 0, label, COLOR_BG, COLOR_ANNOT); + t = dtext_bg(gc, x, y, 200, 0, label, &COLOR_BG, &COLOR_ANNOT); pcb_text_bbox(pcb_font(PCB, 0, 1), t); dhrect(PCB_COORD_TO_MM(t->BoundingBox.X1), y, PCB_COORD_TO_MM(t->BoundingBox.X2)+1, y+4, 0.25, 0, 0, 0, OMIT_NONE); box->X1 = t->BoundingBox.X1; @@ -432,7 +437,7 @@ reset_layer_coords(); csect_gc = gc; - pcb_gui->set_color(gc, COLOR_ANNOT); + pcb_gui->set_color(gc, &COLOR_ANNOT); dtext(0, 0, 500, 0, "Board cross section"); /* draw physical layers */ @@ -440,7 +445,7 @@ for(gid = 0; gid < pcb_max_group(PCB); gid++) { int i, stepf = 0, stepb = 0, th; pcb_layergrp_t *g = PCB->LayerGroups.grp + gid; - const char *color = "#ff0000"; + const pcb_color_t *color; if ((!g->valid) || (gid == drag_gid) || (gid == drag_gid_subst)) continue; @@ -451,31 +456,31 @@ else stepb = -last_copper_step; th = 5; - color = COLOR_COPPER; + color = &COLOR_COPPER; } else if (g->ltype & PCB_LYT_SUBSTRATE) { stepf = stepb = 7; th = 10; - color = COLOR_SUBSTRATE; + color = &COLOR_SUBSTRATE; } else if (g->ltype & PCB_LYT_SILK) { th = 5; - color = COLOR_SILK; + color = &COLOR_SILK; stepb = 3; } else if (g->ltype & PCB_LYT_MASK) { th = 5; - color = COLOR_MASK; + color = &COLOR_MASK; stepb = 9; } else if (g->ltype & PCB_LYT_PASTE) { th = 5; - color = COLOR_PASTE; + color = &COLOR_PASTE; stepf = 9; } else if (g->ltype & PCB_LYT_MISC) { th = 5; - color = COLOR_MISC; + color = &COLOR_MISC; stepf = 3; } else if (g->ltype & PCB_LYT_BOUNDARY) { @@ -488,7 +493,7 @@ pcb_gui->set_color(gc, color); dhrect(0, y, GROUP_WIDTH_MM, y+th, 1, 0.5, stepf, stepb, OMIT_LEFT | OMIT_RIGHT); - dtext_bg(gc, 5, y, 200, 0, g->name, COLOR_BG, COLOR_ANNOT); + dtext_bg(gc, 5, y, 200, 0, g->name, &COLOR_BG, &COLOR_ANNOT); reg_group_coords(gid, PCB_MM_TO_COORD(y), PCB_MM_TO_COORD(y+th)); @@ -503,7 +508,7 @@ if (lid == drag_lid) continue; - t = dtext_bg(gc, x, y, 200, 0, l->name, COLOR_BG, l->meta.real.color); + t = dtext_bg(gc, x, y, 200, 0, l->name, &COLOR_BG, &l->meta.real.color); pcb_text_bbox(pcb_font(PCB, 0, 1), t); if (l->comb & PCB_LYC_SUB) { dhrect(PCB_COORD_TO_MM(t->BoundingBox.X1), y, PCB_COORD_TO_MM(t->BoundingBox.X2)+1, y+4, 1.2, 0, 0, 0, OMIT_NONE); @@ -511,7 +516,7 @@ } if (redraw_text) - t = dtext_bg(gc, x, y, 200, 0, l->name, COLOR_BG, l->meta.real.color); + t = dtext_bg(gc, x, y, 200, 0, l->name, &COLOR_BG, &l->meta.real.color); else dhrect(PCB_COORD_TO_MM(t->BoundingBox.X1), y, PCB_COORD_TO_MM(t->BoundingBox.X2)+1, y+4, 0.25, 0, 0, 0, OMIT_NONE); @@ -534,19 +539,19 @@ pcb_text_t *t; if (g->len > 0) { pcb_layer_t *l = &PCB->Data->Layer[g->lid[0]]; - pcb_gui->set_color(gc, l->meta.real.color); - t = dtext_bg(gc, 1, y, 200, 0, l->name, COLOR_BG, l->meta.real.color); + pcb_gui->set_color(gc, &l->meta.real.color); + t = dtext_bg(gc, 1, y, 200, 0, l->name, &COLOR_BG, &l->meta.real.color); pcb_text_bbox(pcb_font(PCB, 0, 1), t); dhrect(PCB_COORD_TO_MM(t->BoundingBox.X1), y, PCB_COORD_TO_MM(t->BoundingBox.X2)+1, y+4, 1, 0, 0, 0, OMIT_NONE); - dtext_bg(gc, 1, y, 200, 0, l->name, COLOR_BG, l->meta.real.color); + dtext_bg(gc, 1, y, 200, 0, l->name, &COLOR_BG, &l->meta.real.color); reg_layer_coords(g->lid[0], t->BoundingBox.X1, PCB_MM_TO_COORD(y), t->BoundingBox.X2+PCB_MM_TO_COORD(1), PCB_MM_TO_COORD(y+4)); } else { - pcb_gui->set_color(gc, COLOR_OUTLINE); - t = dtext_bg(gc, 1, y, 200, 0, "", COLOR_BG, COLOR_OUTLINE); + pcb_gui->set_color(gc, &COLOR_OUTLINE); + t = dtext_bg(gc, 1, y, 200, 0, "", &COLOR_BG, &COLOR_OUTLINE); pcb_text_bbox(pcb_font(PCB, 0, 1), t); dhrect(PCB_COORD_TO_MM(t->BoundingBox.X1), y, PCB_COORD_TO_MM(t->BoundingBox.X2)+1, y+4, 1, 0, 0, 0, OMIT_NONE); - dtext_bg(gc, 1, y, 200, 0, "", COLOR_BG, COLOR_OUTLINE); + dtext_bg(gc, 1, y, 200, 0, "", &COLOR_BG, &COLOR_OUTLINE); } dline(0, ystart, 0, y+4, 1); reg_outline_coords(t->BoundingBox.X1, PCB_MM_TO_COORD(y), t->BoundingBox.X2, PCB_MM_TO_COORD(y+4)); @@ -565,7 +570,7 @@ if (DRAGGING) { - pcb_gui->set_color(gc, "#000000"); + pcb_gui->set_color(gc, pcb_color_black); /* draw the actual operation */ if (drag_addgrp) { @@ -936,6 +941,16 @@ PCB_API_CHK_VER; PCB_REGISTER_ACTIONS(draw_csect_action_list, draw_csect_cookie) + pcb_color_load_str(&COLOR_ANNOT, COLOR_ANNOT_); + pcb_color_load_str(&COLOR_BG, COLOR_BG_); + pcb_color_load_str(&COLOR_COPPER, COLOR_COPPER_); + pcb_color_load_str(&COLOR_SUBSTRATE, COLOR_SUBSTRATE_); + pcb_color_load_str(&COLOR_SILK, COLOR_SILK_); + pcb_color_load_str(&COLOR_MASK, COLOR_MASK_); + pcb_color_load_str(&COLOR_PASTE, COLOR_PASTE_); + pcb_color_load_str(&COLOR_MISC, COLOR_MISC_); + pcb_color_load_str(&COLOR_OUTLINE, COLOR_OUTLINE_); + pcb_stub_draw_csect = draw_csect; pcb_stub_draw_csect_mouse_ev = mouse_csect; Index: trunk/src_plugins/draw_fab/draw_fab.c =================================================================== --- trunk/src_plugins/draw_fab/draw_fab.c (revision 21672) +++ trunk/src_plugins/draw_fab/draw_fab.c (revision 21673) @@ -234,7 +234,7 @@ plated_sym = --ds; if (drill->UnplatedCount) unplated_sym = --ds; - pcb_gui->set_color(gc, conf_core.appearance.color.pin); + pcb_gui->set_color(gc, &conf_core.appearance.color.pin); for (i = 0; i < drill->PinN; i++) { int unplated = 1; pcb_coord_t x, y; @@ -261,7 +261,7 @@ text_at(info, gc, PCB_MIL_TO_COORD(1400), yoff, PCB_MIL_TO_COORD(2), "NO"); text_at(info, gc, PCB_MIL_TO_COORD(980), yoff, PCB_MIL_TO_COORD(2), "%d", drill->UnplatedCount); } - pcb_gui->set_color(gc, conf_core.appearance.color.element); + pcb_gui->set_color(gc, &conf_core.appearance.color.element); if (conf_core.editor.grid_unit->family == PCB_UNIT_IMPERIAL) text_at(info, gc, PCB_MIL_TO_COORD(450), yoff, PCB_MIL_TO_COORD(2), "%0.3f", PCB_COORD_TO_INCH(drill->DrillSize)); else @@ -277,7 +277,7 @@ total_drills += drill->ViaCount; } - pcb_gui->set_color(gc, conf_core.appearance.color.element); + pcb_gui->set_color(gc, &conf_core.appearance.color.element); text_at(info, gc, 0, yoff, PCB_MIL_TO_COORD(9), "Symbol"); if (conf_core.editor.grid_unit->family == PCB_UNIT_IMPERIAL) text_at(info, gc, PCB_MIL_TO_COORD(410), yoff, PCB_MIL_TO_COORD(9), "Diam. (Inch)"); Index: trunk/src_plugins/draw_fontsel/draw_fontsel.c =================================================================== --- trunk/src_plugins/draw_fontsel/draw_fontsel.c (revision 21672) +++ trunk/src_plugins/draw_fontsel/draw_fontsel.c (revision 21673) @@ -78,13 +78,13 @@ int w = 2, h = 2; float th = 0.1, th2 = 0.4; - pcb_gui->set_color(gc, "#000000"); + pcb_gui->set_color(gc, pcb_color_black); dline(x0, y0, x0+w, y0, th); dline(x0+w, y0, x0+w, y0+h, th); dline(x0+w, y0+h, x0, y0+h, th); dline(x0, y0+h, x0, y0, th); if (checked) { - pcb_gui->set_color(gc, "#AA0033"); + pcb_gui->set_color(gc, pcb_color_red); dline(x0, y0, x0+w, y0+h, th2); dline(x0, y0+h, x0+w, y0, th2); } @@ -114,7 +114,7 @@ dchkbox(gc, x-4, *y, (f->id == target_fid)); - pcb_gui->set_color(gc, "#000000"); + pcb_gui->set_color(gc, pcb_color_black); t = dtext(x, *y, 200, f->id, txt); pcb_text_bbox(pcb_font(PCB, f->id, 1), t); Index: trunk/src_plugins/export_bboard/bboard.c =================================================================== --- trunk/src_plugins/export_bboard/bboard.c (revision 21672) +++ trunk/src_plugins/export_bboard/bboard.c (revision 21673) @@ -209,10 +209,9 @@ } } - if (layer->meta.real.color && (layer->meta.real.color[0] == '#')) { - if (sscanf(&(layer->meta.real.color[1]), "%02x%02x%02x", &r, &g, &b) == 3) - goto ok; - } + r = layer->meta.real.color.r; + g = layer->meta.real.color.g; + b = layer->meta.real.color.b; /* default color */ *clr_r = 0xff; Index: trunk/src_plugins/export_dxf/dxf.c =================================================================== --- trunk/src_plugins/export_dxf/dxf.c (revision 21672) +++ trunk/src_plugins/export_dxf/dxf.c (revision 21673) @@ -429,9 +429,9 @@ } } -static void dxf_set_color(pcb_hid_gc_t gc, const char *name) +static void dxf_set_color(pcb_hid_gc_t gc, const pcb_color_t *color) { - if (strcmp(name, "drill") == 0) + if (pcb_color_is_drill(color) == 0) gc->drawing_hole = 1; } Index: trunk/src_plugins/export_gcode/gcode.c =================================================================== --- trunk/src_plugins/export_gcode/gcode.c (revision 21672) +++ trunk/src_plugins/export_gcode/gcode.c (revision 21673) @@ -595,15 +595,13 @@ free(gc); } -static void gcode_set_color(pcb_hid_gc_t gc, const char *name) +static void gcode_set_color(pcb_hid_gc_t gc, const pcb_color_t *color) { if (gcode_im == NULL) { return; } - if (name == NULL) { - name = "#ff0000"; - } - if (!strcmp(name, "drill")) { +TODO("This is broken - sets color to 0 on everything"); + if (pcb_color_is_drill(color)) { gc->color = black; gc->erase = 0; return; Index: trunk/src_plugins/export_gerber/gerber.c =================================================================== --- trunk/src_plugins/export_gerber/gerber.c (revision 21672) +++ trunk/src_plugins/export_gerber/gerber.c (revision 21673) @@ -55,7 +55,7 @@ static int gerber_parse_arguments(int *argc, char ***argv); static pcb_hid_gc_t gerber_make_gc(void); static void gerber_destroy_gc(pcb_hid_gc_t gc); -static void gerber_set_color(pcb_hid_gc_t gc, const char *name); +static void gerber_set_color(pcb_hid_gc_t gc, const pcb_color_t *name); static void gerber_set_line_cap(pcb_hid_gc_t gc, pcb_cap_style_t style); static void gerber_set_line_width(pcb_hid_gc_t gc, pcb_coord_t width); static void gerber_set_draw_xor(pcb_hid_gc_t gc, int _xor); @@ -979,8 +979,8 @@ if (want_outline && !(PCB_LAYER_IS_ROUTE(flags, purpi))) { if (has_outline) { - pcb_draw_groups(PCB, PCB_LYT_BOUNDARY, F_proute, NULL, ®ion, "#000000", PCB_LYT_MECH, 0, 0); - pcb_draw_groups(PCB, PCB_LYT_BOUNDARY, F_uroute, NULL, ®ion, "#000000", PCB_LYT_MECH, 0, 0); + pcb_draw_groups(PCB, PCB_LYT_BOUNDARY, F_proute, NULL, ®ion, pcb_color_black, PCB_LYT_MECH, 0, 0); + pcb_draw_groups(PCB, PCB_LYT_BOUNDARY, F_uroute, NULL, ®ion, pcb_color_black, PCB_LYT_MECH, 0, 0); } else { pcb_hid_gc_t gc = pcb_hid_make_gc(); @@ -1019,9 +1019,9 @@ fprintf(f, "G04 hid debug composite: %d*\r\n", op); } -static void gerber_set_color(pcb_hid_gc_t gc, const char *name) +static void gerber_set_color(pcb_hid_gc_t gc, const pcb_color_t *color) { - if (strcmp(name, "drill") == 0) { + if (pcb_color_is_drill(color)) { gc->color = 1; gc->erase = 0; gc->drill = 1; Index: trunk/src_plugins/export_openems/export_openems.c =================================================================== --- trunk/src_plugins/export_openems/export_openems.c (revision 21672) +++ trunk/src_plugins/export_openems/export_openems.c (revision 21673) @@ -694,7 +694,7 @@ } } -static void openems_set_color(pcb_hid_gc_t gc, const char *name) +static void openems_set_color(pcb_hid_gc_t gc, const pcb_color_t *name) { } Index: trunk/src_plugins/export_openems/mesh.c =================================================================== --- trunk/src_plugins/export_openems/mesh.c (revision 21672) +++ trunk/src_plugins/export_openems/mesh.c (revision 21673) @@ -666,12 +666,17 @@ static void mesh_layer_reset() { + static pcb_color_t clr; + + if (clr.str[0] != '#') + pcb_color_load_str(&clr, "#007733"); + if (mesh.ui_layer_xy != NULL) pcb_uilayer_free(mesh.ui_layer_xy); if (mesh.ui_layer_z != NULL) pcb_uilayer_free(mesh.ui_layer_z); - mesh.ui_layer_xy = pcb_uilayer_alloc(mesh_ui_cookie, "mesh xy", "#007733"); - mesh.ui_layer_z = pcb_uilayer_alloc(mesh_ui_cookie, "mesh z", "#007733"); + mesh.ui_layer_xy = pcb_uilayer_alloc(mesh_ui_cookie, "mesh xy", &clr); + mesh.ui_layer_z = pcb_uilayer_alloc(mesh_ui_cookie, "mesh z", &clr); } static void ia_close_cb(void *caller_data, pcb_hid_attr_ev_t ev) Index: trunk/src_plugins/export_openscad/export_openscad.c =================================================================== --- trunk/src_plugins/export_openscad/export_openscad.c (revision 21672) +++ trunk/src_plugins/export_openscad/export_openscad.c (revision 21673) @@ -447,7 +447,7 @@ } } -static void openscad_set_color(pcb_hid_gc_t gc, const char *name) +static void openscad_set_color(pcb_hid_gc_t gc, const pcb_color_t *name) { } Index: trunk/src_plugins/export_png/png.c =================================================================== --- trunk/src_plugins/export_png/png.c (revision 21672) +++ trunk/src_plugins/export_png/png.c (revision 21673) @@ -1412,7 +1412,7 @@ } } -static void png_set_color(pcb_hid_gc_t gc, const char *name) +static void png_set_color(pcb_hid_gc_t gc, const pcb_color_t *color) { pcb_hidval_t cval; @@ -1419,10 +1419,10 @@ if (im == NULL) return; - if (name == NULL) - name = "#ff0000"; + if (color == NULL) + color = pcb_color_red; - if (strcmp(name, "drill") == 0) { + if (pcb_color_is_drill(color)) { gc->color = white; gc->is_erase = 1; return; @@ -1429,17 +1429,19 @@ } gc->is_erase = 0; - if (in_mono || (strcmp(name, "#000000") == 0)) { + if (in_mono || (strcmp(color->str, "#000000") == 0)) { gc->color = black; return; } - if (pcb_hid_cache_color(0, name, &cval, &color_cache)) { + if (pcb_hid_cache_color(0, color->str, &cval, &color_cache)) { gc->color = (color_struct *) cval.ptr; } - else if (name[0] == '#') { + else if (color->str[0] == '#') { gc->color = (color_struct *) malloc(sizeof(color_struct)); - sscanf(name + 1, "%2x%2x%2x", &(gc->color->r), &(gc->color->g), &(gc->color->b)); + gc->color->r = color->r; + gc->color->g = color->g; + gc->color->b = color->b; gc->color->c = gdImageColorAllocate(im, gc->color->r, gc->color->g, gc->color->b); if (gc->color->c == BADC) { pcb_message(PCB_MSG_ERROR, "png_set_color(): gdImageColorAllocate() returned NULL. Aborting export.\n"); @@ -1446,7 +1448,7 @@ return; } cval.ptr = gc->color; - pcb_hid_cache_color(1, name, &cval, &color_cache); + pcb_hid_cache_color(1, color->str, &cval, &color_cache); } else { fprintf(stderr, "WE SHOULD NOT BE HERE!!!\n"); Index: trunk/src_plugins/export_ps/eps.c =================================================================== --- trunk/src_plugins/export_ps/eps.c (revision 21672) +++ trunk/src_plugins/export_ps/eps.c (revision 21673) @@ -37,7 +37,7 @@ static int eps_set_layer_group(pcb_layergrp_id_t group, const char *purpose, int purpi, pcb_layer_id_t layer, unsigned int flags, int is_empty, pcb_xform_t **xform); static pcb_hid_gc_t eps_make_gc(void); static void eps_destroy_gc(pcb_hid_gc_t gc); -static void eps_set_color(pcb_hid_gc_t gc, const char *name); +static void eps_set_color(pcb_hid_gc_t gc, const pcb_color_t *name); static void eps_set_line_cap(pcb_hid_gc_t gc, pcb_cap_style_t style); static void eps_set_line_width(pcb_hid_gc_t gc, pcb_coord_t width); static void eps_set_draw_xor(pcb_hid_gc_t gc, int _xor); @@ -452,7 +452,7 @@ } -static void eps_set_color(pcb_hid_gc_t gc, const char *name) +static void eps_set_color(pcb_hid_gc_t gc, const pcb_color_t *color) { static void *cache = 0; pcb_hidval_t cval; @@ -462,22 +462,20 @@ gc->erase = 1; return; } - if (strcmp(name, "drill") == 0) { + if (pcb_color_is_drill(color)) { gc->color = 0xffffff; gc->erase = 0; return; } gc->erase = 0; - if (pcb_hid_cache_color(0, name, &cval, &cache)) { + if (pcb_hid_cache_color(0, color->str, &cval, &cache)) { gc->color = cval.lval; } else if (in_mono) { gc->color = 0; } - else if (name[0] == '#') { - unsigned int r, g, b; - sscanf(name + 1, "%2x%2x%2x", &r, &g, &b); - gc->color = (r << 16) + (g << 8) + b; + else if (color->str[0] == '#') { + gc->color = (color->r << 16) + (color->g << 8) + color->b; } else gc->color = 0; Index: trunk/src_plugins/export_ps/ps.c =================================================================== --- trunk/src_plugins/export_ps/ps.c (revision 21672) +++ trunk/src_plugins/export_ps/ps.c (revision 21673) @@ -1005,8 +1005,8 @@ !(PCB_LAYER_IS_ROUTE(flags, purpi))) { int save_drill = global.is_drill; global.is_drill = 0; - pcb_draw_groups(PCB, PCB_LYT_BOUNDARY, F_proute, NULL, &global.exps.view, "#000000", PCB_LYT_MECH, 0, 0); - pcb_draw_groups(PCB, PCB_LYT_BOUNDARY, F_uroute, NULL, &global.exps.view, "#000000", PCB_LYT_MECH, 0, 0); + pcb_draw_groups(PCB, PCB_LYT_BOUNDARY, F_proute, NULL, &global.exps.view, pcb_color_black, PCB_LYT_MECH, 0, 0); + pcb_draw_groups(PCB, PCB_LYT_BOUNDARY, F_uroute, NULL, &global.exps.view, pcb_color_black, PCB_LYT_MECH, 0, 0); global.is_drill = save_drill; } @@ -1032,22 +1032,20 @@ } -static void ps_set_color(pcb_hid_gc_t gc, const char *name) +static void ps_set_color(pcb_hid_gc_t gc, const pcb_color_t *color) { if (global.drawing_mode == PCB_HID_COMP_NEGATIVE) { gc->r = gc->g = gc->b = 255; gc->erase = 0; } - else if (strcmp(name, "drill") == 0) { + else if (pcb_color_is_drill(color)) { gc->r = gc->g = gc->b = 255; gc->erase = 1; } else if (global.incolor) { - unsigned int r, g, b; - sscanf(name + 1, "%02x%02x%02x", &r, &g, &b); - gc->r = r; - gc->g = g; - gc->b = b; + gc->r = color->r; + gc->g = color->g; + gc->b = color->b; gc->erase = 0; } else { Index: trunk/src_plugins/export_svg/svg.c =================================================================== --- trunk/src_plugins/export_svg/svg.c (revision 21672) +++ trunk/src_plugins/export_svg/svg.c (revision 21673) @@ -484,12 +484,17 @@ return NULL; } -static void svg_set_color(pcb_hid_gc_t gc, const char *name) +static void svg_set_color(pcb_hid_gc_t gc, const pcb_color_t *color) { + const char *name; gc->drill = 0; - if (name == NULL) + + if (color == NULL) name = "#ff0000"; - if (strcmp(name, "drill") == 0) { + else + name = color->str; + + if (pcb_color_is_drill(color)) { name = "#ffffff"; gc->drill = 1; } Index: trunk/src_plugins/fontmode/fontmode.c =================================================================== --- trunk/src_plugins/fontmode/fontmode.c (revision 21672) +++ trunk/src_plugins/fontmode/fontmode.c (revision 21673) @@ -78,7 +78,7 @@ lid = pcb_layer_create(PCB, grp, lname); assert(lid >= 0); PCB->Data->Layer[lid].meta.real.vis = 1; - PCB->Data->Layer[lid].meta.real.color = pcb_strdup(pcb_layer_default_color(lid, 0)); + PCB->Data->Layer[lid].meta.real.color = *pcb_layer_default_color(lid, 0); return &PCB->Data->Layer[lid]; } Index: trunk/src_plugins/hid_batch/batch.c =================================================================== --- trunk/src_plugins/hid_batch/batch.c (revision 21672) +++ trunk/src_plugins/hid_batch/batch.c (revision 21673) @@ -184,7 +184,7 @@ { } -static void batch_set_color(pcb_hid_gc_t gc, const char *name) +static void batch_set_color(pcb_hid_gc_t gc, const pcb_color_t *name) { } Index: trunk/src_plugins/hid_gtk2_gdk/gtkhid-gdk.c =================================================================== --- trunk/src_plugins/hid_gtk2_gdk/gtkhid-gdk.c (revision 21672) +++ trunk/src_plugins/hid_gtk2_gdk/gtkhid-gdk.c (revision 21673) @@ -61,7 +61,7 @@ GdkGC *pixel_gc; GdkGC *clip_gc; - gchar *colorname; + pcb_color_t pcolor; pcb_coord_t width; gint cap, join; gchar xor_mask; @@ -154,8 +154,6 @@ g_object_unref(gc->pixel_gc); if (gc->clip_gc) g_object_unref(gc->clip_gc); - if (gc->colorname != NULL) - g_free(gc->colorname); g_free(gc); } @@ -165,7 +163,7 @@ rv = g_new0(hid_gc_s, 1); rv->me_pointer = >k2_gdk_hid; - rv->colorname = g_strdup(conf_core.appearance.color.background); + rv->pcolor = conf_core.appearance.color.background; return rv; } @@ -335,7 +333,7 @@ colormap = gtk_widget_get_colormap(gport->top_window); if (!priv->grid_gc) { - if (gdk_color_parse(conf_core.appearance.color.grid, &priv->grid_color)) { + if (gdk_color_parse(conf_core.appearance.color.grid.str, &priv->grid_color)) { priv->grid_color.red ^= priv->bg_color.red; priv->grid_color.green ^= priv->bg_color.green; priv->grid_color.blue ^= priv->bg_color.blue; @@ -497,7 +495,7 @@ render_priv_t *priv = gport->render_priv; /* The color grid is combined with background color */ - map_color_string(conf_core.appearance.color.grid, &priv->grid_color); + map_color_string(conf_core.appearance.color.grid.str, &priv->grid_color); priv->grid_color.red = (priv->grid_color.red ^ priv->bg_color.red) & 0xFF; priv->grid_color.green = (priv->grid_color.green ^ priv->bg_color.green) & 0xFF; priv->grid_color.blue = (priv->grid_color.blue ^ priv->bg_color.blue) & 0xFF; @@ -513,7 +511,7 @@ render_priv_t *priv = gport->render_priv; if (((CFT_COLOR *)cfg->val.color == &conf_core.appearance.color.background) && priv->bg_gc) { - if (map_color_string(cfg->val.color[0], &priv->bg_color)) { + if (map_color_string(cfg->val.color[0].str, &priv->bg_color)) { config_color_button_update(&ghidgui->common, conf_get_field("appearance/color/background"), -1); gdk_gc_set_foreground(priv->bg_gc, &priv->bg_color); set_special_grid_color(); @@ -520,13 +518,13 @@ } } else if (((CFT_COLOR *)cfg->val.color == &conf_core.appearance.color.off_limit) && priv->offlimits_gc) { - if (map_color_string(cfg->val.color[0], &priv->offlimits_color)) { + if (map_color_string(cfg->val.color[0].str, &priv->offlimits_color)) { config_color_button_update(&ghidgui->common, conf_get_field("appearance/color/off_limit"), -1); gdk_gc_set_foreground(priv->offlimits_gc, &priv->offlimits_color); } } else if (((CFT_COLOR *)cfg->val.color == &conf_core.appearance.color.grid) && priv->grid_gc) { - if (map_color_string(cfg->val.color[0], &priv->grid_color)) { + if (map_color_string(cfg->val.color[0].str, &priv->grid_color)) { conf_setf(CFR_DESIGN, "appearance/color/grid", -1, "%s", get_color_name(&priv->grid_color)); set_special_grid_color(); } @@ -533,12 +531,13 @@ } } -static void ghid_gdk_set_color(pcb_hid_gc_t gc, const char *name) +static void ghid_gdk_set_color(pcb_hid_gc_t gc, const pcb_color_t *color) { static void *cache = 0; static GdkColormap *colormap = NULL; render_priv_t *priv = gport->render_priv; pcb_hidval_t cval; + const char *name = color->str; if (name == NULL) { fprintf(stderr, "ghid_gdk_set_color(): name = NULL, setting to magenta\n"); @@ -545,11 +544,7 @@ name = "magenta"; } - if (name != gc->colorname) { - if (gc->colorname != NULL) - g_free(gc->colorname); - gc->colorname = g_strdup(name); - } + gc->pcolor = *color; if (!gc->pixel_gc) return; @@ -556,7 +551,7 @@ if (colormap == NULL) colormap = gtk_widget_get_colormap(gport->top_window); - if (strcmp(name, "drill") == 0) { + if (pcb_color_is_drill(color)) { gdk_gc_set_foreground(gc->pixel_gc, &priv->offlimits_color); } else { @@ -640,7 +635,7 @@ gdk_gc_set_function(gc->pixel_gc, xor_mask ? GDK_XOR : GDK_COPY); if (gc->clip_gc != NULL) gdk_gc_set_function(gc->clip_gc, xor_mask ? GDK_XOR : GDK_COPY); - ghid_gdk_set_color(gc, gc->colorname); + ghid_gdk_set_color(gc, &gc->pcolor); /* If not in direct mode then select the correct drawables so that the sketch and clip * drawables are not drawn to in XOR mode */ @@ -682,7 +677,7 @@ } if (need_setup) { - ghid_gdk_set_color(gc, gc->colorname); + ghid_gdk_set_color(gc, &gc->pcolor); ghid_gdk_set_line_width(gc, gc->core_gc.width); if ((need_pen) || (gc->core_gc.cap != pcb_cap_invalid)) ghid_gdk_set_line_cap(gc, (pcb_cap_style_t) gc->core_gc.cap); @@ -1386,7 +1381,7 @@ gdk_gc_set_clip_origin(xor_gc, 0, 0); set_clip(priv, xor_gc); /* FIXME: when CrossColor changed from config */ - map_color_string(conf_core.appearance.color.cross, &cross_color); + map_color_string(conf_core.appearance.color.cross.str, &cross_color); } x = Vx(gport->view.crosshair_x); y = Vy(gport->view.crosshair_y); @@ -1439,13 +1434,13 @@ if (!done_once) { priv->bg_gc = gdk_gc_new(priv->out_pixel); - if (!map_color_string(conf_core.appearance.color.background, &priv->bg_color)) + if (!map_color_string(conf_core.appearance.color.background.str, &priv->bg_color)) map_color_string("white", &priv->bg_color); gdk_gc_set_foreground(priv->bg_gc, &priv->bg_color); gdk_gc_set_clip_origin(priv->bg_gc, 0, 0); priv->offlimits_gc = gdk_gc_new(priv->out_pixel); - if (!map_color_string(conf_core.appearance.color.off_limit, &priv->offlimits_color)) + if (!map_color_string(conf_core.appearance.color.off_limit.str, &priv->offlimits_color)) map_color_string("white", &priv->offlimits_color); gdk_gc_set_foreground(priv->offlimits_gc, &priv->offlimits_color); gdk_gc_set_clip_origin(priv->offlimits_gc, 0, 0); Index: trunk/src_plugins/hid_gtk2_gl/gtkhid-gl.c =================================================================== --- trunk/src_plugins/hid_gtk2_gl/gtkhid-gl.c (revision 21672) +++ trunk/src_plugins/hid_gtk2_gl/gtkhid-gl.c (revision 21673) @@ -401,6 +401,7 @@ if (colormap == NULL) colormap = gtk_widget_get_colormap(gport->top_window); +TODO("color: Do not depend on manual strcmp here - use pcb_color_is_drill()"); if (strcmp(gc->colorname, "drill") == 0) { r = priv->offlimits_color.red / 65535.; g = priv->offlimits_color.green / 65535.; @@ -477,9 +478,9 @@ drawgl_set_colour(r,g,b,a); } -void ghid_gl_set_color(pcb_hid_gc_t gc, const char *name) +void ghid_gl_set_color(pcb_hid_gc_t gc, const color_t *name) { - + const char *name = color->str; if(name == NULL) { fprintf(stderr, "ghid_gl_set_color(): name = NULL, setting to magenta\n"); name = "magenta"; Index: trunk/src_plugins/hid_gtk3_cairo/gtkhid-cairo.c =================================================================== --- trunk/src_plugins/hid_gtk3_cairo/gtkhid-cairo.c (revision 21672) +++ trunk/src_plugins/hid_gtk3_cairo/gtkhid-cairo.c (revision 21673) @@ -684,15 +684,16 @@ } } -static void ghid_cairo_set_color(pcb_hid_gc_t gc, const char *name) +static void ghid_cairo_set_color(pcb_hid_gc_t gc, const color_t *color) { static void *cache = 0; pcb_hidval_t cval; render_priv_t *priv = gport->render_priv; + const char *name = color->str; - if (name == NULL) { + if (color == NULL) { fprintf(stderr, "ghid_cairo_set_color(): name = NULL, setting to magenta\n"); - name = "magenta"; + color = &pcb_color_cyan; } //if (name != gc->colorname) { @@ -707,7 +708,7 @@ //if (gport->colormap == 0) // gport->colormap = gtk_widget_get_colormap(gport->top_window); - if (strcmp(name, "drill") == 0) { + if (pcb_color_is_drill(color)) { copy_color(&gc->color, &priv->offlimits_color); //gdk_cairo_set_source_rgba(cr, &priv->offlimits_color); //gdk_gc_set_foreground(gc->gc, &gport->offlimits_color); Index: trunk/src_plugins/hid_lesstif/dlg_attr_misc.c =================================================================== --- trunk/src_plugins/hid_lesstif/dlg_attr_misc.c (revision 21672) +++ trunk/src_plugins/hid_lesstif/dlg_attr_misc.c (revision 21673) @@ -54,7 +54,7 @@ stdarg(XmNsliderSize, 1); stdarg(XmNorientation, XmHORIZONTAL); stdarg(XmNshowArrows, pcb_false); - stdarg_do_color("#000099", XmNforeground); + stdarg_do_color_str("#000099", XmNforeground); stdarg(XmNsliderVisual, XmFOREGROUND_COLOR); bar = XmCreateScrollBar(parent, XmStrCast("scale"), stdarg_args, stdarg_n); Index: trunk/src_plugins/hid_lesstif/lesstif.h =================================================================== --- trunk/src_plugins/hid_lesstif/lesstif.h (revision 21672) +++ trunk/src_plugins/hid_lesstif/lesstif.h (revision 21673) @@ -50,7 +50,8 @@ extern void lesstif_pan_fixup(void); extern void lesstif_show_library(void); extern void lesstif_show_netlist(void); -extern Pixel lesstif_parse_color(const char *value); +extern Pixel lesstif_parse_color(const pcb_color_t *value); +extern Pixel lesstif_parse_color_str(const char *value); extern void lesstif_styles_update_values(); extern void lesstif_update_layer_groups(); extern void lesstif_update_status_line(); Index: trunk/src_plugins/hid_lesstif/main.c =================================================================== --- trunk/src_plugins/hid_lesstif/main.c (revision 21672) +++ trunk/src_plugins/hid_lesstif/main.c (revision 21673) @@ -294,9 +294,18 @@ *py = Py(vy); } -Pixel lesstif_parse_color(const char *value) +Pixel lesstif_parse_color(const pcb_color_t *value) { XColor color; + if (XParseColor(display, lesstif_colormap, value->str, &color)) + if (XAllocColor(display, lesstif_colormap, &color)) + return color.pixel; + return 0; +} + +Pixel lesstif_parse_color_str(const char *value) +{ + XColor color; if (XParseColor(display, lesstif_colormap, value, &color)) if (XAllocColor(display, lesstif_colormap, &color)) return color.pixel; @@ -1394,7 +1403,7 @@ if (!crosshair_in_window || !window) return; if (xor_gc == 0) { - crosshair_color = lesstif_parse_color(conf_core.appearance.color.crosshair) ^ bgcolor; + crosshair_color = lesstif_parse_color(&conf_core.appearance.color.crosshair) ^ bgcolor; xor_gc = XCreateGC(display, window, 0, 0); XSetFunction(display, xor_gc, GXxor); XSetForeground(display, xor_gc, crosshair_color); @@ -1504,10 +1513,10 @@ my_gc = XCreateGC(display, window, 0, 0); arc1_gc = XCreateGC(display, window, 0, 0); - c = lesstif_parse_color("#804000"); + c = lesstif_parse_color_str("#804000"); XSetForeground(display, arc1_gc, c); arc2_gc = XCreateGC(display, window, 0, 0); - c = lesstif_parse_color("#004080"); + c = lesstif_parse_color_str("#004080"); XSetForeground(display, arc2_gc, c); XSetLineAttributes(display, arc1_gc, 1, LineOnOffDash, 0, 0); XSetLineAttributes(display, arc2_gc, 1, LineOnOffDash, 0, 0); @@ -1522,8 +1531,8 @@ view_width = width; view_height = height; - offlimit_color = lesstif_parse_color(conf_core.appearance.color.off_limit); - grid_color = lesstif_parse_color(conf_core.appearance.color.grid); + offlimit_color = lesstif_parse_color(&conf_core.appearance.color.off_limit); + grid_color = lesstif_parse_color(&conf_core.appearance.color.grid); bg_gc = XCreateGC(display, window, 0, 0); XSetForeground(display, bg_gc, bgcolor); @@ -1679,7 +1688,7 @@ XtManageChild(work_area_frame); stdarg_n = 0; - stdarg_do_color(conf_core.appearance.color.background, XmNbackground); + stdarg_do_color(&conf_core.appearance.color.background, XmNbackground); work_area = XmCreateDrawingArea(work_area_frame, XmStrCast("work_area"), stdarg_args, stdarg_n); XtManageChild(work_area); XtAddCallback(work_area, XmNexposeCallback, (XtCallbackProc) work_area_first_expose, 0); @@ -2901,11 +2910,12 @@ -static void lesstif_set_color(pcb_hid_gc_t gc, const char *name) +static void lesstif_set_color(pcb_hid_gc_t gc, const pcb_color_t *pcolor) { static void *cache = 0; pcb_hidval_t cval; static XColor color, exact_color; + const char *name = pcolor->str; if (!display) return; @@ -2918,7 +2928,7 @@ gc->colorname = pcb_strdup(name); } - if (strcmp(name, "drill") == 0) { + if (pcb_color_is_drill(pcolor)) { gc->color = offlimit_color; gc->erase = 0; } Index: trunk/src_plugins/hid_lesstif/menu.c =================================================================== --- trunk/src_plugins/hid_lesstif/menu.c (revision 21672) +++ trunk/src_plugins/hid_lesstif/menu.c (revision 21673) @@ -392,11 +392,11 @@ stdarg_n = 0; v = pcb_hid_cfg_menu_field_str(node, PCB_MF_FOREGROUND); if (v != NULL) - stdarg_do_color(v, XmNforeground); + stdarg_do_color_str(v, XmNforeground); v = pcb_hid_cfg_menu_field_str(node, PCB_MF_BACKGROUND); if (v != NULL) - stdarg_do_color(v, XmNbackground); + stdarg_do_color_str(v, XmNbackground); v = pcb_hid_cfg_menu_field_str(node, PCB_MF_FONT); if (v != NULL) { Index: trunk/src_plugins/hid_lesstif/stdarg.c =================================================================== --- trunk/src_plugins/hid_lesstif/stdarg.c (revision 21672) +++ trunk/src_plugins/hid_lesstif/stdarg.c (revision 21673) @@ -5,9 +5,18 @@ extern Colormap lesstif_colormap; extern Display *lesstif_display; -void stdarg_do_color(const char *value, char *which) +void stdarg_do_color(const pcb_color_t *value, char *which) { XColor color; + if (XParseColor(lesstif_display, lesstif_colormap, value->str, &color)) + if (XAllocColor(lesstif_display, lesstif_colormap, &color)) { + stdarg(which, color.pixel); + } +} + +void stdarg_do_color_str(const char *value, char *which) +{ + XColor color; if (XParseColor(lesstif_display, lesstif_colormap, value, &color)) if (XAllocColor(lesstif_display, lesstif_colormap, &color)) { stdarg(which, color.pixel); Index: trunk/src_plugins/hid_lesstif/stdarg.h =================================================================== --- trunk/src_plugins/hid_lesstif/stdarg.h (revision 21672) +++ trunk/src_plugins/hid_lesstif/stdarg.h (revision 21673) @@ -1,4 +1,5 @@ #include "xincludes.h" +#include "color.h" extern Colormap lesstif_colormap; @@ -6,5 +7,6 @@ extern int stdarg_n; #define stdarg(t,v) XtSetArg(stdarg_args[stdarg_n], t, v), stdarg_n++ -void stdarg_do_color(const char *value, char *which); +void stdarg_do_color(const pcb_color_t *value, char *which); +void stdarg_do_color_str(const char *value, char *which); Index: trunk/src_plugins/hid_remote/remote.c =================================================================== --- trunk/src_plugins/hid_remote/remote.c (revision 21672) +++ trunk/src_plugins/hid_remote/remote.c (revision 21673) @@ -201,13 +201,13 @@ pcb_message(PCB_MSG_ERROR, "Invalid drawing mode %d\n", op); } -static void remote_set_color(pcb_hid_gc_t gc, const char *name) +static void remote_set_color(pcb_hid_gc_t gc, const pcb_color_t *color) { int idx = gc2idx(gc); if (idx >= 0) { - if (strcmp(gc_cache[idx].color, name) != 0) { - proto_send_set_color(idx, name); - strcpy(gc_cache[idx].color, name); + if (strcmp(gc_cache[idx].color, color->str) != 0) { + proto_send_set_color(idx, color->str); + strcpy(gc_cache[idx].color, color->str); } } } Index: trunk/src_plugins/io_lihata/read.c =================================================================== --- trunk/src_plugins/io_lihata/read.c (revision 21672) +++ trunk/src_plugins/io_lihata/read.c (revision 21673) @@ -967,8 +967,10 @@ if ((nclr != NULL) && (nclr->type != LHT_INVALID_TYPE)) { if (rdver < 5) iolht_warn(nclr, 1, "layer color was not supprted before lihata board v5 (reading from v%d)\n", rdver); - if (nclr->type == LHT_TEXT) - ly->meta.real.color = pcb_strdup(nclr->data.text.value); + if (nclr->type == LHT_TEXT) { + if (pcb_color_load_str(&ly->meta.real.color, nclr->data.text.value) != 0) + return iolht_error(nclr, "Invalid color: '%s'\n", nclr->data.text.value); + } else iolht_warn(nclr, 1, "Ignoring color: text node required\n"); } Index: trunk/src_plugins/io_lihata/write.c =================================================================== --- trunk/src_plugins/io_lihata/write.c (revision 21672) +++ trunk/src_plugins/io_lihata/write.c (revision 21673) @@ -935,7 +935,7 @@ lht_dom_hash_put(obj, build_text("visible", layer->meta.real.vis ? "1" : "0")); lht_dom_hash_put(obj, build_textf("group", "%ld", layer_group)); if (wrver >= 5) - lht_dom_hash_put(obj, build_text("color", layer->meta.real.color)); + lht_dom_hash_put(obj, build_text("color", layer->meta.real.color.str)); } else { if (wrver >= 3) { Index: trunk/src_plugins/lib_gtk_common/wt_layersel.c =================================================================== --- trunk/src_plugins/lib_gtk_common/wt_layersel.c (revision 21672) +++ trunk/src_plugins/lib_gtk_common/wt_layersel.c (revision 21673) @@ -52,18 +52,8 @@ #define set_pixel(dst, r, g, b, a) \ do { p[0] = r; p[1] = g; p[2] = b; p[3] = a; } while(0) -static guint hex2bin_(char c) -{ - if ((c >= '0') && (c <= '9')) return c - '0'; - if ((c >= 'a') && (c <= 'z')) return c - 'a' + 10; - if ((c >= 'A') && (c <= 'Z')) return c - 'A' + 10; - return 0; /* syntax error... */ -} - -#define hex2bin(str) ((hex2bin_((str)[0])) << 4 | hex2bin_((str)[1])) - /* draw a visibility box: filled or partially filled with layer color */ -static GtkWidget *layer_vis_box(int filled, const char *rgb, int brd, int hatch) +static GtkWidget *layer_vis_box(int filled, const pcb_color_t *color, int brd, int hatch) { GdkPixbuf *pixbuf; GtkWidget *image; @@ -77,9 +67,9 @@ pixels = gdk_pixbuf_get_pixels(pixbuf); /* Fill the whole rectangle with color */ - r = hex2bin(rgb+1); - g = hex2bin(rgb+3); - b = hex2bin(rgb+5); + r = color->r; + g = color->g; + b = color->b; while (height--) { w = width; @@ -397,18 +387,25 @@ } /*** Row builder ***/ -static const char *lyr_color(pcb_layer_id_t lid) +static const pcb_color_t *lyr_color(pcb_layer_id_t lid) { - const char *clr = "#aaaa00"; + static pcb_color_t clr_invalid; + static int clr_invalid_inited = 0; + const pcb_color_t *clr = &clr_invalid; pcb_layer_t *ly = pcb_get_layer(PCB->Data, lid); + if (!clr_invalid_inited) { + pcb_color_load_str(&clr_invalid, "#aaaa00"); + clr_invalid_inited = 1; + } + if (ly != NULL) - clr = ly->meta.real.color; + clr = &ly->meta.real.color; return clr; } -static const char * const grp_color(pcb_layergrp_t *g) +static const pcb_color_t *grp_color(pcb_layergrp_t *g) { /* normal mechanism: first layer's color or default by type */ return pcb_layer_default_color(g->len > 0 ? g->lid[0] : 0, g->ltype); @@ -415,7 +412,7 @@ } /* Create a hbox with on/off visibility boxes packed in, pointers returned in *on, *off */ -static GtkWidget *build_visbox(const char *color, GtkWidget **on, GtkWidget **off, int brd, int hatch) +static GtkWidget *build_visbox(const pcb_color_t *color, GtkWidget **on, GtkWidget **off, int brd, int hatch) { GtkWidget *vis_box = gtkc_hbox_new(0, 0); *on = layer_vis_box(1, color, brd, hatch); @@ -426,11 +423,11 @@ } /* Create a hbox of a layer within an expanded group */ -static GtkWidget *build_layer(pcb_gtk_ls_grp_t *lsg, pcb_gtk_ls_lyr_t *lsl, const char *name, pcb_layer_id_t lid, char * const*force_color) +static GtkWidget *build_layer(pcb_gtk_ls_grp_t *lsg, pcb_gtk_ls_lyr_t *lsl, const char *name, pcb_layer_id_t lid, const pcb_color_t *force_color) { GtkWidget *vis_box, *vis_ebox, *ly_name_bx, *lab; pcb_layer_t *ly; - const char *color; + const pcb_color_t *color; lsl->lsg = lsg; lsl->force_color = force_color; @@ -439,7 +436,7 @@ if (force_color == NULL) color = lyr_color(lid); else - color = *force_color; + color = force_color; ly = pcb_get_layer(PCB->Data, lid); @@ -534,9 +531,9 @@ /* install layers */ if (grp->len == 0) { - const char * const clr = grp_color(grp); + const pcb_color_t *clr = grp_color(grp); char *name = pcb_strdup_printf("<%s>", lsg->grp->name); - GtkWidget *wl = build_layer(lsg, &lsg->layer[0], name, -1, (char *const *)&clr); + GtkWidget *wl = build_layer(lsg, &lsg->layer[0], name, -1, clr); gtk_box_pack_start(GTK_BOX(lsg->layers), wl, TRUE, TRUE, 1); lsg->layer[0].lid = -1; lsg->layer[0].ev_selected = ev_lyr_no_select; Index: trunk/src_plugins/lib_gtk_common/wt_layersel.h =================================================================== --- trunk/src_plugins/lib_gtk_common/wt_layersel.h (revision 21672) +++ trunk/src_plugins/lib_gtk_common/wt_layersel.h (revision 21673) @@ -17,7 +17,7 @@ int (*ev_selected)(pcb_gtk_ls_lyr_t *lsl, int do_select); /* called first in click handler with do_select=1, if returns -1, layer can not be selected; when called with do_select=0, return current selection */ pcb_layer_id_t lid; - char * const*force_color; + pcb_color_t *force_color; int vis_ui_idx, virt_idx; Index: trunk/src_plugins/lib_gtk_config/gui-config.c =================================================================== --- trunk/src_plugins/lib_gtk_config/gui-config.c (revision 21672) +++ trunk/src_plugins/lib_gtk_config/gui-config.c (revision 21673) @@ -1165,7 +1165,7 @@ conf_native_t *nat = conf_get_field(ci->cfg->hash_path); if (nat != NULL) for(n = 0; (n < PCB_MAX_LAYER) && (n < nat->array_size); n++) - conf_set(CFR_DESIGN, ci->cfg->hash_path, n, nat->val.color[n], POL_OVERWRITE); + conf_set(CFR_DESIGN, ci->cfg->hash_path, n, nat->val.color[n].str, POL_OVERWRITE); } } @@ -1195,7 +1195,7 @@ conf_hid_set_data(cfg, ghid_conf_id, ci); } - com->map_color_string(cfg->val.color[idx], &(ci->color[idx])); + com->map_color_string(cfg->val.color[idx].str, &(ci->color[idx])); title = g_strdup_printf(_("pcb-rnd %s Color"), cfg->description); ci->button = gtkc_color_button_new_with_color(&(ci->color[idx])); @@ -1218,7 +1218,7 @@ else { cfg_color_idx_t *ci = conf_hid_get_data(cfg, ghid_conf_id); - com->map_color_string(cfg->val.color[idx], &(ci->color[idx])); + com->map_color_string(cfg->val.color[idx].str, &(ci->color[idx])); gtkc_color_button_set_color(ci->button, &(ci->color[idx])); } } Index: trunk/src_plugins/lib_hid_common/layer_menu.c =================================================================== --- trunk/src_plugins/lib_hid_common/layer_menu.c (revision 21672) +++ trunk/src_plugins/lib_hid_common/layer_menu.c (revision 21673) @@ -137,8 +137,8 @@ pcb_layer_t *l = pcb_get_layer(PCB->Data, lid); pcb_layer_type_t lyt = pcb_layer_flags_(l); - props.background = l->meta.real.color; - props.foreground = conf_core.appearance.color.background; + props.background = &l->meta.real.color; + props.foreground = &conf_core.appearance.color.background; props.checked = chk; if (ctx->view) { sprintf(act, "ToggleView(%ld)", lid+1); Index: trunk/src_plugins/loghid/hid-logger.c =================================================================== --- trunk/src_plugins/loghid/hid-logger.c (revision 21672) +++ trunk/src_plugins/loghid/hid-logger.c (revision 21673) @@ -101,10 +101,10 @@ } -static void log_set_color(pcb_hid_gc_t gc, const char *name) +static void log_set_color(pcb_hid_gc_t gc, const pcb_color_t *color) { - pcb_fprintf(out_, "set_color(gc, %s)\n", name); - delegatee_->set_color(gc, name); + pcb_fprintf(out_, "set_color(gc, %s)\n", color->str); + delegatee_->set_color(gc, color); } static void log_set_line_cap(pcb_hid_gc_t gc, pcb_cap_style_t style) Index: trunk/src_plugins/millpath/toolpath.c =================================================================== --- trunk/src_plugins/millpath/toolpath.c (revision 21672) +++ trunk/src_plugins/millpath/toolpath.c (revision 21673) @@ -118,12 +118,18 @@ { gdl_iterator_t it; pcb_line_t *line; + static pcb_color_t clr1, clr2; + if (clr1.str[0] != '#') + pcb_color_load_str(&clr1, "#EE9922"); + if (clr2.str[0] != '#') + pcb_color_load_str(&clr2, "#886611"); + if (result->res_ply == NULL) - result->res_ply = pcb_uilayer_alloc(pcb_millpath_cookie, "mill remove", "#EE9922"); + result->res_ply = pcb_uilayer_alloc(pcb_millpath_cookie, "mill remove", &clr1); if (result->res_path == NULL) - result->res_path = pcb_uilayer_alloc(pcb_millpath_cookie, "mill toolpath", "#886611"); + result->res_path = pcb_uilayer_alloc(pcb_millpath_cookie, "mill toolpath", &clr2); if (result->fill != NULL) pcb_polyop_destroy(NULL, result->res_ply, result->fill); Index: trunk/src_plugins/propedit/propsel.c =================================================================== --- trunk/src_plugins/propedit/propsel.c (revision 21672) +++ trunk/src_plugins/propedit/propsel.c (revision 21673) @@ -134,7 +134,7 @@ map_add_prop(ctx, "p/layer/comb/negative", int, !!(layer->comb & PCB_LYC_SUB)); map_add_prop(ctx, "p/layer/comb/auto", int, !!(layer->comb & PCB_LYC_AUTO)); if (!layer->is_bound) - map_add_prop(ctx, "p/layer/color", String, layer->meta.real.color); + map_add_prop(ctx, "p/layer/color", String, layer->meta.real.color.str); map_attr(ctx, &layer->Attributes); return 0; } @@ -340,6 +340,13 @@ pcb_message(PCB_MSG_ERROR, "This property can not be changed from the property editor.\n"); } +static int layer_recolor(pcb_layer_t *layer, const char *clr) +{ + pcb_color_t c; + if (pcb_color_load_str(&c, clr) != 0) + return -1; + return pcb_layer_recolor_(layer, &c); +} static int set_layer_cb(void *ctx, pcb_board_t *pcb, pcb_layer_t *layer, int enter) { @@ -358,7 +365,7 @@ (pcb_layer_rename_(layer, pcb_strdup(st->value)) == 0)) DONE0; if ((strcmp(pn, "color") == 0) && - (pcb_layer_recolor_(layer, pcb_strdup(st->value)) == 0)) DONE0; + (layer_recolor(layer, st->value) == 0)) DONE0; pcb_message(PCB_MSG_ERROR, "This property can not be changed from the property editor.\n"); return 0; Index: trunk/src_plugins/rubberband_orig/rubberband.c =================================================================== --- trunk/src_plugins/rubberband_orig/rubberband.c (revision 21672) +++ trunk/src_plugins/rubberband_orig/rubberband.c (revision 21673) @@ -1209,15 +1209,15 @@ } if (PCB_FLAG_TEST(PCB_FLAG_RAT, ptr->Line)) { - pcb_gui->set_color(pcb_crosshair.GC, conf_core.appearance.color.rat); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.rat); pcb_draw_wireframe_line(pcb_crosshair.GC, x[0], y[0], x[1], y[1], ptr->Line->Thickness, 0); } else if (direct || (conf_core.editor.move_linepoint_uses_route == 0)) { - pcb_gui->set_color(pcb_crosshair.GC, ptr->Layer->meta.real.color); + pcb_gui->set_color(pcb_crosshair.GC, &ptr->Layer->meta.real.color); pcb_draw_wireframe_line(pcb_crosshair.GC, x[0], y[0], x[1], y[1], ptr->Line->Thickness, 0); /* Draw the DRC outline if it is enabled */ if (conf_core.editor.show_drc) { - pcb_gui->set_color(pcb_crosshair.GC, conf_core.appearance.color.cross); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.cross); pcb_draw_wireframe_line(pcb_crosshair.GC, x[0], y[0], x[1], y[1], ptr->Line->Thickness + 2 * (conf_core.design.bloat + 1), 0); } } @@ -1241,7 +1241,7 @@ pcb_route_draw_drc(&route, pcb_crosshair.GC); pcb_route_destroy(&route); } - pcb_gui->set_color(pcb_crosshair.GC, conf_core.appearance.color.crosshair); + pcb_gui->set_color(pcb_crosshair.GC, &conf_core.appearance.color.crosshair); } ptr++; Index: trunk/src_plugins/sketch_route/sketch_route.c =================================================================== --- trunk/src_plugins/sketch_route/sketch_route.c (revision 21672) +++ trunk/src_plugins/sketch_route/sketch_route.c (revision 21673) @@ -718,12 +718,12 @@ pcb_r_search(layer->arc_tree, &bbox, NULL, r_search_cb, &info, NULL); pcb_snprintf(name, sizeof(name), "%s: CDT", layer->name); - sk->ui_layer_cdt = pcb_uilayer_alloc(pcb_sketch_route_cookie, name, layer->meta.real.color); + sk->ui_layer_cdt = pcb_uilayer_alloc(pcb_sketch_route_cookie, name, &layer->meta.real.color); sk->ui_layer_cdt->meta.real.vis = pcb_false; sketch_update_cdt_layer(sk); pcb_snprintf(name, sizeof(name), "%s: ERBS", layer->name); - sk->ui_layer_erbs = pcb_uilayer_alloc(pcb_sketch_route_cookie, name, layer->meta.real.color); + sk->ui_layer_erbs = pcb_uilayer_alloc(pcb_sketch_route_cookie, name, &layer->meta.real.color); sketch_update_erbs_layer(sk); pcb_event(PCB_EVENT_LAYERS_CHANGED, NULL); }