-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_basic.c
168 lines (143 loc) · 5.61 KB
/
test_basic.c
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
161
162
163
164
165
166
167
168
/*
* Screentest - CRT/LCD monitor testing utility.
* https://tobix.github.io/screentest/
* Copyright (C) 2001 Jan "Yenya" Kasprzak <[email protected]>
* Copyright (C) 2006-2017 Tobias Gruetzmacher <[email protected]>
* Copyright (C) 2021 Apr Thorsten Kattanek <[email protected]>
*
* 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
*/
#include <config.h>
#include <gtk/gtk.h>
#include <stdio.h>
#include "callbacks.h"
#include "gettext.h"
#include "screentest_colors.h"
#define _(String) gettext(String)
#define N_(String) gettext_noop(String)
#define BASIC_STEP 40
static void draw_boxes(cairo_t *cr, const GdkRGBA *colors, gint ncols, gint x,
gint y, gint d) {
const GdkRGBA *col;
int i;
for (i = 0; i < ncols; i++) {
col = &colors[i];
cairo_set_source_rgb(cr, col->red, col->green, col->blue);
cairo_rectangle(cr, x, y, d, d);
cairo_fill(cr);
x += d;
}
screentest_set_color_fg(cr);
}
static void basic_draw(GtkWidget *widget, cairo_t *cr) {
PangoLayout *pl;
GdkWindow *win = gtk_widget_get_window(widget);
gint w, h;
gint i, b, d;
PangoRectangle ink_rect;
gint maxwidth, maxheight;
gint widths[7];
static gchar *text[] = {
"Screentest v" VERSION,
"(C) 2001 Jan \"Yenya\" Kasprzak <[email protected]>",
"(C) 2006-2017 Tobias Gruetzmacher <[email protected]>",
"(C) 2021 Apr Thorsten Kattanek <[email protected]>",
N_("Left Button - param cycle, if any"),
N_("Middle Button - color cycle"),
N_("Right Button - menu"),
};
h = gdk_window_get_height(win);
w = gdk_window_get_width(win);
cairo_set_line_width(cr, 1.0);
pl = pango_cairo_create_layout(cr);
screentest_set_color_bg(cr);
cairo_paint(cr);
screentest_set_color_fg(cr);
for (i = ((w - 1) % BASIC_STEP) / 2; i < w; i += BASIC_STEP)
cairo_rectangle(cr, i, 0, 1, h);
for (i = ((h - 1) % BASIC_STEP) / 2; i < h; i += BASIC_STEP)
cairo_rectangle(cr, 0, i, w, 1);
cairo_fill(cr);
d = w / 4;
if (d > h / 4)
d = h / 4;
maxheight = 0;
maxwidth = 0;
for (i = 0; i < 7; i++) {
pango_layout_set_text(pl, gettext(text[i]), -1);
pango_layout_get_extents(pl, &ink_rect, NULL);
double x = pango_units_to_double(ink_rect.height);
if (x > maxheight)
maxheight = x;
widths[i] = pango_units_to_double(ink_rect.width);
if (widths[i] > maxwidth)
maxwidth = widths[i];
}
maxwidth += 20;
maxheight = 3 * maxheight / 2;
cairo_rectangle(cr, (w - maxwidth) / 2 + 0.5, d / 2 - 2 * maxheight + 0.5,
maxwidth, 5 * maxheight);
cairo_rectangle(cr, (w - maxwidth) / 2 + 0.5, h - d / 2 - 2 * maxheight + 0.5,
maxwidth, 4 * maxheight);
cairo_stroke(cr);
screentest_set_color_bg(cr);
cairo_rectangle(cr, (w - maxwidth) / 2 + 1, d / 2 - 2 * maxheight + 1,
maxwidth - 1, 5 * maxheight - 1);
cairo_rectangle(cr, (w - maxwidth) / 2 + 1, h - d / 2 - 2 * maxheight + 1,
maxwidth - 1, 4 * maxheight - 1);
cairo_fill(cr);
screentest_set_color_fg(cr);
cairo_move_to(cr, (w - widths[0]) / 2, d / 2 - 4 * maxheight / 3);
pango_layout_set_text(pl, gettext(text[0]), -1);
pango_cairo_show_layout(cr, pl);
cairo_move_to(cr, (w - widths[1]) / 2, d / 2 - maxheight / 3);
pango_layout_set_text(pl, gettext(text[1]), -1);
pango_cairo_show_layout(cr, pl);
cairo_move_to(cr, (w - widths[2]) / 2, d / 2 + 2 * maxheight / 3);
pango_layout_set_text(pl, gettext(text[2]), -1);
pango_cairo_show_layout(cr, pl);
cairo_move_to(cr, (w - widths[3]) / 2, d / 2 + 5 * maxheight / 3);
pango_layout_set_text(pl, gettext(text[3]), -1);
pango_cairo_show_layout(cr, pl);
cairo_move_to(cr, (w - widths[4]) / 2, h - d / 2 - 4 * maxheight / 3);
pango_layout_set_text(pl, gettext(text[4]), -1);
pango_cairo_show_layout(cr, pl);
cairo_move_to(cr, (w - widths[5]) / 2, h - d / 2 - maxheight / 3);
pango_layout_set_text(pl, gettext(text[5]), -1);
pango_cairo_show_layout(cr, pl);
cairo_move_to(cr, (w - widths[6]) / 2, h - d / 2 + 2 * maxheight / 3);
pango_layout_set_text(pl, gettext(text[6]), -1);
pango_cairo_show_layout(cr, pl);
b = 7 * d / 4;
draw_boxes(cr, fgcolors, SCREENTEST_COLORS_MAX, (w - b) / 2,
h / 2 - b / SCREENTEST_COLORS_MAX, b / SCREENTEST_COLORS_MAX);
draw_boxes(cr, grays, SCREENTEST_GRAYS_MAX, (w - b) / 2, h / 2,
b / SCREENTEST_GRAYS_MAX);
cairo_arc(cr, 0 + d / 2 + 0.5, 0 + d / 2 + 0.5, d / 2, 0,
2 * G_PI); // Upper left
cairo_new_sub_path(cr);
cairo_arc(cr, 0 + d / 2 + 0.5, h - d / 2 - 0.5, d / 2, 0,
2 * G_PI); // Lower left
cairo_new_sub_path(cr);
cairo_arc(cr, w - d / 2 - 0.5, h - d / 2 - 0.5, d / 2, 0,
2 * G_PI); // Lower right
cairo_new_sub_path(cr);
cairo_arc(cr, w - d / 2 - 0.5, 0 + d / 2 + 0.5, d / 2, 0,
2 * G_PI); // Upper right
cairo_new_sub_path(cr);
cairo_arc(cr, w / 2, h / 2, d, 0, 2 * G_PI);
cairo_stroke(cr);
}
G_MODULE_EXPORT struct test_ops basic_ops = {
.init = NULL, .draw = basic_draw, .cycle = NULL, .close = NULL};