ウィンドウ上での画像の拡大縮小
Reputeless 2016/04/06(Wed) 23:07
サンプルです
# include <Siv3D.hpp>
class Item
{
private:
RectF m_rect = { 0,0 };
int32 m_boxSize = 0;
Optional<int32> m_select;
RectF tl() const
{
return RectF(m_boxSize).setCenter(m_rect.tl);
}
RectF tr() const
{
return RectF(m_boxSize).setCenter(m_rect.tr);
}
RectF bl() const
{
return RectF(m_boxSize).setCenter(m_rect.bl);
}
RectF br() const
{
return RectF(m_boxSize).setCenter(m_rect.br);
}
public:
Item() = default;
explicit Item(const RectF& rect, int32 boxSize = 12)
: m_rect(rect)
, m_boxSize(boxSize) {}
void update()
{
if (Input::MouseL.released)
{
m_select.reset();
}
if (m_select)
{
const Point delta = Mouse::Delta();
switch (m_select.value())
{
case 0:
m_rect.pos += delta;
m_rect.size -= delta;
break;
case 1:
m_rect.w += delta.x;
m_rect.y += delta.y;
m_rect.h -= delta.y;
break;
case 2:
m_rect.x += delta.x;
m_rect.w -= delta.x;
m_rect.h += delta.y;
break;
case 3:
m_rect.size += delta;
break;
case 4:
m_rect.moveBy(delta);
break;
}
}
else
{
if (tl().leftClicked)
{
m_select = 0;
}
else if (tr().leftClicked)
{
m_select = 1;
}
else if (bl().leftClicked)
{
m_select = 2;
}
else if (br().leftClicked)
{
m_select = 3;
}
else if (m_rect.leftClicked)
{
m_select = 4;
}
}
}
void draw(const Texture& texutre) const
{
m_rect(texutre).draw();
if (!tl().mouseOver && !tr().mouseOver && !bl().mouseOver && !br().mouseOver && m_rect.mouseOver)
{
m_rect.drawFrame(2, 2, Color(255, 128));
}
tl().draw(tl().mouseOver ? Palette::Yellow : Palette::White).drawFrame(1, 0, Palette::Black);
tr().draw(tr().mouseOver ? Palette::Yellow : Palette::White).drawFrame(1, 0, Palette::Black);
bl().draw(bl().mouseOver ? Palette::Yellow : Palette::White).drawFrame(1, 0, Palette::Black);
br().draw(br().mouseOver ? Palette::Yellow : Palette::White).drawFrame(1, 0, Palette::Black);
}
};
void Main()
{
const Texture texture(L"Example/Windmill.png", TextureDesc::Mipped);
Item item(Rect(100, 60, texture.size));
while (System::Update())
{
item.update();
item.draw(texture);
}
}