This repository has been archived by the owner on Nov 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_font_async.js
110 lines (86 loc) · 3.23 KB
/
test_font_async.js
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
var nge2 = require('./build/Release/node_nge2');
var app = new nge2.NgeApp();
var quit;
var bg, text_img, maskbox
, box, icon = [];
function MAKE_RGBA_4444(r,g,b,a) {
return nge2.CreateColor(r,g,b,a, nge2.DISPLAY_PIXEL_FORMAT_4444);
}
function MAKE_RGBA_8888(r,g,b,a) {
return nge2.CreateColor(r,g,b,a, nge2.DISPLAY_PIXEL_FORMAT_8888);
}
function MAKE_RGB(r,g,b) {
return nge2.CreateColor(r,g,b,255, nge2.DISPLAY_PIXEL_FORMAT_8888);
}
app.init = function(end){
nge2.Init(nge2.INIT_VIDEO);
nge2.InitInput(function(key) {
if (key == nge2.PSP_BUTTON_UP)
quit = true;
},
function(key) {
console.log(key);
}, 0);
nge2.SetFontEncoding(nge2.NGE_ENCODING_UTF_8);
nge2.SetScreenColor(255,255,255,255);
bg = nge2.image_load("res/images/demo2_bg.jpg", nge2.DISPLAY_PIXEL_FORMAT_8888, 1);
if (!bg)
console.log("can not find demo2_bg.jpg!");
box = nge2.image_load("res/images/demo2_box.jpg",nge2.DISPLAY_PIXEL_FORMAT_8888,1);
if (!box)
console.log("can not find demo2_box.jpg!");
maskbox = MAKE_RGBA_8888(255,255,255,128);
icon[0] = nge2.image_load_colorkey("res/images/demo2_icon1.png",nge2.DISPLAY_PIXEL_FORMAT_8888,MAKE_RGB(0,0,0),1);
icon[1] = nge2.image_load_colorkey("res/images/demo2_icon0.bmp",nge2.DISPLAY_PIXEL_FORMAT_8888,MAKE_RGB(0,0,0),1);
text_img = nge2.image_create(512, 512, nge2.DISPLAY_PIXEL_FORMAT_4444);
var pf = [];
var str1 = ["【报幕员】","下面播放的是由雪莉演唱的射手座。","欢迎大家收听!"]
, str2 = ["【雪莉粉丝】","哇哇哇。。。太棒了!","XXXX女王SAMA,我爱你。"]
, buf;
nge2.create_font_hzk_async("res/fonts/GBK14", "res/fonts/ASC14", 14, nge2.DISPLAY_PIXEL_FORMAT_4444, function(err, font) {
pf[0] = font;
nge2.create_font_freetype_async("res/fonts/simfang.ttf", 13, nge2.DISPLAY_PIXEL_FORMAT_4444, function(err, font) {
pf[1] = font;
nge2.font_setcolor(pf[0], MAKE_RGBA_4444(128,0,0,255));
nge2.font_drawtext(pf[0], str2[0],text_img,100,195,nge2.FONT_SHOW_NORMAL);
nge2.font_setcolor(pf[0], MAKE_RGBA_4444(255,0,0,255));
for (var i = 1; i<3; i++) {
nge2.font_drawtext(pf[0],str2[i],text_img,120,200+i*20,nge2.FONT_SHOW_SHADOW);
}
nge2.font_setcolor(pf[1],MAKE_RGBA_4444(128,0,0,255));
nge2.font_drawtext(pf[1],str1[0],text_img,100,30,nge2.FONT_SHOW_NORMAL);
nge2.font_setcolor(pf[1],MAKE_RGBA_4444(255,0,0,255));
for(var i =1;i<3;i++){
nge2.font_drawtext(pf[1],str1[i],text_img,120,35+i*20,nge2.FONT_SHOW_NORMAL);
}
end();
});
});
}
app.mainloop = function(end){
try {
nge2.InputProc();
nge2.BeginScene(1);
nge2.ImageToScreen(bg,0,0);
nge2.RenderQuad(box,0,0,0,0,70,185,1,1,0,maskbox);
nge2.RenderQuad(box,0,0,0,0,70,5,1,1,0,maskbox);
nge2.DrawImage(icon[0],0,0,0,0,-20,-37,128,128);
nge2.DrawImage(icon[1],0,0,0,0,-20,143,128,128);
nge2.ImageToScreen(text_img,0,0);
nge2.EndScene();
}
catch (err) {
console.log("err : " + err);
end(nge2.NGE_APP_QUIT);
return;
}
if (quit)
end(nge2.NGE_APP_QUIT);
else
end(nge2.NGE_APP_NORMAL);
}
app.fini = function(end){
nge2.Quit();
end();
}
app.startRun();