1
Général / Re : Vue et position de la souris
« le: Mai 24, 2015, 11:49:55 am »
Oui mais ca c'est la position de la souris dans la fenêtre, moi je veux dans ma vue.
Cette section vous permet de consulter les contributions (messages, sujets et fichiers joints) d'un utilisateur. Vous ne pourrez voir que les contributions des zones auxquelles vous avez accès.
sf::Vector2i posFen = sf::Mouse::getPosition(win);
sf::Vector2f pos = win.mapPixelToCoords(posFen, _itemsContainer.getView());
où _itemsContainer est une sf::RenderTexture._inBox.setSize(sf::Vector2f(COMBO_WIDTH, COMBO_HEIGHT));
par :_inBox.setSize(sf::Vector2f(COMBO_WIDTH, COMBO_HEIGHT * 10));
#ifndef __COMBO_HPP__
# define __COMBO_HPP__
# include <vector>
# include "Widget.hpp"
# include "ComboItem.hpp"
class Combo : public Widget
{
private:
sf::View _view;
sf::RectangleShape _inBox;
sf::RectangleShape _box;
sf::RenderTexture _itemsContainer;
std::vector<ComboItem *> _items;
public:
Combo(int win_width, int win_height);
Combo(int width, int height, int posX, int posY);
virtual void draw(sf::RenderWindow &win);
virtual bool collide(sf::Vector2i pos);
void addItem(ComboItem *item);
void up();
void down();
};
#endif
#include <iterator>
#include "CharteGraphique.hpp"
#include "Combo.hpp"
Combo::Combo(int win_width, int win_height)
{
_box.setSize(sf::Vector2f(COMBO_WIDTH, COMBO_HEIGHT));
_box.setPosition(win_width - MARGIN_RIGHT - COMBO_WIDTH,
COMBO_MARGIN_TOP);
_box.setFillColor(sf::Color::Transparent);
_box.setOutlineThickness(COMBO_BORDER);
_box.setOutlineColor(sf::Color(COMBO_BORDER_RED, COMBO_BORDER_GREEN,
COMBO_BORDER_BLUE));
_inBox.setSize(sf::Vector2f(COMBO_WIDTH, COMBO_HEIGHT));
_inBox.setPosition(0, 0);
_inBox.setFillColor(sf::Color(BG_RED, BG_GREEN, BG_BLUE));
_view.setSize(sf::Vector2f(COMBO_WIDTH, COMBO_HEIGHT));
_view.setCenter(sf::Vector2f(COMBO_WIDTH / 2, COMBO_HEIGHT / 2));
_itemsContainer.create(COMBO_WIDTH, COMBO_HEIGHT * 10);
_itemsContainer.setView(_view);
}
Combo::Combo(int height, int widht, int posX, int posY)
{
}
void Combo::draw(sf::RenderWindow &win)
{
win.draw(_box);
_itemsContainer.clear();
_itemsContainer.draw(_inBox);
for (std::vector<ComboItem *>::iterator it = _items.begin();
it != _items.end(); ++it)
(*it)->draw(_itemsContainer);
_itemsContainer.display();
sf::Sprite sp(_itemsContainer.getTexture());
sp.setPosition(_box.getPosition().x, _box.getPosition().y);
win.draw(sp);
}
bool Combo::collide(sf::Vector2i pos)
{
}
void Combo::addItem(ComboItem *item)
{
item->setPosition(COMBO_MARGIN_RIGHT + COMBO_BORDER,
_items.size() * (COMBO_ITEM_HEIGHT + COMBO_BTW_ITEM) +
COMBO_BTW_ITEM);
_items.push_back(item);
}
void Combo::up()
{
_view.move(0, -COMBO_SPEED);
_itemsContainer.setView(_view);
}
void Combo::down()
{
_view.move(0, COMBO_SPEED);
_itemsContainer.setView(_view);
}