GRASS Programmer's Manual  6.4.2(2012)
symbol.c
Go to the documentation of this file.
00001 
00002 /****************************************************************************
00003  *
00004  * MODULE:       display
00005  * AUTHOR(S):    Hamish Bowman <hamish_nospam yahoo.com> (original contributor)
00006  *                      (adapted from Radim Blazek's d.vect code)
00007  *               Glynn Clements <glynn gclements.plus.com>
00008  * PURPOSE:      draw a symbol at pixel coordinates
00009  * COPYRIGHT:    (C) 2005-2007 by M. Hamish Bowman, and
00010  *                              the GRASS Development Team
00011  *
00012  *               This program is free software under the GNU General Public
00013  *               License (>=v2). Read the file COPYING that comes with GRASS
00014  *               for details.
00015  *
00016  *****************************************************************************/
00017 
00018 #include <grass/gis.h>
00019 #include <grass/raster.h>
00020 #include <grass/symbol.h>
00021 #include <grass/glocale.h>
00022 
00047 void D_symbol(const SYMBOL * Symb, int x0, int y0,
00048               const RGBA_Color * line_color, const RGBA_Color * fill_color)
00049 {
00050     int i, j, k;
00051     const SYMBPART *part;
00052     const SYMBCHAIN *chain;
00053     int xp, yp;
00054     int *x, *y;
00055 
00056 
00057     G_debug(2, "D_symbol(): %d parts", Symb->count);
00058 
00059     for (i = 0; i < Symb->count; i++) {
00060         part = Symb->part[i];
00061 
00062         switch (part->type) {
00063 
00064         case S_POLYGON:
00065             /* draw background fills */
00066             if ((part->fcolor.color == S_COL_DEFAULT &&
00067                  fill_color->a != RGBA_COLOR_NONE) ||
00068                 part->fcolor.color == S_COL_DEFINED) {
00069                 if (part->fcolor.color == S_COL_DEFAULT)
00070                     R_RGB_color(fill_color->r, fill_color->g, fill_color->b);
00071                 else
00072                     R_RGB_color(part->fcolor.r, part->fcolor.g,
00073                                 part->fcolor.b);
00074 
00075                 for (j = 0; j < part->count; j++) {     /* for each component polygon */
00076                     chain = part->chain[j];
00077 
00078                     x = G_malloc(sizeof(int) * chain->scount);
00079                     y = G_malloc(sizeof(int) * chain->scount);
00080 
00081                     for (k = 0; k < chain->scount; k++) {
00082                         x[k] = x0 + chain->sx[k];
00083                         y[k] = y0 - chain->sy[k];
00084                     }
00085                     R_polygon_abs(x, y, chain->scount);
00086 
00087                     G_free(x);
00088                     G_free(y);
00089                 }
00090 
00091             }
00092             /* again, to draw the lines */
00093             if ((part->color.color == S_COL_DEFAULT &&
00094                  line_color->a != RGBA_COLOR_NONE) ||
00095                 part->color.color == S_COL_DEFINED) {
00096                 if (part->color.color == S_COL_DEFAULT) {
00097                     R_RGB_color(line_color->r, line_color->g, line_color->b);
00098                 }
00099                 else
00100                     R_RGB_color(part->color.r, part->color.g, part->color.b);
00101 
00102                 for (j = 0; j < part->count; j++) {
00103                     chain = part->chain[j];
00104 
00105                     for (k = 0; k < chain->scount; k++) {
00106                         xp = x0 + chain->sx[k];
00107                         yp = y0 - chain->sy[k];
00108                         if (k == 0)
00109                             R_move_abs(xp, yp);
00110                         else
00111                             R_cont_abs(xp, yp);
00112                     }
00113                 }
00114             }
00115             break;
00116 
00117         case S_STRING:
00118             if (part->color.color == S_COL_NONE)
00119                 break;
00120             else if (part->color.color == S_COL_DEFAULT &&
00121                      line_color->a != RGBA_COLOR_NONE)
00122                 R_RGB_color(line_color->r, line_color->g, line_color->b);
00123             else
00124                 R_RGB_color(part->color.r, part->color.g, part->color.b);
00125 
00126             chain = part->chain[0];
00127 
00128             for (j = 0; j < chain->scount; j++) {
00129                 xp = x0 + chain->sx[j];
00130                 yp = y0 - chain->sy[j];
00131                 if (j == 0)
00132                     R_move_abs(xp, yp);
00133                 else
00134                     R_cont_abs(xp, yp);
00135             }
00136             break;
00137 
00138         }                       /* switch */
00139     }                           /* for loop */
00140 }
00141 
00142 
00159 void D_symbol2(const SYMBOL * Symb, int x0, int y0,
00160                const RGBA_Color * primary_color,
00161                const RGBA_Color * secondary_color)
00162 {
00163     /* TODO: merge duplicate D_symbol() code into common lib fns */
00164     int i, j, k;
00165     const SYMBPART *part;
00166     const SYMBCHAIN *chain;
00167     int xp, yp;
00168     int *x, *y;
00169 
00170 
00171     G_debug(2, "D_symbol(): %d parts", Symb->count);
00172 
00173     for (i = 0; i < Symb->count; i++) {
00174         part = Symb->part[i];
00175 
00176         switch (part->type) {
00177 
00178         case S_POLYGON:
00179             /* draw background fills */
00180             if ((part->fcolor.color == S_COL_DEFAULT &&
00181                  primary_color->a != RGBA_COLOR_NONE) ||
00182                 part->fcolor.color == S_COL_DEFINED) {
00183                 if (part->fcolor.color == S_COL_DEFAULT)
00184                     R_RGB_color(primary_color->r, primary_color->g,
00185                                 primary_color->b);
00186                 else
00187                     R_RGB_color(part->fcolor.r, part->fcolor.g,
00188                                 part->fcolor.b);
00189 
00190                 for (j = 0; j < part->count; j++) {     /* for each component polygon */
00191                     chain = part->chain[j];
00192 
00193                     x = G_malloc(sizeof(int) * chain->scount);
00194                     y = G_malloc(sizeof(int) * chain->scount);
00195 
00196                     for (k = 0; k < chain->scount; k++) {
00197                         x[k] = x0 + chain->sx[k];
00198                         y[k] = y0 - chain->sy[k];
00199                     }
00200                     R_polygon_abs(x, y, chain->scount);
00201 
00202                     G_free(x);
00203                     G_free(y);
00204                 }
00205 
00206             }
00207             /* again, to draw the lines */
00208             if ((part->color.color == S_COL_DEFAULT &&
00209                  secondary_color->a != RGBA_COLOR_NONE) ||
00210                 part->color.color == S_COL_DEFINED) {
00211                 if (part->color.color == S_COL_DEFAULT) {
00212                     R_RGB_color(secondary_color->r, secondary_color->g,
00213                                 secondary_color->b);
00214                 }
00215                 else
00216                     R_RGB_color(part->color.r, part->color.g, part->color.b);
00217 
00218                 for (j = 0; j < part->count; j++) {
00219                     chain = part->chain[j];
00220 
00221                     for (k = 0; k < chain->scount; k++) {
00222                         xp = x0 + chain->sx[k];
00223                         yp = y0 - chain->sy[k];
00224                         if (k == 0)
00225                             R_move_abs(xp, yp);
00226                         else
00227                             R_cont_abs(xp, yp);
00228                     }
00229                 }
00230             }
00231             break;
00232 
00233         case S_STRING:
00234             if (part->color.color == S_COL_NONE)
00235                 break;
00236             else if (part->color.color == S_COL_DEFAULT &&
00237                      primary_color->a != RGBA_COLOR_NONE)
00238                 R_RGB_color(primary_color->r, primary_color->g,
00239                             primary_color->b);
00240             else
00241                 R_RGB_color(part->color.r, part->color.g, part->color.b);
00242 
00243             chain = part->chain[0];
00244 
00245             for (j = 0; j < chain->scount; j++) {
00246                 xp = x0 + chain->sx[j];
00247                 yp = y0 - chain->sy[j];
00248                 if (j == 0)
00249                     R_move_abs(xp, yp);
00250                 else
00251                     R_cont_abs(xp, yp);
00252             }
00253             break;
00254 
00255         }                       /* switch */
00256     }                           /* for loop */
00257 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines