X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fimage.cpp;h=f1180c39e1664491fd239560d59f251b8194074a;hb=b3234ca0277c5e282a2a0a2558b58edb25750653;hp=bff790427657ae3256596220d68bfd81c657d079;hpb=2b70e8801c43875ed3f4135bdd0141265cff0312;p=libs%2Fgltk.git diff --git a/source/image.cpp b/source/image.cpp index bff7904..f1180c3 100644 --- a/source/image.cpp +++ b/source/image.cpp @@ -1,6 +1,4 @@ -#include -#include -#include +#include #include "image.h" #include "part.h" #include "style.h" @@ -17,25 +15,20 @@ Image::Image(const GL::Texture2D *i): focusable = false; } -void Image::autosize() +void Image::autosize_special(const Part &part, Geometry &ageom) const { - if(!style) - return; - - Widget::autosize(); - - if(const Part *image_part = style->get_part("image")) + if(part.get_name()=="image") { - const Sides &margin = image_part->get_margin(); + const Sides &margin = part.get_margin(); if(image) { - geom.w = max(geom.w, image->get_width()+margin.left+margin.right); - geom.h = max(geom.h, image->get_height()+margin.top+margin.bottom); + ageom.w = max(ageom.w, image->get_width()+margin.left+margin.right); + ageom.h = max(ageom.h, image->get_height()+margin.top+margin.bottom); } else { - geom.w = max(geom.w, margin.left+margin.right); - geom.h = max(geom.h, margin.top+margin.bottom); + ageom.w = max(ageom.w, margin.left+margin.right); + ageom.h = max(ageom.h, margin.top+margin.bottom); } } } @@ -44,14 +37,16 @@ void Image::set_image(const GL::Texture2D *i) { image = i; signal_autosize_changed.emit(); + rebuild(); } void Image::set_keep_aspect(bool ka) { keep_aspect = ka; + rebuild(); } -void Image::render_special(const Part &part) const +void Image::rebuild_special(const Part &part) { if(part.get_name()=="image") { @@ -79,19 +74,18 @@ void Image::render_special(const Part &part) const } } - GL::Bind _bind_tex(image); - GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2)); - imm.color(1.0f, 1.0f, 1.0f); - imm.begin(GL::QUADS); - imm.texcoord(0.0, 0.0); - imm.vertex(rgeom.x, rgeom.y); - imm.texcoord(1.0, 0.0); - imm.vertex(rgeom.x+rgeom.w, rgeom.y); - imm.texcoord(1.0, 1.0); - imm.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h); - imm.texcoord(0.0, 1.0); - imm.vertex(rgeom.x, rgeom.y+rgeom.h); - imm.end(); + GL::MeshBuilder bld(part_cache.create_mesh(part, *image)); + bld.color(1.0f, 1.0f, 1.0f); + bld.begin(GL::TRIANGLE_STRIP); + bld.texcoord(0.0, 1.0); + bld.vertex(rgeom.x, rgeom.y+rgeom.h); + bld.texcoord(0.0, 0.0); + bld.vertex(rgeom.x, rgeom.y); + bld.texcoord(1.0, 1.0); + bld.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h); + bld.texcoord(1.0, 0.0); + bld.vertex(rgeom.x+rgeom.w, rgeom.y); + bld.end(); } }