arrayfire / forge

High Performance Visualization
224 stars 48 forks source link

Add qt5 widget ChartWidget #136

Closed caseymcc closed 6 years ago

caseymcc commented 7 years ago

This adds a qt5 widget ChartWidget (and example) to the API that can be enabled by adding USE_QT5_WIDGET=ON to the cmake build. Also added the ability to set the USE_WINDOW_TOOLKIT to "none" removing window creation support.

This is not quite ready needs clean up and testing across platforms, put it here for the moment to get feedback.

caseymcc commented 7 years ago

This is ready as far as windows is concerned (haven't tested on other OSes yet and not sure when I can).

The only real meddling I did outside of adding the class is I had to modify how the font local static variable was used. I modified it to use a static weak_ptr rather than a static object and made the chart keep a shared reference to it. I did this because the static object is not destroyed until most of the program is already closing and (at least with the thread testing) the opengl context had already been closed and the deconstructor is calling opengl functions.

This allows one font object to be used when multiple charts are in use, but makes sure it is destroyed when the last chart is.

const std::shared_ptr<forge::opengl::font_impl> getChartFont()
{
    static std::weak_ptr<forge::opengl::font_impl> chartFont;
    std::shared_ptr<forge::opengl::font_impl> font=chartFont.lock();

    if(!font)
    {
        forge::common::Font gChartFont;
#if defined(OS_WIN)
        gChartFont.loadSystemFont("Calibri");
#else
        gChartFont.loadSystemFont("Vera");
#endif
        font=gChartFont.impl();
        chartFont=font;
    }
    return font;
}
9prady9 commented 6 years ago

@caseymcc If you don't mind, can you please rebase from master after #150 is merged and push your additions. Thank you.

9prady9 commented 6 years ago

@caseymcc A lot has changed in the current master w.r.t CMake. Can you please rebase from master and test your changes on Linux/OSX. I shall close the PR for now. Feel free to reopen it when you have the changes ready. Thank you!