简体   繁体   中英

Visual artifact on fltk-1.3.5 widget

I'm currently working on a tic tac toe game and I cannot figure out how to remove the visual artifact (enlarged arrow in the Fl_Choice/Dropdown) that you can see in the image. You can find the code at https://github.com/FG-33/TicTacToeML .

I'm working on windows using fltk-1.3.5.

1] .

Currently I have two types of components which I'm using to create the GUI. The first one being a shape that is drawn using fltk's draw methods:

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());
}

To break it down there is this class GameWindow that contains a vector which holds all the shapes I want to draw. The class overrides Fl_Double_Window 's draw method.

The second type of GUI components are the actual ones given by 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
}

To create the widgets I'm calling the attach() methods which initializes the fltk widgets from the window class. To remove the widgets and shapes I call the vector's clear() -methode.

What I'm doing and when the artifact occurs:

// 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))));

Any help, tips or pointers on what might be the case of the artifact are appreciated.

I solved it.

How I draw different kinds of shapes:

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());
}

The proplem is that fl_line_style(FL_SOLID, line_width); can still change the line width of other things added to the window afterwards. So in order to solve this I did reset the line width to 1 by adding

fl_line_style(FL_SOLID, 1); 

at the end of the draw function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM