"Fossies" - the Fresh Open Source Software Archive

Member "screentest-2.0/basic_test.c" (28 Jul 2007, 4647 Bytes) of package /linux/privat/old/screentest-2.0.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 "basic_test.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  *  Screentest - CRT/LCD monitor testing utility.
    3  *  http://screentest.sourceforge.net/
    4  *  Copyright (C) 2001 Jan "Yenya" Kasprzak <kas@fi.muni.cz>
    5  *  Copyright (C) 2006-2007 Tobias Gruetzmacher <tobias@portfolio16.de>
    6  *
    7  *  This program is free software; you can redistribute it and/or modify
    8  *  it under the terms of the GNU General Public License version 2 as
    9  *  published by the Free Software Foundation.
   10  *
   11  *  This program is distributed in the hope that it will be useful,
   12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  *  GNU General Public License for more details.
   15  *
   16  *  You should have received a copy of the GNU General Public License
   17  *  along with this program; if not, write to the Free Software
   18  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
   19  */
   20 
   21 #ifdef HAVE_CONFIG_H
   22 #  include <config.h>
   23 #endif
   24 
   25 #include <stdio.h>
   26 #include <gtk/gtk.h>
   27 
   28 #include "callbacks.h"
   29 #include "gettext.h"
   30 #define _(String) gettext(String)
   31 #define N_(String) gettext_noop(String)
   32 
   33 #define BASIC_STEP 40
   34 
   35 static gchar fontname[] =
   36     "-adobe-helvetica-bold-r-normal-*-14-*-*-*-p-*-iso8859-1";
   37 static GdkFont *font;
   38 
   39 static void basic_init(G_GNUC_UNUSED GtkWidget * widget)
   40 {
   41     font = gdk_font_load(fontname);
   42 
   43     if (!font) {
   44         printf("Cannot load font %s, trying 'fixed'.\n", fontname);
   45         font = gdk_font_load("fixed");
   46     }
   47 }
   48 
   49 static void draw_boxes(GdkWindow * win, GdkColor * colors, gint ncols,
   50                gint x, gint y, gint d)
   51 {
   52     int i;
   53 
   54     for (i = 0; i < ncols; i++) {
   55         gdk_gc_set_rgb_fg_color(gc, &colors[i]);
   56 
   57         gdk_draw_rectangle(win, gc, TRUE, x, y, d, d);
   58         x += d;
   59     }
   60 
   61     gdk_gc_set_rgb_fg_color(gc, fg_color);
   62 }
   63 
   64 static void basic_draw(GtkWidget * widget)
   65 {
   66     GdkWindow *win = widget->window;
   67     gint w, h;
   68     gint i, b, d;
   69     gint maxwidth, maxheight;
   70     gint widths[6];
   71     static gchar *text[] = {
   72         "Screentest v" VERSION,
   73         "(C) 2001 Jan \"Yenya\" Kasprzak <kas@fi.muni.cz>",
   74         "(C) 2006-2007 Tobias Gruetzmacher <tobias@portfolio16.de>",
   75         N_("Left Button - param cycle, if any"),
   76         N_("Middle Button - color cycle"),
   77         N_("Right Button - menu"),
   78     };
   79 
   80     gdk_window_get_size(win, &w, &h);
   81 
   82     for (i = ((w - 1) % BASIC_STEP) / 2; i < w; i += BASIC_STEP)
   83         gdk_draw_line(win, gc, i, 0, i, h - 1);
   84     for (i = ((h - 1) % BASIC_STEP) / 2; i < h; i += BASIC_STEP)
   85         gdk_draw_line(win, gc, 0, i, w - 1, i);
   86 
   87     d = w / 4;
   88     if (d > h / 4)
   89         d = h / 4;
   90 
   91     maxheight = 0;
   92     for (i = 0; i < 5; i++) {
   93         int x = gdk_string_height(font, gettext(text[i]));
   94         if (x > maxheight)
   95             maxheight = x;
   96     }
   97 
   98     maxwidth = 0;
   99     for (i = 0; i < 6; i++) {
  100         widths[i] = gdk_string_width(font, gettext(text[i]));
  101         if (widths[i] > maxwidth)
  102             maxwidth = widths[i];
  103     }
  104 
  105     maxwidth += 20;
  106     maxheight = 3 * maxheight / 2;
  107     gdk_draw_rectangle(win, gc, FALSE, (w - maxwidth) / 2,
  108                d / 2 - 2 * maxheight, maxwidth, 4 * maxheight);
  109     gdk_draw_rectangle(win, gc, FALSE, (w - maxwidth) / 2,
  110                h - d / 2 - 2 * maxheight, maxwidth,
  111                4 * maxheight);
  112     gdk_draw_rectangle(win, backgc, TRUE, (w - maxwidth) / 2 + 1,
  113                d / 2 - 2 * maxheight + 1, maxwidth - 1,
  114                4 * maxheight - 1);
  115     gdk_draw_rectangle(win, backgc, TRUE, (w - maxwidth) / 2 + 1,
  116                h - d / 2 - 2 * maxheight + 1, maxwidth - 1,
  117                4 * maxheight - 1);
  118 
  119     gdk_draw_string(win, font, gc, (w - widths[0]) / 2,
  120             d / 2 - 2 * maxheight / 3, gettext(text[0]));
  121     gdk_draw_string(win, font, gc, (w - widths[1]) / 2,
  122             d / 2 + maxheight / 3, gettext(text[1]));
  123     gdk_draw_string(win, font, gc, (w - widths[2]) / 2,
  124             d / 2 + 4 * maxheight / 3, gettext(text[2]));
  125 
  126     gdk_draw_string(win, font, gc, (w - widths[3]) / 2,
  127             h - d / 2 - 2 * maxheight / 3, gettext(text[3]));
  128     gdk_draw_string(win, font, gc, (w - widths[4]) / 2,
  129             h - d / 2 + maxheight / 3, gettext(text[4]));
  130     gdk_draw_string(win, font, gc, (w - widths[5]) / 2,
  131             h - d / 2 + 4 * maxheight / 3, gettext(text[5]));
  132 
  133     b = 7 * d / 4;
  134     draw_boxes(win, fgcolors, COLOR_MAX, (w - b) / 2,
  135            h / 2 - b / COLOR_MAX, b / COLOR_MAX);
  136     draw_boxes(win, grays, GRAYS_MAX, (w - b) / 2, h / 2,
  137            b / GRAYS_MAX);
  138     w--;
  139     h--;
  140     gdk_draw_arc(win, gc, FALSE, 0, 0, d, d, 0, 360 * 64);
  141     gdk_draw_arc(win, gc, FALSE, 0, h - d, d, d, 0, 360 * 64);
  142     gdk_draw_arc(win, gc, FALSE, w - d, h - d, d, d, 0, 360 * 64);
  143     gdk_draw_arc(win, gc, FALSE, w - d, 0, d, d, 0, 360 * 64);
  144     gdk_draw_arc(win, gc, FALSE, w / 2 - d, h / 2 - d, d * 2, d * 2, 0,
  145              360 * 64);
  146 }
  147 
  148 static void basic_close(G_GNUC_UNUSED GtkWidget * widget)
  149 {
  150     gdk_font_unref(font);
  151 }
  152 
  153 struct test_ops basic_ops = {
  154     init:basic_init,
  155     draw:basic_draw,
  156     cycle:NULL,
  157     close:basic_close
  158 };