调用 sf::矩形形状绘制函数
Calling sf::RectangleShapes draw function?
我有一组简单的类。其中之一是ButtonComponent
,我想基本上将sf::RectangleShape
用于视觉方面,然后ButtonComponent
的其余部分将处理诸如事件侦听器之类的事情。问题的形式是,如果我从父类中的sf::Drawable
继承,我必须实现draw()
(Component
类(,这意味着子类实现父类draw()
而不是SFML形状draw()
函数。有没有办法重组这两个类或调用sf::RectangleShapes
绘制函数的方法?
组件.h
class Component : public sf::Drawable {
public:
Component();
virtual ~Component();
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const = 0;
};
class ButtonComponent : public sf::RectangleShape, public Component {
virtual void draw(sf::RenderTarget& target, sf::RenderStates states);
};
解决方案是让子类仅继承sf::Drawable
,并在子类中具有sf::RectangleShape
。类似于下面的东西
class Component : public sf::Drawable {
public:
Component();
virtual ~Component();
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const = 0;
};
class ButtonComponent : public Component {
public:
ButtonComponent(const sf::Vector2f &size = sf::Vector2f(0, 0));
void draw(sf::RenderTarget& target, sf::RenderStates states) const;
void setSize(const sf::Vector2f& size);
const sf::Vector2f& getSize() const;
virtual unsigned int getPointCount() const;
virtual sf::Vector2f getPoint(unsigned int index) const;
void setTexture(const sf::Texture* texture, bool resetRect = false);
void setTextureRect(const sf::IntRect &rect);
void setFillColor(const sf::Color &color);
void setOutlineColor(const sf::Color &color);
void setOutlineThickness(float thickness);
const sf::Texture* getTexture() const;
const sf::IntRect& getTextureRext() const;
const sf::Color& getFillColor() const;
const sf::Color& getOutlineColor() const;
float getOutlineThickness() const;
sf::FloatRect getLocalBounds() const;
sf::FloatRect getGlobalBounds() const;
void setPosition(float x, float y);
void setPosition(const sf::Vector2f &position);
void setRotation(float angle);
void setScale(float factorX, float factorY);
void setScale(const sf::Vector2f& factors);
void setOrigin(float x, float y);
void setOrigin(const sf::Vector2f& origin);
const sf::Vector2f& getPosition() const;
float getRotation() const;
const sf::Vector2f& getScale() const;
const sf::Vector2f& getOrigin() const;
void move(float offsetX, float offsetY);
void move(const sf::Vector2f& offset);
void rotate(float angle);
void scale(float factorX, float factorY);
void scale(const sf::Vector2f& factor);
const sf::Transform& getTransform() const;
const sf::Transform& getInverseTransform() const;
private:
sf::RectangleShape _btnShape;
};
相关文章:
- 如何在Visual Basic中使用矩形函数OpenGL绘制矩形
- CGAL 绘制函数在 Visual Studio 中给出'CGAL_USE_BASIC_VIEWER is not defined'错误
- 使用 glDrawArray 函数绘制三角形
- C++ SFML 创建形状向量并在函数中绘制它们
- 如何在调用函数时将对象绘制到 sfml 窗口上
- 获取以矩形()函数绘制的矩形
- 调用 sf::矩形形状绘制函数
- 使用 c++ 中函数的执行时间绘制图形
- 如何调用OnEraseBkgnd()在另一个函数中重新绘制窗口?(MFC)
- c++ Glut 显示需要调用我的绘制函数,但我无法传递任何参数
- 变量指针的成员函数未绘制到SDL_Surface?
- 禁用 CListCtrl 自定义绘制函数中的行或将其显示为灰色
- 使用函数在 c++ 中绘制矩形
- 使用OpenCV教程中的任何一个进行人脸检测是否有任何函数可以计算绘制在人脸上的矩形的大小
- 如何在C程序中直接更改视频内存映射来绘制像素(无库函数)
- Qt-具有自定义参数的可重用绘制函数
- 摆脱在Qt QGlWidget中绘制实体对象的glut函数
- C++如何使用setpixel函数绘制色调曲线(gamma)到图形
- OpenGL:帮助使用gl函数绘制球体/圆
- 擦除通过extextout函数绘制的文本