fltk-1.3.5 小部件上的视觉工件

Visual artifact on fltk-1.3.5 widget

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

找到代码

我正在 windows 使用 fltk-1.3.5。

.

目前我有两种类型的组件用于创建 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());
}

要分解它,这个 class GameWindow 包含一个矢量,其中包含我想要绘制的所有形状。 class 覆盖了 Fl_Double_Window 的绘制方法。

第二种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() 方法,该方法从 window class 初始化 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))));

感谢任何有关工件可能情况的帮助、提示或指示。

我解决了

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

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);之后仍然可以改变添加到window的其他东西的线宽。所以为了解决这个问题,我通过添加

将线宽重置为 1
fl_line_style(FL_SOLID, 1); 

绘制函数结束时。