1 /*****************************************************************************
2 * This file is part of gfxprim library. *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
19 * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
20 * <jiri.bluebear.dluhos@gmail.com> *
22 * Copyright (C) 2009-2014 Cyril Hrubis <metan@ucw.cz> *
24 *****************************************************************************/
29 static GP_Pixel black_pixel
, red_pixel
, yellow_pixel
, green_pixel
, blue_pixel
,
30 darkgray_pixel
, white_pixel
;
32 static int font_flag
= 0;
37 static GP_FontFace
*font
= NULL
;
38 static GP_TextStyle style
= GP_DEFAULT_TEXT_STYLE
;
40 static GP_Backend
*win
;
42 void redraw_screen(void)
44 GP_Fill(win
->pixmap
, black_pixel
);
46 /* draw axes intersecting in the middle, where text should be shown */
47 GP_HLine(win
->pixmap
, 0, X
, Y
/2, darkgray_pixel
);
48 GP_VLine(win
->pixmap
, X
/2, 0, Y
, darkgray_pixel
);
52 style
.font
= &GP_DefaultProportionalFont
;
55 style
.font
= &GP_DefaultConsoleFont
;
58 style
.font
= GP_FontTinyMono
;
61 style
.font
= GP_FontTiny
;
64 style
.font
= GP_FontC64
;
71 GP_Text(win
->pixmap
, &style
, X
/2, Y
/2, GP_ALIGN_LEFT
|GP_VALIGN_BELOW
,
72 yellow_pixel
, black_pixel
, "bottom left");
73 GP_Text(win
->pixmap
, &style
, X
/2, Y
/2, GP_ALIGN_RIGHT
|GP_VALIGN_BELOW
,
74 red_pixel
, black_pixel
, "bottom right");
75 GP_Text(win
->pixmap
, &style
, X
/2, Y
/2, GP_ALIGN_RIGHT
|GP_VALIGN_ABOVE
,
76 blue_pixel
, black_pixel
, "top right");
77 GP_Text(win
->pixmap
, &style
, X
/2, Y
/2, GP_ALIGN_LEFT
|GP_VALIGN_ABOVE
,
78 green_pixel
, black_pixel
, "top left");
80 GP_HLine(win
->pixmap
, 0, X
, Y
/3, darkgray_pixel
);
81 GP_Text(win
->pixmap
, &style
, X
/2, Y
/3, GP_ALIGN_CENTER
|GP_VALIGN_BASELINE
,
82 white_pixel
, black_pixel
, "x center y baseline");
85 static void event_loop(void)
90 GP_BackendWaitEvent(win
, &ev
);
94 if (ev
.code
!= GP_EV_KEY_DOWN
)
97 switch (ev
.val
.key
.key
) {
99 win
->pixmap
->x_swap
= !win
->pixmap
->x_swap
;
102 win
->pixmap
->y_swap
= !win
->pixmap
->y_swap
;
105 win
->pixmap
->axes_swap
= !win
->pixmap
->axes_swap
;
120 style
.pixel_xspace
++;
121 style
.pixel_yspace
++;
124 style
.pixel_xspace
--;
125 style
.pixel_yspace
--;
147 case GP_EV_SYS_RESIZE
:
148 GP_BackendResizeAck(win
);
161 void print_instructions(void)
163 printf("Use the following keys to control the test:\n");
164 printf(" Space ........ toggle font\n");
165 printf(" X ............ mirror X\n");
166 printf(" Y ............ mirror Y\n");
167 printf(" R ............ reverse X and Y\n");
168 printf(" UP/DOWN ...... increase/decrease X and Y space\n");
169 printf(" RIGHT/LEFT ... increase/decrease X and Y mul\n");
172 int main(int argc
, char *argv
[])
174 const char *backend_opts
= "X11";
177 font
= GP_FontFaceLoad(argv
[1], 0, 20);
179 print_instructions();
181 win
= GP_BackendInit(backend_opts
, "Font Align Test");
184 fprintf(stderr
, "Failed to initalize backend '%s'\n",
189 black_pixel
= GP_RGBToPixmapPixel(0x00, 0x00, 0x00, win
->pixmap
);
190 red_pixel
= GP_RGBToPixmapPixel(0xff, 0x00, 0x00, win
->pixmap
);
191 blue_pixel
= GP_RGBToPixmapPixel(0x00, 0x00, 0xff, win
->pixmap
);
192 green_pixel
= GP_RGBToPixmapPixel(0x00, 0xff, 0x00, win
->pixmap
);
193 yellow_pixel
= GP_RGBToPixmapPixel(0xff, 0xff, 0x00, win
->pixmap
);
194 white_pixel
= GP_RGBToPixmapPixel(0xff, 0xff, 0xff, win
->pixmap
);
195 darkgray_pixel
= GP_RGBToPixmapPixel(0x7f, 0x7f, 0x7f, win
->pixmap
);