14 void Graphic::build(unsigned wd, unsigned ht, GL::PrimitiveBuilder &bld) const
17 create_coords(0.0f-shadow.left, wd+shadow.right, border.left, border.right, slice.w-border.left-border.right, x);
18 create_coords(0.0f-shadow.bottom, ht+shadow.top, border.bottom, border.top, slice.h-border.bottom-border.top, y);
21 create_texcoords(slice.x, slice.x+slice.w, border.left, border.right, texture->get_width(), u);
22 create_texcoords(slice.y, slice.y+slice.h, border.bottom, border.top, texture->get_height(), v);
24 unsigned xmin = border.left ? 0 : 1;
25 unsigned xmax = x.size()-(border.right ? 2 : 3);
26 unsigned ymin = border.bottom ? 0 : 1;
27 unsigned ymax = y.size()-(border.top ? 2 : 3);
29 bld.color(1.0f, 1.0f, 1.0f);
31 for(unsigned i=ymin; i<=ymax; ++i)
33 unsigned i2 = (i==0 ? 0 : i==y.size()-2 ? 2 : 1);
34 for(unsigned j=xmin; j<=xmax; ++j)
36 unsigned j2 = (j==0 ? 0 : j==x.size()-2 ? 2 : 1);
37 bld.texcoord(u[j2], v[i2]);
38 bld.vertex(x[j], y[i]);
39 bld.texcoord(u[j2+1], v[i2]);
40 bld.vertex(x[j+1], y[i]);
41 bld.texcoord(u[j2+1], v[i2+1]);
42 bld.vertex(x[j+1], y[i+1]);
43 bld.texcoord(u[j2], v[i2+1]);
44 bld.vertex(x[j], y[i+1]);
50 void Graphic::create_coords(float low, float high, float brd1, float brd2, float block, vector<float> &coords) const
52 coords.push_back(low);
53 coords.push_back(low+brd1);
56 float space = high-low-brd1-brd2;
57 unsigned div = max(static_cast<unsigned>(space/block), 1U);
58 float delta = space/div;
59 for(unsigned i=1; i<div; ++i)
60 coords.push_back(low+brd1+delta*i);
62 coords.push_back(high-brd2);
63 coords.push_back(high);
66 void Graphic::create_texcoords(float low, float high, float brd1, float brd2, float scale, vector<float> &coords) const
68 coords.push_back(low/scale);
69 coords.push_back((low+brd1)/scale);
70 coords.push_back((high-brd2)/scale);
71 coords.push_back(high/scale);
75 Graphic::Loader::Loader(Graphic &g, Resources &r):
79 add("texture", &Loader::texture);
80 add("slice", &Loader::slice);
81 add("border", &Loader::border);
82 add("repeat", &Graphic::repeat);
83 add("shadow", &Loader::shadow);
86 void Graphic::Loader::texture(const string &n)
88 graph.texture = &res.get<GL::Texture2D>(n);
89 graph.slice = Geometry(0, 0, graph.texture->get_width(), graph.texture->get_height());
92 void Graphic::Loader::slice(unsigned x, unsigned y, unsigned w, unsigned h)
94 graph.slice = Geometry(x, y, w, h);
97 void Graphic::Loader::border()
99 load_sub(graph.border);
102 void Graphic::Loader::shadow()
104 load_sub(graph.shadow);