Geogram Version 1.9.6-rc
A programming library of geometric algorithms
Loading...
Searching...
No Matches
application.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2000-2022 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40#ifndef H_GEOGRAM_GFX_GUI_APPLICATION_H
41#define H_GEOGRAM_GFX_GUI_APPLICATION_H
42
44#include <geogram_gfx/gui/events.h>
45#include <atomic>
46
47#ifndef GEO_OS_ANDROID
48# define GEO_GLFW
49#endif
50
56namespace GEO {
57
58 class Image;
59 class ApplicationData;
60
68 public:
69
74 Application(const std::string& name);
75
79 virtual ~Application();
80
86 return instance_;
87 }
88
89
94 const std::string& name() const {
95 return name_;
96 }
97
98
105 virtual void start(int argc=0, char** argv=nullptr);
106
110 virtual void stop();
111
116 const std::string& get_style() const {
117 return style_;
118 }
119
125 virtual void set_style(const std::string& value);
126
132 static std::string get_styles();
133
139
145 return font_size_;
146 }
147
151 virtual void update();
152
158
166 ++nb_update_locks_;
167 }
168
173 // Note: Under Windows, when the Graphite window is iconified,
174 // it can happen that nb_update_locks_ is already 0 when
175 // reaching this point.
176 if(nb_update_locks_ > 0) {
177 --nb_update_locks_;
178 }
179 }
180
189 bool updates_locked() const {
190 return (nb_update_locks_ > 0);
191 }
192
199 virtual void draw();
200
206 double scaling() const;
207
216 index_t w=0, index_t h=0, index_t hz=0,
217 index_t monitor=0
218 );
219
226
233
237 void iconify();
238
242 void restore();
243
250 void set_gui_state(std::string x);
251
257 std::string get_gui_state() const;
258
264 void set_full_screen(bool x);
265
271 bool get_full_screen() const;
272
281 return width_;
282 }
283
292 return height_;
293 }
294
302 return frame_buffer_width_;
303 }
304
312 return frame_buffer_height_;
313 }
314
321 void set_accept_drops(bool value) {
322 accept_drops_ = value;
323 }
324
331 bool get_accept_drops() const {
332 return accept_drops_;
333 }
334
339 void set_window_icon(Image* image);
340
351 int button, int action, int mods=0, int source=EVENT_SOURCE_MOUSE
352 );
353
358 virtual void scroll_callback(double xoffset, double yoffset);
359
367 double x, double y, int source=EVENT_SOURCE_MOUSE
368 );
369
375 virtual void drop_callback(int nb, const char** f);
376
382 virtual void char_callback(unsigned int c);
383
391 virtual void key_callback(int key, int scancode, int action, int mods);
392
397 void restart_gui() {
398 ImGui_restart_ = true;
399 }
400
406 ApplicationData* impl_data() {
407 return data_;
408 }
409
415 void* impl_window();
416
424 double hidpi_scaling() const {
425 return hidpi_scaling_;
426 }
427
439 double pixel_ratio() const {
440 return pixel_ratio_;
441 }
442
447 soft_keyboard_visible_ = false;
448 }
449
450 //protected:
451 public:
452
458 const char* key_to_string(int key);
459
465 virtual void draw_gui();
466
473 virtual void draw_graphics();
474
480 virtual void pre_draw();
481
486 virtual void post_draw();
487
493 virtual bool needs_to_redraw() const;
494
498 virtual void create_window();
499
503 virtual void delete_window();
504
513 virtual void resize(index_t w, index_t h, index_t fb_w, index_t fb_h);
514
519 virtual void one_frame(bool draw_GUI = true);
520
527 virtual void main_loop();
528
532 virtual void GL_initialize();
533
537 virtual void GL_terminate();
538
542 virtual void ImGui_initialize();
543
547 virtual void ImGui_load_fonts();
548
552 virtual void ImGui_terminate();
553
557 virtual void ImGui_new_frame();
558
559 /*
560 * \param[in] argc , argv command line parameters, used
561 * to initialize geogram.
562 */
563 virtual void geogram_initialize(int argc, char** argv);
564
571 virtual void declare_args();
572
577
582 const std::vector<std::string>& filenames() const {
583 return filenames_;
584 }
585
586 bool animate() const {
587 return animate_;
588 }
589
590 bool* animate_ptr() {
591 return &animate_;
592 }
593
594 void start_animation() {
595 animate_ = true;
596 }
597
598 void stop_animation() {
599 animate_ = false;
600 }
601
602 private:
603 static Application* instance_;
604 ApplicationData* data_;
605 index_t width_;
606 index_t height_;
607 index_t frame_buffer_width_;
608 index_t frame_buffer_height_;
609 bool in_main_loop_;
610 bool accept_drops_;
611 double scaling_;
612 std::atomic<index_t> nb_update_locks_;
613 std::string style_;
614 bool ImGui_restart_;
615 bool ImGui_reload_font_;
616 bool ImGui_initialized_;
617 index_t font_size_;
618 index_t nb_frames_update_;
619 double hidpi_scaling_;
620 double pixel_ratio_;
621 std::string name_;
622 bool currently_drawing_gui_;
623 std::vector<std::string> filenames_;
624 bool animate_;
627 protected:
629 bool menubar_visible_;
631 bool soft_keyboard_visible_;
632
633#ifdef GEO_OS_EMSCRIPTEN
634 friend void emscripten_one_frame();
635#endif
636 };
637
638}
639
640#endif
Base class for all applications.
Definition application.h:67
void set_full_screen(bool x)
Sets full-screen mode.
virtual void main_loop()
Enters the main application loop.
index_t get_font_size() const
Gets the font size.
void restart_gui()
Restarts the gui.
double hidpi_scaling() const
MacOS non-sense.
virtual void ImGui_load_fonts()
Loads the fonts in ImGui.
void lock_updates()
Lock updates.
bool get_accept_drops() const
Tests whether drag and drop events are taken into account.
bool updates_locked() const
Tests whether graphic updates are locked.
index_t get_frame_buffer_width() const
Gets the width of the frame buffer.
void reset_soft_keyboard_flag()
Used internally.
void draw_dock_space()
Draws a dockspace that fills the current window.
static Application * instance()
Gets the instance.
Definition application.h:85
virtual void mouse_button_callback(int button, int action, int mods=0, int source=EVENT_SOURCE_MOUSE)
Callback called whenenver a mouse button changed.
virtual void ImGui_terminate()
Deallocates objects used by the ImGui library.
virtual void GL_terminate()
Deallocates OpenGL and GLUP objects.
void set_accept_drops(bool value)
Sets whether drag and drop events should be taken into account.
void set_full_screen_mode(index_t w=0, index_t h=0, index_t hz=0, index_t monitor=0)
Sets full-screen mode.
void set_font_size(index_t value)
Sets the font size.
double scaling() const
Gets the global scaling to be applied to all GUI elements.
virtual void scroll_callback(double xoffset, double yoffset)
Callback called whenenver the mouse wheel is moved.
void list_video_modes()
Lists the video modes that can be used for set_full_screen_mode()
index_t get_height() const
Gets the height of the window.
index_t get_width() const
Gets the width of the window.
void unlock_updates()
Unlock updates.
void set_windowed_mode(index_t w=0, index_t h=0)
Sets windowed mode.
virtual void pre_draw()
This function is called before starting drawing operations.
void iconify()
Iconifies this application.
virtual void ImGui_initialize()
Initializes the ImGui library.
virtual void resize(index_t w, index_t h, index_t fb_w, index_t fb_h)
Called whenever window size changes.
virtual void drop_callback(int nb, const char **f)
Callback called whenever files are dropped in the window.
virtual void update()
Indicates that the main window should be redrawn.
virtual void stop()
Stops the application.
Application(const std::string &name)
Application constructor.
virtual void key_callback(int key, int scancode, int action, int mods)
Callback called whenever a key is pushed (low level version)
void callbacks_initialize()
Initializes the callbacks if not already initialized.
const std::string & get_style() const
Gets the style.
const char * key_to_string(int key)
Converts a key to a symbolic string with the name of the key.
virtual void start(int argc=0, char **argv=nullptr)
Starts the main event loop of the application.
const std::vector< std::string > & filenames() const
Gets all the filenames specified on the command line.
void set_gui_state(std::string x)
Sets the gui state.
virtual void declare_args()
Called by geogram_initialize(), right before parsing command line arguments.
double pixel_ratio() const
More MacOS non-sense.
virtual void post_draw()
This function is called after all drawing operations.
virtual void create_window()
Creates the window using GLFW.
virtual void draw_gui()
This function is called when the GUI should be redisplayed.
virtual void delete_window()
Deletes the window created by GLFW.
void set_window_icon(Image *image)
Sets the icon of the window.
const std::string & name() const
Gets the name of this application.
Definition application.h:94
virtual ~Application()
Application destructor.
index_t get_frame_buffer_height() const
Gets the height of the frame buffer.
void restore()
Restores this application.
ApplicationData * impl_data()
Gets a pointer to the implementation-specific data.
virtual void set_style(const std::string &value)
Sets the style of the application.
virtual void cursor_pos_callback(double x, double y, int source=EVENT_SOURCE_MOUSE)
Callback called whenever the mouse cursor is moved.
virtual void ImGui_new_frame()
Notifies ImGui that a new frame has just started.
virtual void GL_initialize()
Initializes OpenGL and GLUP objects.
virtual void one_frame(bool draw_GUI=true)
Draws one frame.
void * impl_window()
Gets a pointer to the implementation-specific window.
virtual bool needs_to_redraw() const
Tests whether the window needs to be redrawn.
std::string get_gui_state() const
Gets the gui state.
virtual void draw_graphics()
This function is called when the 3d content should be redisplayed.
bool get_full_screen() const
Tests whether this application is in full-screen mode.
static std::string get_styles()
Gets the possible styles.
virtual void char_callback(unsigned int c)
Callback called whenever a key is pushed (high level version)
virtual void draw()
Redraws the main window.
An image.
Definition image.h:59
#define GEOGRAM_GFX_API
Linkage declaration for geogram symbols.
Definition defs.h:55
Common include file, providing basic definitions. Should be included before anything else by all head...
Global Vorpaline namespace.
Definition basic.h:55
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:329