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-2013 Cyril Hrubis <metan@ucw.cz> *
24 *****************************************************************************/
28 static GP_Pixel black_pixel
, red_pixel
, yellow_pixel
, green_pixel
, blue_pixel
,
31 static int font_flag
= 0;
36 static GP_FontFace
*font
= NULL
;
38 static GP_Backend
*win
;
40 void redraw_screen(void)
42 GP_Fill(win
->context
, black_pixel
);
44 /* draw axes intersecting in the middle, where text should be shown */
45 GP_HLine(win
->context
, 0, X
, Y
/2, darkgray_pixel
);
46 GP_VLine(win
->context
, X
/2, 0, Y
, darkgray_pixel
);
48 GP_TextStyle style
= GP_DEFAULT_TEXT_STYLE
;
52 style
.font
= &GP_DefaultProportionalFont
;
55 style
.font
= &GP_DefaultConsoleFont
;
62 GP_Text(win
->context
, &style
, X
/2, Y
/2, GP_ALIGN_LEFT
|GP_VALIGN_BELOW
,
63 yellow_pixel
, black_pixel
, "bottom left");
64 GP_Text(win
->context
, &style
, X
/2, Y
/2, GP_ALIGN_RIGHT
|GP_VALIGN_BELOW
,
65 red_pixel
, black_pixel
, "bottom right");
66 GP_Text(win
->context
, &style
, X
/2, Y
/2, GP_ALIGN_RIGHT
|GP_VALIGN_ABOVE
,
67 blue_pixel
, black_pixel
, "top right");
68 GP_Text(win
->context
, &style
, X
/2, Y
/2, GP_ALIGN_LEFT
|GP_VALIGN_ABOVE
,
69 green_pixel
, black_pixel
, "top left");
72 static void event_loop(void)
77 GP_BackendWaitEvent(win
, &ev
);
81 if (ev
.code
!= GP_EV_KEY_DOWN
)
84 switch (ev
.val
.key
.key
) {
86 win
->context
->x_swap
= !win
->context
->x_swap
;
89 win
->context
->y_swap
= !win
->context
->y_swap
;
92 win
->context
->axes_swap
= !win
->context
->axes_swap
;
127 void print_instructions(void)
129 printf("Use the following keys to control the test:\n");
130 printf(" Space ........ toggle proportional/nonproportional font\n");
131 printf(" X ............ mirror X\n");
132 printf(" Y ............ mirror Y\n");
133 printf(" R ............ reverse X and Y\n");
136 int main(int argc
, char *argv
[])
138 const char *backend_opts
= "X11";
141 font
= GP_FontFaceLoad(argv
[1], 0, 16);
143 print_instructions();
145 win
= GP_BackendInit(backend_opts
, "Font Align Test");
148 fprintf(stderr
, "Failed to initalize backend '%s'\n",
153 black_pixel
= GP_ColorToContextPixel(GP_COL_BLACK
, win
->context
);
154 red_pixel
= GP_ColorToContextPixel(GP_COL_RED
, win
->context
);
155 blue_pixel
= GP_ColorToContextPixel(GP_COL_BLUE
, win
->context
);
156 green_pixel
= GP_ColorToContextPixel(GP_COL_GREEN
, win
->context
);
157 yellow_pixel
= GP_ColorToContextPixel(GP_COL_YELLOW
, win
->context
);
158 darkgray_pixel
= GP_ColorToContextPixel(GP_COL_GRAY_DARK
, win
->context
);