]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/graphic.cpp
Add various constructors to Sides (semantics inspired by CSS margins)
[libs/gltk.git] / source / graphic.cpp
index 0c874c8d1c0dd785e4bfe024822a35139c1fa801..db2afa2cfa0340018b2424cc18865a2ae5a51b85 100644 (file)
@@ -21,9 +21,6 @@ Graphic::Graphic():
 
 void Graphic::render(unsigned wd, unsigned ht) const
 {
-       GL::VertexArray varr((GL::TEXCOORD2, GL::VERTEX2));
-       RefPtr<GL::VertexArrayBuilder> vab=varr.modify();
-
        vector<float> 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);
@@ -32,20 +29,21 @@ void Graphic::render(unsigned wd, unsigned ht) const
        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);
 
-       unsigned xmin=border.left ? 0 : 1;
-       unsigned xmax=x.size()-(border.right ? 2 : 3);
-       unsigned ymin=border.bottom ? 0 : 1;
-       unsigned ymax=y.size()-(border.top ? 2 : 3);
+       unsigned xmin = border.left ? 0 : 1;
+       unsigned xmax = x.size()-(border.right ? 2 : 3);
+       unsigned ymin = border.bottom ? 0 : 1;
+       unsigned ymax = y.size()-(border.top ? 2 : 3);
 
        texture->bind();
-       GL::Immediate imm((GL::TEXCOORD2,GL::VERTEX2));
+       GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
+       imm.color(1.0f, 1.0f, 1.0f);
        imm.begin(GL::QUADS);
        for(unsigned i=ymin; i<=ymax; ++i)
        {
-               unsigned i2=(i==0 ? 0 : i==y.size()-2 ? 2 : 1);
+               unsigned i2 = (i==0 ? 0 : i==y.size()-2 ? 2 : 1);
                for(unsigned j=xmin; j<=xmax; ++j)
                {
-                       unsigned j2=(j==0 ? 0 : j==x.size()-2 ? 2 : 1);
+                       unsigned j2 = (j==0 ? 0 : j==x.size()-2 ? 2 : 1);
                        imm.texcoord(u[j2], v[i2]);
                        imm.vertex(x[j], y[i]);
                        imm.texcoord(u[j2+1], v[i2]);
@@ -65,9 +63,9 @@ void Graphic::create_coords(float low, float high, float brd1, float brd2, float
        coords.push_back(low+brd1);
        if(repeat)
        {
-               float space=high-low-brd1-brd2;
-               unsigned div=max(static_cast<unsigned>(space/block), 1U);
-               float delta=space/div;
+               float space = high-low-brd1-brd2;
+               unsigned div = max(static_cast<unsigned>(space/block), 1U);
+               float delta = space/div;
                for(unsigned i=1; i<div; ++i)
                        coords.push_back(low+brd1+delta*i);
        }
@@ -97,13 +95,13 @@ Graphic::Loader::Loader(Graphic &g, Resources &r):
 
 void Graphic::Loader::texture(const string &n)
 {
-       graph.texture=res.get<GL::Texture2D>(n);
-       graph.slice=Geometry(0, 0, graph.texture->get_width(), graph.texture->get_height());
+       graph.texture = res.get<GL::Texture2D>(n);
+       graph.slice = Geometry(0, 0, graph.texture->get_width(), graph.texture->get_height());
 }
 
 void Graphic::Loader::slice(unsigned x, unsigned y, unsigned w, unsigned h)
 {
-       graph.slice=Geometry(x, y, w, h);
+       graph.slice = Geometry(x, y, w, h);
 }
 
 void Graphic::Loader::border()