예제 #1
0
파일: SnowModel.cpp 프로젝트: nobbk/copo
/**
 * Remove all edge groups and clear the container.
 */
void
SnowModel::RemoveEdgeGroups()
{
    /* Remember colors of the previous edge groups */
    if (m_rememberColors == false) {
        m_vecRememberedColors.clear();
        // clear edge group collection
        for (eg_it it = edge_groups.begin(); it != edge_groups.end(); ++it) {
            if (*it) delete(*it);
        }

        // load last saved colors
        load_colors();
    }
    else if (edge_groups.size() > 0) {
        m_vecRememberedColors.clear();
        // clear edge group collection
        for (eg_it it = edge_groups.begin(); it != edge_groups.end(); ++it) {
            if (*it) {
                m_vecRememberedColors.push_back((*it)->GetEdgeGroupFaceColor());
                delete(*it);
            }
        }

        save_colors();
    } else {
        // if there are no edge groups, load the saved colors
        load_colors();
    }

    edge_groups.clear();
}
예제 #2
0
static void colors_changed(GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data)
{
        gint color_scheme = gconf_client_get_int(client, entry->key, NULL);
        load_colors(color_scheme);
        load_palette(color_scheme);
        gtk_widget_queue_draw(gui.conversation_panel);
}
예제 #3
0
void edosu_beatmap_load_objects(EdosuBeatmap *beatmap, osux_beatmap *osux_bm)
{
    GtkTreeStore *ts;
    ts = gtk_tree_store_new(COL_NUM,
                            G_TYPE_INT, G_TYPE_STRING,
                            G_TYPE_STRING, G_TYPE_POINTER);
    beatmap->Objects = ts;
    gtk_tree_store_append(ts, &beatmap->TimingPoints, NULL);
    gtk_tree_store_set(ts, &beatmap->TimingPoints, COL_TYPE, _("TimingPoints"),
                       COL_OFFSET, osux_bm->timingpoint_count, -1);
    load_timing_points(osux_bm, ts, &beatmap->TimingPoints);

    gtk_tree_store_append(ts, &beatmap->HitObjects, NULL);
    gtk_tree_store_set(ts, &beatmap->HitObjects, COL_TYPE, _("HitObjects"),
                       COL_OFFSET, osux_bm->hitobject_count, -1);
    load_hit_objects(osux_bm, ts, beatmap->HitObjectsSeq, &beatmap->HitObjects);

    gtk_tree_store_append(ts, &beatmap->Bookmarks, NULL);
    gtk_tree_store_set(ts, &beatmap->Bookmarks, COL_TYPE, _("Bookmarks"),
                       COL_OFFSET, osux_bm->bookmark_count, -1);
    load_bookmarks(osux_bm, ts, &beatmap->Bookmarks);

    gtk_tree_store_append(ts, &beatmap->Events, NULL);
    gtk_tree_store_set(ts, &beatmap->Events, COL_TYPE, _("Events"),
                       COL_OFFSET, osux_bm->event_count, -1);
    load_events(osux_bm, ts, &beatmap->Events);

    gtk_tree_store_append(ts, &beatmap->Colors, NULL);
    gtk_tree_store_set(ts, &beatmap->Colors, COL_TYPE, _("Colors"),
                       COL_OFFSET, osux_bm->color_count, -1);
    load_colors(osux_bm, ts, &beatmap->Colors);

    edosu_beatmap_steal_objects(beatmap, osux_bm);
}
예제 #4
0
int curses_start_color(void)
{
    colorpairs = new pairs[100];
    //Load the console colors from colors.json
    std::ifstream colorfile("data/raw/colors.json", std::ifstream::in | std::ifstream::binary);
    try{
        JsonIn jsin(colorfile);
        char ch;
        // Manually load the colordef object because the json handler isn't loaded yet.
        jsin.eat_whitespace();
        ch = jsin.peek();
        if( ch == '[' ) {
            jsin.start_array();
            // find type and dispatch each object until array close
            while (!jsin.end_array()) {
                jsin.eat_whitespace();
                char ch = jsin.peek();
                if (ch != '{') {
                    std::stringstream err;
                    err << jsin.line_number() << ": ";
                    err << "expected array of objects but found '";
                    err << ch << "', not '{'";
                    throw err.str();
                }
                JsonObject jo = jsin.get_object();
                load_colors(jo);
                jo.finish();
            }
        } else {
            // not an array?
            std::stringstream err;
            err << jsin.line_number() << ": ";
            err << "expected object or array, but found '" << ch << "'";
            throw err.str();
        }
    }
    catch(std::string e){
        throw "data/raw/colors.json: " + e;
    }
    if(consolecolors.empty())return 0;
    windowsPalette[0]  = BGR(ccolor("BLACK"));
    windowsPalette[1]  = BGR(ccolor("RED"));
    windowsPalette[2]  = BGR(ccolor("GREEN"));
    windowsPalette[3]  = BGR(ccolor("BROWN"));
    windowsPalette[4]  = BGR(ccolor("BLUE"));
    windowsPalette[5]  = BGR(ccolor("MAGENTA"));
    windowsPalette[6]  = BGR(ccolor("CYAN"));
    windowsPalette[7]  = BGR(ccolor("GRAY"));
    windowsPalette[8]  = BGR(ccolor("DGRAY"));
    windowsPalette[9]  = BGR(ccolor("LRED"));
    windowsPalette[10] = BGR(ccolor("LGREEN"));
    windowsPalette[11] = BGR(ccolor("YELLOW"));
    windowsPalette[12] = BGR(ccolor("LBLUE"));
    windowsPalette[13] = BGR(ccolor("LMAGENTA"));
    windowsPalette[14] = BGR(ccolor("LCYAN"));
    windowsPalette[15] = BGR(ccolor("WHITE"));
    return 0;
}
예제 #5
0
int curses_start_color(void)
{
    //TODO: this should be reviewed in the future.

    colorpairs = new pairs[100];
    windowsPalette = new RGBQUAD[16];

    //Load the console colors from colors.json
    std::ifstream colorfile(FILENAMES["colors"].c_str(), std::ifstream::in | std::ifstream::binary);
    try{
        JsonIn jsin(colorfile);
        char ch;
        // Manually load the colordef object because the json handler isn't loaded yet.
        jsin.eat_whitespace();
        ch = jsin.peek();
        if( ch == '[' ) {
            jsin.start_array();
            // find type and dispatch each object until array close
            while (!jsin.end_array()) {
                jsin.eat_whitespace();
                char ch = jsin.peek();
                if (ch != '{') {
                    jsin.error( string_format( "expected array of objects but found '%c', not '{'", ch ) );
                }
                JsonObject jo = jsin.get_object();
                load_colors(jo);
                jo.finish();
            }
        } else {
            // not an array?
            jsin.error( string_format( "expected object or array, but found '%c'", ch ) );
        }
    } catch( const JsonError &err ){
        throw std::runtime_error( FILENAMES["colors"] + ": " + err.what() );
    }

    if(consolecolors.empty())return SetDIBColorTable(backbuffer, 0, 16, windowsPalette);
    windowsPalette[0]  = BGR(ccolor("BLACK"));
    windowsPalette[1]  = BGR(ccolor("RED"));
    windowsPalette[2]  = BGR(ccolor("GREEN"));
    windowsPalette[3]  = BGR(ccolor("BROWN"));
    windowsPalette[4]  = BGR(ccolor("BLUE"));
    windowsPalette[5]  = BGR(ccolor("MAGENTA"));
    windowsPalette[6]  = BGR(ccolor("CYAN"));
    windowsPalette[7]  = BGR(ccolor("GRAY"));
    windowsPalette[8]  = BGR(ccolor("DGRAY"));
    windowsPalette[9]  = BGR(ccolor("LRED"));
    windowsPalette[10] = BGR(ccolor("LGREEN"));
    windowsPalette[11] = BGR(ccolor("YELLOW"));
    windowsPalette[12] = BGR(ccolor("LBLUE"));
    windowsPalette[13] = BGR(ccolor("LMAGENTA"));
    windowsPalette[14] = BGR(ccolor("LCYAN"));
    windowsPalette[15] = BGR(ccolor("WHITE"));
    return SetDIBColorTable(backbuffer, 0, 16, windowsPalette);
}
예제 #6
0
void scan_cats(const struct Map_info *Map, int field,
	       const char *style, const char *rules,
	       const struct FPRange *range, struct Colors *colors)
{
    int ltype, lmin, lmax, cmin, cmax;
    struct line_cats *Cats;

    cmin = cmax = -1;
    Cats = Vect_new_cats_struct();

    G_message(_("Reading features..."));
    while(TRUE) {
	ltype = Vect_read_next_line(Map, NULL, Cats);
	if (ltype == -1)
	    G_fatal_error(_("Unable to read vector map"));
	if (ltype == -2)
	    break; /* EOF */

	scan_layer(field, Cats, &lmin, &lmax);

	if (cmin == -1 || lmin <= cmin)
	    cmin = lmin;
	if (cmax == -1 || lmax >= cmax)
	    cmax = lmax;
    }

    if (range) {
	if (range->min >= cmin && range->min <= cmax)
	    cmin = range->min;
	else
	    G_warning(_("Min value (%d) is out of range %d,%d"),
		      (int) range->min, cmin, cmax);
	
	if (range->max <= cmax && range->max >= cmin)
	    cmax = range->max;
	else
	    G_warning(_("Max value (%d) is out of range %d,%d"),
		      (int) range->max, cmin, cmax);
    }

    if (style)
	make_colors(colors, style, (DCELL) cmin, (DCELL) cmax, FALSE);
    else if (rules) {
	load_colors(colors, rules, (DCELL) cmin, (DCELL) cmax, FALSE);
    }

    Vect_destroy_cats_struct(Cats);
}
예제 #7
0
void particle_system_init(ParticleSystem *sys){
    sys->num_cubes = sys->num_particles + 1;
    sys->num_triangles = 6 * 2 * 3 * sys->num_cubes;
    sys->num_floats = 6 * 2 * 3 * 3 * sys->num_cubes;

    sys->attractor_size = 0.03;
    sys->particle_size = 0.003;
    
    sys->attractor[0] = 0;
    sys->attractor[1] = 0;
    sys->attractor[2] = 0;

    int i;
    load_cubes(sys->attractor, sys->cubes, sys->attractor_size);
    for (i = 0; i < 3 * 3 * 12; i++) {
        sys->colors[i] = 1.0; //want the cube to be all white
    }

    int j,k,l;
    for(i = 0;i < sys->num_particles;i++){
        j = i * 3 + 0;
        k = i * 3 + 1;
        l = i * 3 + 2;
        sys->positions[j] = next_random();
        sys->positions[k] = next_random();
        sys->positions[l] = next_random();

        load_cubes(sys->positions + j, sys->cubes + (i+1) * 3 * 36, sys->particle_size);
        load_colors(sys->colors + (i+1) * 3 * 36);

        sys->velocities[j] = next_random();
        sys->velocities[k] = next_random();
        sys->velocities[l] = next_random();
        
        sys->accelerations[j] = 0.0;
        sys->accelerations[k] = 0.0;
        sys->accelerations[l] = 0.0;
    }

    sys->friction_coeff = 0.25;
}
예제 #8
0
static void load_options(void)
{
	XFILE *file;
	Options tmp;
	int error = 0;
	long n, opt_n;

	get_set_video(0); /* DjV 007 030103 get current video mode */
	
	if ((file = x_fopen(optname, O_DENYW | O_RDONLY, &error)) != NULL)
	{
		opt_n = sizeof(Options);
		tmp.version = 0;
		x_fread(file, &tmp, sizeof(int));

/* HR 240103: load older cfg versions */
		if (   tmp.version >= MIN_VERSION
		    && tmp.version <  CFG_VERSION
		   )
		{
			memset(&tmp.V2_2, 0, sizeof(tmp.V2_2));
			opt_n -= sizeof(tmp.V2_2);
		}

		x_fclose(file);
	}

	if ((file = x_fopen(optname, O_DENYW | O_RDONLY, &error)) != NULL)
	{
		if ((n = x_fread(file, &tmp, opt_n)) == opt_n)
		{
			if (   tmp.version >= MIN_VERSION		/* DjV 005 120103 (was 0x119) */
			    && tmp.version <= CFG_VERSION
			    && tmp.magic   == MAGIC
			   )
			{
				options = tmp;
				if (opt_n != sizeof(Options))		/* HR 240103 */
				{
					options.V2_2.fields = WD_SHSIZ | WD_SHDAT | WD_SHTIM | WD_SHATT; /* DjV 010 251202 HR 240103 */
					options.attribs = FA_SUBDIR | FA_SYSTEM; /* DjV 004 251202 HR 240103 */
				}
				ins_shorts();     /* DjV 019 080103 put kbd shortcuts into menu texts */
				wd_deselect_all();
				wd_default();

				if (tmp.cprefs & SAVE_COLORS)
					error = load_colors(file);

				if (error == 0)
					if ((error = dsk_load(file)) == 0)
						if ((error = ft_load(file)) == 0)
							if ((error = icnt_load(file)) == 0)
								if ((error = app_load(file)) == 0)
									if ((error = prg_load(file)) == 0)
										error = wd_load(file);
			}
			else
			{
				alert_printf(1, MVALIDCF);
				x_fclose(file);
				return;
			}
			/* DjV 007 030103 ---vvv--- */
			
			/* If read ok, set video state but do not change resolution */
			
			get_set_video(1);
			
			/* DjV 007 030103 ---^^^--- */
		}
		else
		{
			error = (n < 0) ? (int) n : EEOF;
			hndl_error(MLOADCFG, error);
			x_fclose(file);
			return;
		}
		x_fclose(file);
	}

	if (error != 0)
	{
		hndl_error(MLOADCFG, error);

		opt_default();
		dsk_default();
		ft_default();
		icnt_default();
		app_default();
		prg_default();
		wd_default();
	}

	if (options.version < 0x0130)
		options.dial_mode = (options.cprefs & 0x80) ? XD_BUFFERED : XD_NORMAL;

	xd_setposmode((options.cprefs & DIALPOS_MODE) ? XD_MOUSE : XD_CENTERED);
	set_dialmode();

	options.version = CFG_VERSION;
}
예제 #9
0
void scan_z(struct Map_info *Map, int field,
            const char *style, const char *rules,
            const struct FPRange *range, struct Colors *colors)
{
    int ltype, line, cat, i;
    int items_alloc;
    double zmin, zmax;
    struct line_pnts *Points;
    struct line_cats *Cats;
    
    struct Colors vcolors;
    
    dbCatValArray cvarr;

    Points = Vect_new_line_struct();
    Cats = Vect_new_cats_struct();
    
    items_alloc = 0;
    db_CatValArray_init(&cvarr);
    cvarr.ctype = DB_C_TYPE_DOUBLE;

    Vect_set_constraint_field(Map, field);
    Vect_set_constraint_type(Map, GV_POINTS); /* points, centroids or kernels only) */
        
    G_message(_("Reading features..."));
    line = i = 0;
    while(TRUE) {
	ltype = Vect_read_next_line(Map, Points, Cats);
	if (ltype == -1)
	    G_fatal_error(_("Unable to read vector map"));
	if (ltype == -2)
	    break; /* EOF */

	G_progress(++line, 1e4);
        
        if (Vect_cat_get(Cats, field, &cat) == -1)
            continue; /* skip features without category */
        
        /* add item into cat-value array */
        if (i >= items_alloc) {
            items_alloc += 1000;
            db_CatValArray_realloc(&cvarr, items_alloc);
        }
        cvarr.n_values++;
        cvarr.value[i].cat = cat;
        cvarr.value[i++].val.d = Points->z[0];

	if (line == 1 || Points->z[0] < zmin)
	    zmin = Points->z[0];
	if (line == 1 || Points->z[0] > zmax)
	    zmax = Points->z[0];
    }
    G_progress(1, 1);
    
    /* sort array by z-coordinate */
    db_CatValArray_sort_by_value(&cvarr);
    
    if (range) {
	if (range->min >= zmin && range->min <= zmax)
	    zmin = range->min;
	else
	    G_warning(_("Min value (%f) is out of range %f,%f"),
		      range->min, zmin, zmax);
	
	if (range->max <= zmax && range->max >= zmin)
	    zmax = range->max;
	else
	    G_warning(_("Max value (%f) is out of range %f,%f"),
		      range->max, zmin, zmax);
    }

    if (style)
	make_colors(&vcolors, style, (DCELL) zmin, (DCELL) zmax, TRUE);
    else if (rules) {
	load_colors(&vcolors, rules, (DCELL) zmin, (DCELL) zmax, TRUE);
    }

    /* color table for categories */
    color_rules_to_cats(&cvarr, TRUE, &vcolors, colors);

    Vect_destroy_line_struct(Points);
    Vect_destroy_cats_struct(Cats);
    db_CatValArray_free(&cvarr);

}
예제 #10
0
/*
 * Given an XEvent, process it if it pertains to a ColorBar, else do
 * nothing with it.
 * Input:  event - the X event
 * Output:  whichcb - which colorbar this event pertained to.
 * Return: 1 - if color table was changed.
 *         2 - if reset key was pressed
 *         3 - if <shift>+reset key was pressed
 *         0 - if no change
 */
