11 Graphic::Graphic(const Resources &r, const string &n):
17 void Graphic::render(unsigned wd, unsigned ht) const
24 x[0]=0.0f-shadow.left;
25 x[1]=x[0]+border.left;
27 x[2]=x[3]-border.right;
29 y[0]=0.0f-shadow.bottom;
30 y[1]=y[0]+border.bottom;
34 const unsigned twidth=texture->get_width();
35 u[0]=static_cast<float>(slice.x)/twidth;
36 u[1]=static_cast<float>(slice.x+border.left)/twidth;
37 u[2]=static_cast<float>(slice.x+slice.w-border.right)/twidth;
38 u[3]=static_cast<float>(slice.x+slice.w)/twidth;
40 const unsigned theight=texture->get_height();
41 v[0]=static_cast<float>(slice.y)/theight;
42 v[1]=static_cast<float>(slice.y+border.bottom)/theight;
43 v[2]=static_cast<float>(slice.y+slice.h-border.top)/theight;
44 v[3]=static_cast<float>(slice.y+slice.h)/theight;
47 unsigned xmin=border.left ? 0 : 1;
48 unsigned xmax=border.right ? 3 : 2;
49 unsigned ymin=border.bottom ? 0 : 1;
50 unsigned ymax=border.top ? 3 : 2;
52 for(unsigned i=ymin; i<ymax; ++i)
54 glBegin(GL_QUAD_STRIP);
55 for(unsigned j=xmin; j<=xmax; ++j)
57 glTexCoord2f(u[j], v[i]);
58 glVertex2f(x[j], y[i]);
59 glTexCoord2f(u[j], v[i+1]);
60 glVertex2f(x[j], y[i+1]);
67 Graphic::Loader::Loader(Graphic &g):
70 add("texture", &Loader::texture);
71 add("slice", &Loader::slice);
72 add("border", &Loader::border);
73 add("shadow", &Loader::shadow);
76 void Graphic::Loader::texture(const string &n)
78 graph.texture=&graph.res.get_texture(n);
79 graph.slice=Geometry(0, 0, graph.texture->get_width(), graph.texture->get_height());
82 void Graphic::Loader::slice(unsigned x, unsigned y, unsigned w, unsigned h)
84 graph.slice=Geometry(x, y, w, h);
87 void Graphic::Loader::border()
89 load_sub(graph.border);
92 void Graphic::Loader::shadow()
94 load_sub(graph.shadow);