viewButtonArea.cpp 2.75 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3 4
#include "viewButtonArea.h"

#include "schnapps.h"
#include "view.h"
5
//#include "texture.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
6 7
//#include "camera.h"

8 9
#include "Utils/Shaders/shaderWallPaper.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
10 11 12 13 14 15 16 17
#include <iostream>

namespace CGoGN
{

namespace SCHNApps
{

18

Pierre Kraemer's avatar
Pierre Kraemer committed
19 20 21 22
ViewButton::ViewButton(const QString& image, View* view) :
	m_img(image),
	m_view(view)
{
23 24 25 26 27 28 29
	m_texture = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE);

	if (!m_texture->load(m_img.toStdString()))
		std::cerr << "Problem loading icon "<< m_img.toStdString() << std::endl;

	m_texture->update();
	m_texture->setWrapping(GL_CLAMP_TO_EDGE);
Pierre Kraemer's avatar
Pierre Kraemer committed
30 31 32 33 34 35 36
}

ViewButton::~ViewButton()
{
	m_view->getSCHNApps()->releaseTexture(m_img);
}

37
void ViewButton::click(int x, int y, int globalX, int globalY)
Pierre Kraemer's avatar
Pierre Kraemer committed
38
{
39
	emit clicked(x, y, globalX, globalY);
Pierre Kraemer's avatar
Pierre Kraemer committed
40 41
}

42
void ViewButton::drawAt(int x, int y, Utils::ShaderWallPaper* shader)
Pierre Kraemer's avatar
Pierre Kraemer committed
43
{
44 45 46 47
	QSize szw = m_view->size();

	shader->drawFront(szw.width(),szw.height(),x,y,ViewButton::SIZE,ViewButton::SIZE, m_texture);

Pierre Kraemer's avatar
Pierre Kraemer committed
48 49
}

50 51 52
ViewButtonArea::ViewButtonArea(View* view) :
	m_view(view),
	m_form(0,0,0,0)
Pierre Kraemer's avatar
Pierre Kraemer committed
53
{
54 55 56
	m_shaderButton = new CGoGN::Utils::ShaderWallPaper();
	m_shaderButton->setTextureUnit(GL_TEXTURE0);

Pierre Kraemer's avatar
Pierre Kraemer committed
57 58
}

59 60 61 62
ViewButtonArea::~ViewButtonArea()
{
	delete m_shaderButton;
}
Pierre Kraemer's avatar
Pierre Kraemer committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112



void ViewButtonArea::addButton(ViewButton* button)
{
	if(!l_buttons.contains(button))
	{
		m_form.setWidth(m_form.width() + ViewButton::SIZE + ViewButton::SPACE);
		m_form.moveTopLeft(QPoint(m_form.x() - ViewButton::SIZE - ViewButton::SPACE, m_form.y()));
		m_form.setHeight(ViewButton::SIZE + 2 * ViewButton::SPACE);

		l_buttons.push_back(button);
	}
}

void ViewButtonArea::removeButton(ViewButton* button)
{
	if(l_buttons.removeOne(button))
	{
		m_form.setWidth(m_form.width() - ViewButton::SIZE - ViewButton::SPACE);
		m_form.moveTopLeft(QPoint(m_form.x() + ViewButton::SIZE + ViewButton::SPACE, m_form.y()));
		m_form.setHeight(ViewButton::SIZE + 2 * ViewButton::SPACE);
	}
}

bool ViewButtonArea::isClicked(int x, int y)
{
	return m_form.contains(x, y);
}

void ViewButtonArea::clickButton(int x, int y, int globalX, int globalY)
{
	QPoint p = m_form.topLeft();
	p.setY(p.y() + ViewButton::SPACE);
	foreach(ViewButton* b, l_buttons)
	{
		if(QRect(p, QSize(ViewButton::SIZE, ViewButton::SIZE)).contains(x, y))
		{
			b->click(x, y, globalX, globalY);
			return;
		}
		p.setX(p.x() + ViewButton::SPACE + ViewButton::SIZE);
	}
}

void ViewButtonArea::setTopRightPosition(int x, int y)
{
	m_form.moveTopRight(QPoint(x,y));
}

Sylvain Thery's avatar
Sylvain Thery committed
113 114 115 116 117
void ViewButtonArea::setTopLeftPosition(int x, int y)
{
	m_form.moveTopLeft(QPoint(x+ViewButton::SPACE,y));
}

Pierre Kraemer's avatar
Pierre Kraemer committed
118 119 120 121 122 123 124
void ViewButtonArea::draw()
{
	int p_x = m_form.x();
	int p_y = m_form.y();

	foreach(ViewButton* b, l_buttons)
	{
125
		b->drawAt(p_x, p_y + ViewButton::SPACE, m_shaderButton);
Pierre Kraemer's avatar
Pierre Kraemer committed
126 127 128 129 130 131 132
		p_x += ViewButton::SIZE + ViewButton::SPACE;
	}
}

} // namespace SCHNApps

} // namespace CGoGN