Allegro学习笔记九

http://wiki.allegro.cc/AllegroExamples 以上是英文例子站点。

by Shawn Hargreaves,allegro的作者

目录: 1 Allegro 例子

1.1 exhello
1.2 exmem
1.3 expat
1.4 expal
1.5 exflame
1.6 exbuf
1.7 exflip
1.8 exfixed
1.9 exfont
这是一个非常简单的例子
演示了如何加载和巧妙的处理字体
(他真的很喜欢manipulate“巧妙的处理”这个词额-____-#)


#include <allegro.h>

int main(void)
{
FONT *f1, *f2, *f3, *f4, *f5;

/* you should always do this at the start of Allegro programs */
if (allegro_init() != 0)
return 1;

/* set up the keyboard handler */
install_keyboard();

/* set a graphics mode sized 320x200 */
if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) {
if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
return 1;
}
}

/* set the color palette */
set_palette(desktop_palette);

/* clear the screen to white */
clear_to_color(screen, makecol(255, 255, 255));

/* We will use the lower case letters from Allegro's normal font and the
* uppercase letters from the font in unifont.dat
*/
f1 = load_font("unifont.dat", NULL, NULL);
if (!f1) {
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message("Cannot find unifont.dat in current directory.\n");
return 1;
}

/* Extract character ranges */
f2 = extract_font_range(font, ' ', 'A'-1);
f3 = extract_font_range(f1, 'A', 'Z');
f4 = extract_font_range(font, 'Z'+1, 'z');

/* Merge fonts */
font = merge_fonts(f4, f5 = merge_fonts(f2, f3));

/* Destroy temporary fonts */
destroy_font(f1);
destroy_font(f2);
destroy_font(f3);
destroy_font(f4);
destroy_font(f5);

/* you don't need to do this, but on some platforms (eg. Windows) things
* will be drawn more quickly if you always acquire the screen before
* trying to draw onto it.
*/
acquire_screen();

/* write some text to the screen with black letters and transparent
* background
*/
textout_centre_ex(screen, font, "Hello, world!", SCREEN_W/2, SCREEN_H/2,
makecol(0,0,0), -1);

/* you must always release bitmaps before calling any input functions */
release_screen();

/* wait for a key press */
readkey();

return 0;
}

END_OF_MAIN()
----------------------------------------------------
小结九:
1、FONT *f1, *f2, *f3, *f4, *f5; // 创建字体对象
2、f2 = extract_font_range(font, ' ', 'A'-1);
f3 = extract_font_range(f1, 'A', 'Z');
f4 = extract_font_range(font, 'Z'+1, 'z');

FONT *extract_font_range(FONT *f, int begin, int end)
通过这个函数,可以从某个字体集合中“摘取”其中一部分,作为一个新的字体集合。你可以通过输入“-1”或者任何越界的值来选择全部的字体。
与之相关的还有get_font_range_begin, get_font_range_end, merge_fonts, transpose_font.等。

3、font = merge_fonts(f4, f5 = merge_fonts(f2, f3));
合并字体集合。font为默认调用的字体,即使你什么都不做,也可以直接调用font,就象前几个例子一样。
textout_centre_ex(screen, font, "Hello, world!", SCREEN_W/2, SCREEN_H/2,makecol(0,0,0), -1);

PS:事实上大部分的应用并不需要这么麻烦....

你可能感兴趣的:(windows,F#,UP)