static int colorbar_process( LUI_COLORBAR *cb, XEvent *event )
{
   static int p1 = 0, p2 = 0, p3 = 0, p4 = 0; /* red, green, blue, alpha */
   static int pentry;
   int i, modify, entry, result;
   static int move_marker;

   result = modify = 0;

   if (event->type==KeyPress) {
      char keybuf[50];
      KeySym key;
      XComposeStatus compose;
      int count;
      count = XLookupString( &event->xkey, keybuf, 50, &key, &compose );
      if (count==1) {
         if (keybuf[0]=='r') {
            /* Reset RGB */
            cb->params[DRAWFLAG] = 0.0;
            result = LUI_RGB_RESET;
         }
         else if (keybuf[0]=='R') {
            /* Reset alpha */
            result = LUI_ALPHA_RESET;
            cb->params[DRAWFLAG] = 0.0;
         }
         else if (keybuf[0]=='c' || keybuf[0]=='C') {
            /* Copy current colors to clipboard */
            copy_colors( cb );
         }
         else if (keybuf[0]=='p' || keybuf[0]=='P') {
            /* Paste clipboard colors to current color widget */
            paste_colors( cb );
            LUI_ColorBarRedraw( cb );
            result = LUI_RGB_CHANGE | LUI_ALPHA_CHANGE;
            cb->params[DRAWFLAG] = 0.0;
            result = LUI_RGB_CHANGE | LUI_ALPHA_CHANGE;
         }

/* WLH 7-18-96 */
         else if (keybuf[0]=='s' || keybuf[0]=='S') {
            /* save colors to a file */
            save_colors( cb );
         }
         else if (keybuf[0]=='l' || keybuf[0]=='L') {
            /* load colors from a file */
            load_colors( cb );
            LUI_ColorBarRedraw( cb );
            return 1;
         }

         else {
            /* if unused key, toggle help display */
            cb->helpflag = !cb->helpflag;
            LUI_ColorBarRedraw( cb );
         }
      }
      else if (key == XK_Left) {
         /* rotate left */
         cb->params[BIAS] -= 0.03/cb->params[CURVE];
         result = LUI_RGB_SHAPE;
         cb->params[DRAWFLAG] = 0.0;
      }
      else if (key == XK_Right) {
         /* rotate right */
         cb->params[BIAS] += 0.03/cb->params[CURVE];
         result = LUI_RGB_SHAPE;
         cb->params[DRAWFLAG] = 0.0;
      }
      else if (key == XK_Up) {
         /* expand color map */
         if (event->xkey.state & ANY_MODIFIER) {
            cb->params[ALPHAPOW] -= 0.1;
            if (cb->params[ALPHAPOW]<0.0)
              cb->params[ALPHAPOW] = 0.0;
            result = LUI_ALPHA_SHAPE;
            cb->params[DRAWFLAG] = 0.0;
         }
         else {
            cb->params[CURVE] -= 0.1;
            result = LUI_RGB_SHAPE;
            cb->params[DRAWFLAG] = 0.0;
         }
      }
      else if (key == XK_Down) {
         /* compress color map */
         if (event->xkey.state & ANY_MODIFIER) {
            cb->params[ALPHAPOW] += 0.1;
            result = LUI_ALPHA_SHAPE;
            cb->params[DRAWFLAG] = 0.0;
         }
         else {
            cb->params[CURVE] += 0.1;
            result = LUI_RGB_SHAPE;
            cb->params[DRAWFLAG] = 0.0;
         }
      }
   }
   else if (event->type==Expose && event->xexpose.count==0) {
      LUI_ColorBarRedraw( cb );
      result = 0;
   }
   else if (event->type==ConfigureNotify) {
/* MJK 4.15.99 */
      LUI_ColorBarSetSize( cb, event->xconfigure.width, event->xconfigure.height );
      result = 0;
   }
   else if (event->type==ButtonPress ) {
      if (event->xbutton.y<cb->wedge_y) {
         /* change color function */
         move_marker = 0;
      }
      else {
         /* change marker position */
         move_marker = 1;
      }
      /* determine which curve to modify */
      if (event->xbutton.state&ANY_MODIFIER) {
         p4 = 1;
      }
      else {
         if (event->xbutton.button==Button1)  p1 = 1;
         if (event->xbutton.button==Button2)  p2 = 1;
         if (event->xbutton.button==Button3)  p3 = 1;
      }
      pentry = x_to_index( cb, event->xbutton.x );
      modify = 1;
   }
   else if (event->type==ButtonRelease) {
      if (p1 || p2 || p3) {
         result = LUI_RGB_CHANGE;
      }
      else {
         result = LUI_ALPHA_CHANGE;
      }
      if (event->xbutton.button==Button1)  p1 = 0;
      if (event->xbutton.button==Button2)  p2 = 0;
      if (event->xbutton.button==Button3)  p3 = 0;
      p4 = 0;
   }
   else if (event->type==MotionNotify) {
      /* Flush extra MotionNotify events */
      while (QLength(LUI_Display)>0) {
         XEvent next;
         XPeekEvent(LUI_Display, &next);
         if (next.type!=MotionNotify)
            break;
         XNextEvent(LUI_Display, event);
      }
      modify = 1;
   }


   /* Modify one or more of the color curves */

   if (modify && (p1 || p2 || p3 || p4)) {
      /* calculate which entry in color table to change */
      entry = x_to_index( cb, event->xbutton.x );
      /* update */
      if (move_marker) {
         /* changing marker position */
         cb->markerpos = entry;
         redraw_marker( cb );
      }
      else {
         /* changing color graph */
         int a, b, value;

         value = y_to_intensity( cb, event->xbutton.y );

         if (pentry<=entry) {
            a = pentry;
            b = entry;
         }
         else {
            a = entry;
            b = pentry;
         }

         /* update entries from 'pentry' to 'entry' */
         for (i=a; i<=b; i++) {
            int red, green, blue, alpha;
            red = UNPACK_RED(cb->table[i]);
            green = UNPACK_GREEN(cb->table[i]);
            blue = UNPACK_BLUE(cb->table[i]);
            alpha = UNPACK_ALPHA(cb->table[i]);
            if (p1) {
               /* modify red */
               red = value;
            }
            if (p2) {
               /* modify green */
               green = value;
            }
            if (p3) {
               /* modify blue */
               blue = value;
            }
            if (p4) {
               /* modify alpha */
               alpha = value;
            }
            /* change the color table entry */
            cb->table[i] = PACK_COLOR(red,green,blue,alpha);
         } /* for */

         /* redraw the color curves */
         if (pentry<entry)
           redraw_range( cb, pentry-1, entry+1 );
         else
           redraw_range( cb, entry-1, pentry+1 );

         pentry = entry;

         if (p4) {
            /* update min,max alpha values */
            cb->minalpha = 256;
            cb->maxalpha = 0;
            for (i=0;i<cb->table_size;i++) {
               int a = UNPACK_ALPHA( cb->table[i] );
               if (a<cb->minalpha)  cb->minalpha = a;
               if (a>cb->maxalpha)  cb->maxalpha = a;
            }
         }

         if (p4) {
			  result = LUI_ALPHA_MODIFY;
			  /*
            result = LUI_ALPHA_CHANGE;
			  */
         }
         else {
            result = LUI_RGB_MODIFY;
				/*
            result = LUI_RGB_CHANGE;
				*/
         }
         cb->params[DRAWFLAG] = 1.0;
      }
   } /*modify*/


   if (result!=0 && cb->callback) {
      (*cb->callback)(cb, result);
   }

   return result;
}
예제 #11
0
int scan_attr(const struct Map_info *Map, int layer, const char *column_name,
	      const char *style, const char *rules,
	      const struct FPRange *range, struct Colors *colors)
{
    int ctype, is_fp, nrec;
    double fmin, fmax;
    
    struct field_info *fi;
    struct Colors vcolors;
    dbDriver *driver;
    dbCatValArray cvarr;

    Rast_init_colors(colors);
    
    fi = Vect_get_field(Map, layer);
    if (!fi)
	G_fatal_error(_("Database connection not defined for layer %d"),
		      layer);

    driver = db_start_driver_open_database(fi->driver, fi->database);
    if (!driver)
	G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
		      fi->database, fi->driver);
    db_set_error_handler_driver(driver);

    ctype = db_column_Ctype(driver, fi->table, column_name);
    if (ctype == -1)
	G_fatal_error(_("Column <%s> not found in table <%s>"),
		      column_name, fi->table);
    if (ctype != DB_C_TYPE_INT && ctype != DB_C_TYPE_DOUBLE)
	G_fatal_error(_("Column <%s> is not numeric"), column_name);

    is_fp = ctype == DB_C_TYPE_DOUBLE;

    nrec = db_select_CatValArray(driver, fi->table, fi->key, column_name,
				 NULL, &cvarr);
    if (nrec < 1) {
	G_important_message(_("No data selected"));
	return 0;
    }
    
    /* color table for values */
    db_CatValArray_sort_by_value(&cvarr);
    if (is_fp) {
	fmin = cvarr.value[0].val.d;
	fmax = cvarr.value[cvarr.n_values-1].val.d;

	if (range) {
	    if (range->min >= fmin && range->min <= fmax)
		fmin = range->min;
	    else
		G_warning(_("Min value (%f) is out of range %f,%f"),
			  range->min, fmin, fmax);
	    
	    if (range->max <= fmax && range->max >= fmin)
		fmax = range->max;
	    else
		G_warning(_("Max value (%f) is out of range %f,%f"),
			  range->max, fmin, fmax);
	}
    }
    else {
	fmin = cvarr.value[0].val.i;
	fmax = cvarr.value[cvarr.n_values-1].val.i;
	
	if (range) {
	    if (range->min >= fmin && range->min <= fmax)
		fmin = range->min;
	    else
		G_warning(_("Min value (%d) is out of range %d,%d"),
			  (int) range->min, (int) fmin, (int) fmax);
	    
	    if (range->max <= fmax && range->max >= fmin)
		fmax = range->max;
	    else
		G_warning(_("Max value (%d) is out of range %d,%d"),
			  (int) range->max, (int) fmin, (int) fmax);
	}
    }
    if (style)
	make_colors(&vcolors, style, (DCELL) fmin, (DCELL) fmax, is_fp);
    else if (rules)
	load_colors(&vcolors, rules, (DCELL) fmin, (DCELL) fmax, is_fp);

    /* color table for categories */
    color_rules_to_cats(&cvarr, is_fp, &vcolors, colors);

    db_close_database(driver);

    return is_fp;
}