added gui::ImageView element.

This commit is contained in:
rachytski 2013-01-24 18:52:10 +03:00 committed by Alex Zolotarev
parent 8650c6cd81
commit f6c85b65f4
3 changed files with 134 additions and 0 deletions

View file

@ -14,9 +14,11 @@ HEADERS += \
element.hpp \
button.hpp \
text_view.hpp \
image_view.hpp \
SOURCES += \
controller.cpp \
element.cpp \
button.cpp \
text_view.cpp \
image_view.cpp \

87
gui/image_view.cpp Normal file
View file

@ -0,0 +1,87 @@
#include "image_view.hpp"
#include "controller.hpp"
#include "../graphics/screen.hpp"
#include "../graphics/display_list.hpp"
#include "../base/matrix.hpp"
#include "../geometry/transformations.hpp"
namespace gui
{
ImageView::Params::Params()
{}
ImageView::ImageView(Params const & p)
: base_t(p),
m_boundRects(1)
{
m_image = p.m_image;
}
void ImageView::cache()
{
graphics::Screen * cs = m_controller->GetCacheScreen();
m_displayList.reset();
m_displayList.reset(cs->createDisplayList());
cs->beginFrame();
cs->setDisplayList(m_displayList.get());
math::Matrix<double, 3, 3> m =
math::Shift(
math::Identity<double, 3>(),
-(int)m_image.m_size.x / 2, -(int)m_image.m_size.y / 2);
uint32_t imageResID = cs->mapInfo(m_image);
cs->drawImage(m, imageResID, depth());
cs->setDisplayList(0);
cs->endFrame();
}
void ImageView::purge()
{
m_displayList.reset();
}
vector<m2::AnyRectD> const & ImageView::boundRects() const
{
if (isDirtyRect())
{
m2::PointD sz(m_image.m_size);
m2::PointD pt = computeTopLeft(sz,
pivot(),
position());
m_boundRects[0] = m2::AnyRectD(m2::RectD(pt, pt + sz));
setIsDirtyRect(false);
}
return m_boundRects;
}
void ImageView::draw(graphics::OverlayRenderer * r,
math::Matrix<double, 3, 3> const & m) const
{
if (isVisible())
{
checkDirtyLayout();
m2::PointD pt = computeTopLeft(m_image.m_size,
pivot() * m,
position());
math::Matrix<double, 3, 3> drawM = math::Shift(math::Identity<double, 3>(),
pt.x + m_image.m_size.x / 2,
pt.y + m_image.m_size.y / 2);
r->drawDisplayList(m_displayList.get(), drawM * m);
}
}
}

45
gui/image_view.hpp Normal file
View file

@ -0,0 +1,45 @@
#pragma once
#include "element.hpp"
#include "../graphics/image.hpp"
#include "../std/shared_ptr.hpp"
namespace graphics
{
class DisplayList;
class OverlayRenderer;
}
namespace gui
{
class ImageView : public Element
{
private:
mutable vector<m2::AnyRectD> m_boundRects;
graphics::Image::Info m_image;
m2::RectU m_margin;
shared_ptr<graphics::DisplayList> m_displayList;
public:
void cache();
void purge();
typedef Element base_t;
struct Params : public base_t::Params
{
graphics::Image::Info m_image;
Params();
};
ImageView(Params const & p);
vector<m2::AnyRectD> const & boundRects() const;
void draw(graphics::OverlayRenderer * r, math::Matrix<double, 3, 3> const & m) const;
};
}