Mercurial > hg > orthanc-stone
comparison Applications/Sdl/BasicSdlApplication.cpp @ 276:5de5699ad570 am-2
first display in QCairoWidget; no mouse interaction yet
author | am@osimis.io |
---|---|
date | Mon, 27 Aug 2018 12:21:52 +0200 |
parents | dc1beee33134 |
children | 8f5d7495076d |
comparison
equal
deleted
inserted
replaced
275:58e23e0dd86a | 276:5de5699ad570 |
---|---|
42 SdlWindow::GlobalInitialize(); | 42 SdlWindow::GlobalInitialize(); |
43 } | 43 } |
44 | 44 |
45 void BasicSdlApplication::DeclareCommandLineOptions(boost::program_options::options_description& options) | 45 void BasicSdlApplication::DeclareCommandLineOptions(boost::program_options::options_description& options) |
46 { | 46 { |
47 // Declare the supported parameters | |
48 boost::program_options::options_description generic("Generic options"); | |
49 generic.add_options() | |
50 ("help", "Display this help and exit") | |
51 ("verbose", "Be verbose in logs") | |
52 ("orthanc", boost::program_options::value<std::string>()->default_value("http://localhost:8042/"), | |
53 "URL to the Orthanc server") | |
54 ("username", "Username for the Orthanc server") | |
55 ("password", "Password for the Orthanc server") | |
56 ("https-verify", boost::program_options::value<bool>()->default_value(true), "Check HTTPS certificates") | |
57 ; | |
58 | |
59 options.add(generic); | |
60 | |
61 boost::program_options::options_description sdl("SDL options"); | 47 boost::program_options::options_description sdl("SDL options"); |
62 sdl.add_options() | 48 sdl.add_options() |
63 ("width", boost::program_options::value<int>()->default_value(1024), "Initial width of the SDL window") | 49 ("width", boost::program_options::value<int>()->default_value(1024), "Initial width of the SDL window") |
64 ("height", boost::program_options::value<int>()->default_value(768), "Initial height of the SDL window") | 50 ("height", boost::program_options::value<int>()->default_value(768), "Initial height of the SDL window") |
65 ("opengl", boost::program_options::value<bool>()->default_value(true), "Enable OpenGL in SDL") | 51 ("opengl", boost::program_options::value<bool>()->default_value(true), "Enable OpenGL in SDL") |
66 ; | 52 ; |
67 | 53 |
68 options.add(sdl); | 54 options.add(sdl); |
69 } | 55 } |
70 | 56 |
71 void BasicSdlApplication::Run(BasicNativeApplicationContext& context, const std::string& title, unsigned int width, unsigned int height, bool enableOpenGl) | 57 void BasicSdlApplication::ParseCommandLineOptions(const boost::program_options::variables_map& parameters) |
58 { | |
59 if (!parameters.count("width") || | |
60 !parameters.count("height") || | |
61 !parameters.count("opengl")) | |
62 { | |
63 LOG(ERROR) << "Parameter \"width\", \"height\" or \"opengl\" is missing"; | |
64 return -1; | |
65 } | |
66 | |
67 int w = parameters["width"].as<int>(); | |
68 int h = parameters["height"].as<int>(); | |
69 if (w <= 0 || h <= 0) | |
70 { | |
71 LOG(ERROR) << "Parameters \"width\" and \"height\" must be positive"; | |
72 return -1; | |
73 } | |
74 | |
75 width_ = static_cast<unsigned int>(w); | |
76 height_ = static_cast<unsigned int>(h); | |
77 LOG(WARNING) << "Initial display size: " << width_ << "x" << height_; | |
78 | |
79 opengl_ = parameters["opengl"].as<bool>(); | |
80 if (opengl_) | |
81 { | |
82 LOG(WARNING) << "OpenGL is enabled, disable it with option \"--opengl=off\" if the application crashes"; | |
83 } | |
84 else | |
85 { | |
86 LOG(WARNING) << "OpenGL is disabled, enable it with option \"--opengl=on\" for best performance"; | |
87 } | |
88 | |
89 } | |
90 | |
91 void BasicSdlApplication::Run(BasicNativeApplicationContext& context, const std::string& title, int argc, char* argv[]) | |
72 { | 92 { |
73 /************************************************************** | 93 /************************************************************** |
74 * Run the application inside a SDL window | 94 * Run the application inside a SDL window |
75 **************************************************************/ | 95 **************************************************************/ |
76 | 96 |
77 LOG(WARNING) << "Starting the application"; | 97 LOG(WARNING) << "Starting the application"; |
78 | 98 |
79 SdlWindow window(title.c_str(), width, height, enableOpenGl); | 99 SdlWindow window(title.c_str(), width_, height_, enableOpenGl_); |
80 SdlEngine sdl(window, context); | 100 SdlEngine sdl(window, context); |
81 | 101 |
82 { | 102 { |
83 BasicNativeApplicationContext::GlobalMutexLocker locker(context); | 103 BasicNativeApplicationContext::GlobalMutexLocker locker(context); |
84 context.GetCentralViewport().Register(sdl); // (*) | 104 context.GetCentralViewport().Register(sdl); // (*) |