【问题标题】:Visual artifact on fltk-1.3.5 widgetfltk-1.3.5 小部件上的视觉工件
【发布时间】:2019-05-19 21:30:39
【问题描述】:

我目前正在开发一款井字游戏,但我不知道如何移除您在图像中看到的视觉伪影(Fl_Choice/Dropdown 中的放大箭头)。你可以在https://github.com/FG-33/TicTacToeML找到代码。

我正在使用 fltk-1.3.5 在 Windows 上工作。

.

目前我有两种用于创建 GUI 的组件。第一个是使用 fltk 的绘制方法绘制的形状:

class GameWindow : Fl_Double_Window { 
    std::vector<std::shared_ptr<IShape>> shapes;
    void draw() override;

..

void GameWindow::draw() {
    Fl_Double_Window::draw();
    for(int i=0;i<shapes.size();i++)
        shapes[i]->draw();
}

void Line::draw() const { // An example for an IShape
    fl_color(FL_FOREGROUND_COLOR);
    fl_line_style(FL_SOLID, line_width); // has to be after color on win32
    fl_line(lineStart.x(), lineStart.y(), lineEnd.x(), lineEnd.y());
}

要分解它,有一个 GameWindow 类,它包含一个包含我想要绘制的所有形状的向量。该类覆盖Fl_Double_Window 的draw 方法。

第二种GUI组件是fltk给出的实际组件:

class ConfigDialog : public IWidget {
    std::shared_ptr<Fl_Box> box;
    void attach() override;

..

void ConfigDialog::attach() {
    box = std::make_shared<Fl_Box>(FL_SHADOW_BOX, topLeft.x(), topLeft.y(), width, height, ""); 
}

void GameWindow::attach(std::shared_ptr<IWidget> w) {
        begin();
        w->attach();
        end();
        widgets.push_back(w); // there's also a vector for widgets
}

为了创建小部件,我调用了 attach() 方法,该方法从窗口类初始化 fltk 小部件。要删除小部件和形状,我调用矢量的clear()-方法。

我在做什么以及工件何时发生:

// start the game in main

// Create dialog in the image // THE ERROR DOES NOT OCCUR HERE
view.attach(move(make_shared<ConfigDialog>(ConfigDialog(Point(width/6, height/3), width*2/3, height/3+height/40, this))));

// Remove the dialog if game is started
widgets.clear()

// add some shapes and draw them like this
fl_color(FL_FOREGROUND_COLOR);
fl_line_style(FL_SOLID, line_width); // has to be after color on win32
fl_line(lineStart.x(), lineStart.y(), lineEnd.x(), lineEnd.y());

// remove the shapes if game is finished
shapes.clear()

// add config dialog in the image again // NOW THE ERROR OCCURS
view.attach(move(make_shared<ConfigDialog>(ConfigDialog(Point(width/6, height/3), width*2/3, height/3+height/40, this))));

感谢您就工件可能出现的情况提供任何帮助、提示或指示。

【问题讨论】:

  • 我仍然不清楚你到底在称这个神器是什么。唯一奇怪的是用于列表框下拉菜单的超大向下箭头。这就是你在说的吗?如果是这样,这似乎更像是一个规模问题,而不是人工制品。
  • @DavidC.Rankin 感谢您的建议,我确实编辑了问题。你可能是对的。在添加对话框之前,我正在绘制多条线宽 ~6 的线条,这可能会影响对话框/箭头的绘制。
  • @DavidC.Rankin 我尝试在 linux 上运行该项目,那里发生了更多事情。因此,我确信由于我在添加对话框之前绘制的组件的线宽较粗,所以肯定会出现伪像。

标签: c++ fltk


【解决方案1】:

我解决了。

我如何绘制不同类型的形状:

void Line::draw() const {
    fl_color(FL_FOREGROUND_COLOR);
    fl_line_style(FL_SOLID, line_width); // has to be after color on win32
    fl_line(lineStart.x(), lineStart.y(), lineEnd.x(), lineEnd.y());
}

问题是fl_line_style(FL_SOLID, line_width);之后仍然可以改变添加到窗口的其他东西的线宽。所以为了解决这个问题,我确实通过添加将线宽重置为 1

fl_line_style(FL_SOLID, 1); 

在绘图函数结束时。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-07
    • 1970-01-01
    • 2017-08-30
    相关资源
    最近更新 更多