【问题标题】:How to set the start point of bar chart如何设置条形图的起点
【发布时间】:2017-02-19 09:21:15
【问题描述】:

我正在使用 SFML 库和 Visual-C++ 创建条形图。我想设置条形图的起点,所以我尝试使用 move 和 setOrigin 功能,但无法成功。

sf::RectangleShape rec1(sf::Vector2f(stage1x*1000, stage1y*1000));
sf::RectangleShape rec2(sf::Vector2f(stage2x*1000, stage2y*1000));
sf::RectangleShape rec3(sf::Vector2f(stage3x*1000, stage3y*1000));

rec1.setOrigin(0, 0);
rec2.setOrigin(0, 0);
rec3.setOrigin(0, 0);

rec1.move(200, 700); // This moves the Rectangle over 200 pixels and down 700 pixels
rec2.move(300, 700); // This moves the Rectangle over 300 pixels and down 700 pixels
rec3.move(400, 700); // This moves the Rectangle over 400 pixels and down 700 pixels

rec1.setFillColor(sf::Color(100, 250, 50));
rec2.setFillColor(sf::Color(10, 20, 100));
rec3.setFillColor(sf::Color(500, 600, 700));

【问题讨论】:

    标签: c++ visual-c++ bar-chart sfml


    【解决方案1】:

    为此有很多不同的方法。例如,您可以将窗口的 sf::View 的高度设置为负值,这实际上会垂直翻转所有内容(坐标从下到上运行)。

    SFML 的可绘制对象上的setOrigin() 只会移动它们的本地原点,即确定哪个点与setPosition()̀ 中给定的位置对齐。默认情况下,原点设置为(0, 0),因此您的代码不会更改任何内容。

    我不会使用move(),而是直接调用setPosition()(这是设置绝对位置而不是相对位置)。如果您希望条形图向上移动,请按上述方式翻转视图,或者简单地从它们的 Y 位置减去条形图的高度。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 2018-01-07
      • 2011-10-05
      • 1970-01-01
      • 2018-05-31
      • 2021-12-09
      相关资源
      最近更新 更多