X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgraphic.cpp;h=01bfcdb6a177db0fc16d8acf04498fcb4db47124;hb=a38c924ff32081f5cd67c2b0e2d5ca61f0e99de2;hp=611cdb4c790c4a4e16ff879260f72972cc37bacc;hpb=b23464cda4e4f2c7b69b18549f18c2c893c3fe2d;p=libs%2Fgltk.git diff --git a/source/graphic.cpp b/source/graphic.cpp index 611cdb4..01bfcdb 100644 --- a/source/graphic.cpp +++ b/source/graphic.cpp @@ -8,57 +8,72 @@ namespace Msp { namespace GLtk { Graphic::Graphic(): - texture(0) + texture(0), + repeat(false) { } void Graphic::render(unsigned wd, unsigned ht) const { - float x[4]; - float y[4]; - float u[4]; - float v[4]; - - x[0]=0.0f-shadow.left; - x[1]=x[0]+border.left; - x[3]=wd+shadow.right; - x[2]=x[3]-border.right; - - y[0]=0.0f-shadow.bottom; - y[1]=y[0]+border.bottom; - y[3]=ht+shadow.top; - y[2]=y[3]-border.top; - - const unsigned twidth=texture->get_width(); - u[0]=static_cast(slice.x)/twidth; - u[1]=static_cast(slice.x+border.left)/twidth; - u[2]=static_cast(slice.x+slice.w-border.right)/twidth; - u[3]=static_cast(slice.x+slice.w)/twidth; - - const unsigned theight=texture->get_height(); - v[0]=static_cast(slice.y)/theight; - v[1]=static_cast(slice.y+border.bottom)/theight; - v[2]=static_cast(slice.y+slice.h-border.top)/theight; - v[3]=static_cast(slice.y+slice.h)/theight; + GL::VertexArray varr((GL::TEXCOORD2, GL::VERTEX2)); + RefPtr vab=varr.modify(); + + vector x, y; + create_coords(0.0f-shadow.left, wd+shadow.right, border.left, border.right, slice.w-border.left-border.right, x); + create_coords(0.0f-shadow.bottom, ht+shadow.top, border.bottom, border.top, slice.h-border.bottom-border.top, y); + + vector u, v; + create_texcoords(slice.x, slice.x+slice.w, border.left, border.right, texture->get_width(), u); + create_texcoords(slice.y, slice.y+slice.h, border.bottom, border.top, texture->get_height(), v); - texture->bind(); unsigned xmin=border.left ? 0 : 1; - unsigned xmax=border.right ? 3 : 2; + unsigned xmax=x.size()-(border.right ? 2 : 3); unsigned ymin=border.bottom ? 0 : 1; - unsigned ymax=border.top ? 3 : 2; + unsigned ymax=y.size()-(border.top ? 2 : 3); + texture->bind(); GL::Immediate imm((GL::TEXCOORD2,GL::VERTEX2)); - for(unsigned i=ymin; i &coords) const +{ + coords.push_back(low); + coords.push_back(low+brd1); + if(repeat) + { + float space=high-low-brd1-brd2; + unsigned div=max(static_cast(space/block), 1U); + float delta=space/div; + for(unsigned i=1; i &coords) const +{ + coords.push_back(low/scale); + coords.push_back((low+brd1)/scale); + coords.push_back((high-brd2)/scale); + coords.push_back(high/scale); } @@ -69,6 +84,7 @@ Graphic::Loader::Loader(Graphic &g, Resources &r): add("texture", &Loader::texture); add("slice", &Loader::slice); add("border", &Loader::border); + add("repeat", &Graphic::repeat); add("shadow", &Loader::shadow); }