File: basic_test.c

package info (click to toggle)
screentest 2.0-2.2
  • links: PTS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 1,652 kB
  • ctags: 149
  • sloc: sh: 8,940; ansic: 802; makefile: 65
file content (160 lines) | stat: -rw-r--r-- 4,697 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
 *  Screentest - CRT/LCD monitor testing utility.
 *  http://screentest.sourceforge.net/
 *  Copyright (C) 2001 Jan "Yenya" Kasprzak <kas@fi.muni.cz>
 *  Copyright (C) 2006-2007 Tobias Gruetzmacher <tobias@portfolio16.de>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <stdio.h>
#include <gtk/gtk.h>

#include "callbacks.h"
#include "gettext.h"
#define _(String) gettext(String)
#define N_(String) gettext_noop(String)

#define BASIC_STEP 40

static gchar fontname[] =
    "-adobe-helvetica-bold-r-normal-*-14-*-*-*-p-*-iso8859-1";
static GdkFont *font;

static void basic_init(G_GNUC_UNUSED GtkWidget * widget)
{
	font = gdk_font_load(fontname);

	if (!font) {
		printf("Cannot load font %s, trying 'fixed'.\n", fontname);
		font = gdk_font_load("fixed");
	}
}

static void draw_boxes(GdkWindow * win, GdkColor * colors, gint ncols,
		       gint x, gint y, gint d)
{
	int i;

	for (i = 0; i < ncols; i++) {
		gdk_gc_set_rgb_fg_color(gc, &colors[i]);

		gdk_draw_rectangle(win, gc, TRUE, x, y, d, d);
		x += d;
	}

	gdk_gc_set_rgb_fg_color(gc, fg_color);
}

static void basic_draw(GtkWidget * widget)
{
	bind_textdomain_codeset(PACKAGE, "ISO-8859-1");

	GdkWindow *win = widget->window;
	gint w, h;
	gint i, b, d;
	gint maxwidth, maxheight;
	gint widths[6];
	static gchar *text[] = {
		"Screentest v" VERSION,
		"(C) 2001 Jan \"Yenya\" Kasprzak <kas@fi.muni.cz>",
		"(C) 2006-2007 Tobias Gruetzmacher <tobias@portfolio16.de>",
		N_("Left Button - param cycle, if any"),
		N_("Middle Button - color cycle"),
		N_("Right Button - menu"),
	};

	gdk_window_get_size(win, &w, &h);

	for (i = ((w - 1) % BASIC_STEP) / 2; i < w; i += BASIC_STEP)
		gdk_draw_line(win, gc, i, 0, i, h - 1);
	for (i = ((h - 1) % BASIC_STEP) / 2; i < h; i += BASIC_STEP)
		gdk_draw_line(win, gc, 0, i, w - 1, i);

	d = w / 4;
	if (d > h / 4)
		d = h / 4;

	maxheight = 0;
	for (i = 0; i < 5; i++) {
		int x = gdk_string_height(font, gettext(text[i]));
		if (x > maxheight)
			maxheight = x;
	}

	maxwidth = 0;
	for (i = 0; i < 6; i++) {
		widths[i] = gdk_string_width(font, gettext(text[i]));
		if (widths[i] > maxwidth)
			maxwidth = widths[i];
	}

	maxwidth += 20;
	maxheight = 3 * maxheight / 2;
	gdk_draw_rectangle(win, gc, FALSE, (w - maxwidth) / 2,
			   d / 2 - 2 * maxheight, maxwidth, 4 * maxheight);
	gdk_draw_rectangle(win, gc, FALSE, (w - maxwidth) / 2,
			   h - d / 2 - 2 * maxheight, maxwidth,
			   4 * maxheight);
	gdk_draw_rectangle(win, backgc, TRUE, (w - maxwidth) / 2 + 1,
			   d / 2 - 2 * maxheight + 1, maxwidth - 1,
			   4 * maxheight - 1);
	gdk_draw_rectangle(win, backgc, TRUE, (w - maxwidth) / 2 + 1,
			   h - d / 2 - 2 * maxheight + 1, maxwidth - 1,
			   4 * maxheight - 1);

	gdk_draw_string(win, font, gc, (w - widths[0]) / 2,
			d / 2 - 2 * maxheight / 3, gettext(text[0]));
	gdk_draw_string(win, font, gc, (w - widths[1]) / 2,
			d / 2 + maxheight / 3, gettext(text[1]));
	gdk_draw_string(win, font, gc, (w - widths[2]) / 2,
			d / 2 + 4 * maxheight / 3, gettext(text[2]));

	gdk_draw_string(win, font, gc, (w - widths[3]) / 2,
			h - d / 2 - 2 * maxheight / 3, gettext(text[3]));
	gdk_draw_string(win, font, gc, (w - widths[4]) / 2,
			h - d / 2 + maxheight / 3, gettext(text[4]));
	gdk_draw_string(win, font, gc, (w - widths[5]) / 2,
			h - d / 2 + 4 * maxheight / 3, gettext(text[5]));

	b = 7 * d / 4;
	draw_boxes(win, fgcolors, COLOR_MAX, (w - b) / 2,
		   h / 2 - b / COLOR_MAX, b / COLOR_MAX);
	draw_boxes(win, grays, GRAYS_MAX, (w - b) / 2, h / 2,
		   b / GRAYS_MAX);
	w--;
	h--;
	gdk_draw_arc(win, gc, FALSE, 0, 0, d, d, 0, 360 * 64);
	gdk_draw_arc(win, gc, FALSE, 0, h - d, d, d, 0, 360 * 64);
	gdk_draw_arc(win, gc, FALSE, w - d, h - d, d, d, 0, 360 * 64);
	gdk_draw_arc(win, gc, FALSE, w - d, 0, d, d, 0, 360 * 64);
	gdk_draw_arc(win, gc, FALSE, w / 2 - d, h / 2 - d, d * 2, d * 2, 0,
		     360 * 64);
}

static void basic_close(G_GNUC_UNUSED GtkWidget * widget)
{
	gdk_font_unref(font);
}

struct test_ops basic_ops = {
	init:basic_init,
	draw:basic_draw,
	cycle:NULL,
	close:basic_close
};