"Fossies" - the Fresh Open Source Software Archive

Member "g3data-1.5.4/g3data/drawing.c" (8 Jan 2011, 4694 Bytes) of package /linux/privat/old/g3data-1.5.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "drawing.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2                                                                                                                                                                      
    3 g3data : A program for grabbing data from scanned graphs
    4 Copyright (C) 2000 Jonas Frantz
    5                                                                                                                                                                      
    6     This file is part of g3data.
    7                                                                                                                                                                      
    8     g3data is free software; you can redistribute it and/or modify
    9     it under the terms of the GNU General Public License as published by
   10     the Free Software Foundation; either version 2 of the License, or
   11     (at your option) any later version.
   12                                                                                                                                                                      
   13     g3data is distributed in the hope that it will be useful,
   14     but WITHOUT ANY WARRANTY; without even the implied warranty of
   15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16     GNU General Public License for more details.
   17                                                                                                                                                                      
   18     You should have received a copy of the GNU General Public License
   19     along with this program; if not, write to the Free Software
   20     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21                                                                                                                                                                      
   22                                                                                                                                                                      
   23 Authors email : jonas.frantz@welho.com
   24                                                                                                                                                                      
   25 */
   26 
   27 #include <stdlib.h>
   28 #include <gtk/gtk.h>
   29 #include "main.h"
   30 #include "drawing.h"
   31 
   32 #define MARKERLENGTH 6                  /* Axis marker length */
   33 #define MARKERTHICKNESS 2               /* Axis marker thickness */
   34 
   35 /****************************************************************/
   36 /* This function draws the X-axis, Y-axis or point marker on    */
   37 /* the drawing_area depending on the value of the type      */
   38 /* parameter.                           */
   39 /****************************************************************/
   40 void DrawMarker(cairo_t *cr, gint x, gint y, gint type, GdkColor *color) 
   41 {
   42     if (type == 0) {
   43         gdk_cairo_set_source_color(cr, &color[0]);
   44         cairo_move_to(cr, x - MARKERLENGTH, y);
   45         cairo_rel_line_to(cr, 2 * MARKERLENGTH, 0);
   46         cairo_move_to(cr, x, y);
   47         cairo_rel_line_to(cr, 0, -MARKERLENGTH);
   48         cairo_stroke(cr);
   49     } else if (type == 1) {
   50         gdk_cairo_set_source_color(cr, &color[1]);
   51         cairo_move_to(cr, x, y - MARKERLENGTH);
   52         cairo_rel_line_to(cr, 0, 2 * MARKERLENGTH);
   53         cairo_move_to(cr, x, y);
   54         cairo_rel_line_to(cr, MARKERLENGTH, 0);
   55         cairo_stroke(cr);
   56     } else if (type == 2) {
   57         gdk_cairo_set_source_color(cr, &color[2]);
   58         cairo_rectangle(cr, x - MARKERLENGTH / 2, y - MARKERLENGTH / 2, MARKERLENGTH, MARKERLENGTH);
   59         cairo_stroke(cr);
   60     }
   61 }
   62 
   63 
   64 /****************************************************************/
   65 /* This function initializes the colors which are used when     */
   66 /* drawing the axispoints and the graph points          */
   67 /****************************************************************/
   68 gboolean setcolors(GdkColor **color)
   69 {
   70   gboolean *success;
   71   gint i, ncolors;
   72   gushort xcolor[19][4] = {{40000,20000,48000},             /* x axis marker color */
   73                {40000,48000,20000},             /* y axis marker color */
   74                {65535,00000,00000},             /* outer square color */
   75                {65535,65535,65535}};            /* inner square color */
   76 
   77     ncolors=4;                              /* Number of colors to be initialized */
   78     *color = (GdkColor *) calloc (ncolors, sizeof(GdkColor));       /* Allocate memory for the colors */
   79     success = (gboolean *) calloc (ncolors, sizeof(gboolean));
   80 
   81     for(i=0;i<ncolors;i++) {                        /* Transfer colorindexes into colors array */
   82     (*color)[i].red = xcolor[i][0];
   83         (*color)[i].green = xcolor[i][1];
   84         (*color)[i].blue = xcolor[i][2];
   85     }
   86 
   87 /* Allocate the colors */
   88     gdk_colormap_alloc_colors(gdk_colormap_get_system(),*color, ncolors, FALSE, FALSE, success);
   89     free(success);
   90 
   91   return TRUE;
   92 }