Graphite  Version 3
An experimental 3D geometry processing program
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 
46 #ifndef GEO_OS_ANDROID
47 # define GEO_GLFW
48 #endif
49 
55 namespace GEO {
56 
57  class Image;
58  class ApplicationData;
59 
67  public:
68 
73  Application(const std::string& name);
74 
78  virtual ~Application();
79 
84  static Application* instance() {
85  return instance_;
86  }
87 
88 
93  const std::string& name() const {
94  return name_;
95  }
96 
97 
104  virtual void start(int argc=0, char** argv=nullptr);
105 
109  virtual void stop();
110 
115  const std::string& get_style() const {
116  return style_;
117  }
118 
124  virtual void set_style(const std::string& value);
125 
131  static std::string get_styles();
132 
137  void set_font_size(index_t value);
138 
144  return font_size_;
145  }
146 
150  virtual void update();
151 
157 
164  void lock_updates() {
165  ++nb_update_locks_;
166  }
167 
171  void unlock_updates() {
172  // Note: Under Windows, when the Graphite window is iconified,
173  // it can happen that nb_update_locks_ is already 0 when
174  // reaching this point.
175  if(nb_update_locks_ > 0) {
176  --nb_update_locks_;
177  }
178  }
179 
186  virtual void draw();
187 
193  double scaling() const;
194 
203  index_t w=0, index_t h=0, index_t hz=0,
204  index_t monitor=0
205  );
206 
213 
220 
224  void iconify();
225 
229  void restore();
230 
237  void set_gui_state(std::string x);
238 
244  std::string get_gui_state() const;
245 
251  void set_full_screen(bool x);
252 
258  bool get_full_screen() const;
259 
264  index_t get_width() const {
265  return width_;
266  }
267 
272  index_t get_height() const {
273  return height_;
274  }
275 
281  return frame_buffer_width_;
282  }
283 
289  return frame_buffer_height_;
290  }
291 
298  void set_accept_drops(bool value) {
299  accept_drops_ = value;
300  }
301 
308  bool get_accept_drops() const {
309  return accept_drops_;
310  }
311 
316  void set_window_icon(Image* image);
317 
327  virtual void mouse_button_callback(
328  int button, int action, int mods=0, int source=EVENT_SOURCE_MOUSE
329  );
330 
335  virtual void scroll_callback(double xoffset, double yoffset);
336 
343  virtual void cursor_pos_callback(
344  double x, double y, int source=EVENT_SOURCE_MOUSE
345  );
346 
352  virtual void drop_callback(int nb, const char** f);
353 
359  virtual void char_callback(unsigned int c);
360 
368  virtual void key_callback(int key, int scancode, int action, int mods);
369 
374  void restart_gui() {
375  ImGui_restart_ = true;
376  }
377 
383  ApplicationData* impl_data() {
384  return data_;
385  }
386 
392  void* impl_window();
393 
401  double hidpi_scaling() const {
402  return hidpi_scaling_;
403  }
404 
413  double pixel_ratio() const {
414  return pixel_ratio_;
415  }
416 
421  soft_keyboard_visible_ = false;
422  }
423 
424  //protected:
425  public:
426 
432  const char* key_to_string(int key);
433 
439  virtual void draw_gui();
440 
447  virtual void draw_graphics();
448 
454  virtual void pre_draw();
455 
460  virtual void post_draw();
461 
467  virtual bool needs_to_redraw() const;
468 
472  virtual void create_window();
473 
477  virtual void delete_window();
478 
487  virtual void resize(index_t w, index_t h, index_t fb_w, index_t fb_h);
488 
493  virtual void one_frame();
494 
501  virtual void main_loop();
502 
506  virtual void GL_initialize();
507 
511  virtual void GL_terminate();
512 
516  virtual void ImGui_initialize();
517 
521  virtual void ImGui_load_fonts();
522 
526  virtual void ImGui_terminate();
527 
531  virtual void ImGui_new_frame();
532 
533  /*
534  * \param[in] argc , argv command line parameters, used
535  * to initialize geogram.
536  */
537  virtual void geogram_initialize(int argc, char** argv);
538 
543 
548  const std::vector<std::string>& filenames() const {
549  return filenames_;
550  }
551 
552  bool animate() const {
553  return animate_;
554  }
555 
556  bool* animate_ptr() {
557  return &animate_;
558  }
559 
560  void start_animation() {
561  animate_ = true;
562  }
563 
564  void stop_animation() {
565  animate_ = false;
566  }
567 
568  private:
569  static Application* instance_;
570  ApplicationData* data_;
571  index_t width_;
572  index_t height_;
573  index_t frame_buffer_width_;
574  index_t frame_buffer_height_;
575  bool in_main_loop_;
576  bool accept_drops_;
577  double scaling_;
578  index_t nb_update_locks_;
579  std::string style_;
580  bool ImGui_restart_;
581  bool ImGui_reload_font_;
582  bool ImGui_initialized_;
583  index_t font_size_;
584  index_t nb_frames_update_;
585  double hidpi_scaling_;
586  double pixel_ratio_;
587  std::string name_;
588  bool currently_drawing_gui_;
589  std::vector<std::string> filenames_;
590  bool animate_;
593  protected:
595  bool menubar_visible_;
597  bool soft_keyboard_visible_;
598 
599 #ifdef GEO_OS_EMSCRIPTEN
600  friend void emscripten_one_frame();
601 #endif
602  };
603 
604 }
605 
606 #endif
Base class for all applications.
Definition: application.h:66
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.
Definition: application.h:143
const std::vector< std::string > & filenames() const
Gets all the filenames specified on the command line.
Definition: application.h:548
const char * key_to_string(int key)
Converts a key to a symbolic string with the name of the key.
void restart_gui()
Restarts the gui.
Definition: application.h:374
double hidpi_scaling() const
MacOS non-sense.
Definition: application.h:401
virtual void ImGui_load_fonts()
Loads the fonts in ImGui.
static Application * instance()
Gets the instance.
Definition: application.h:84
void lock_updates()
Lock updates.
Definition: application.h:164
bool get_accept_drops() const
Tests whether drag and drop events are taken into account.
Definition: application.h:308
index_t get_frame_buffer_width() const
Gets the width of the window.
Definition: application.h:280
void reset_soft_keyboard_flag()
Used internally.
Definition: application.h:420
void draw_dock_space()
Draws a dockspace that fills the current window.
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.
Definition: application.h:298
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()
void * impl_window()
Gets a pointer to the implementation-specific window.
index_t get_height() const
Gets the height of the window.
Definition: application.h:272
index_t get_width() const
Gets the width of the window.
Definition: application.h:264
void unlock_updates()
Unlock updates.
Definition: application.h:171
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 one_frame()
Draws one frame.
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.
virtual void start(int argc=0, char **argv=nullptr)
Starts the main event loop of the application.
void set_gui_state(std::string x)
Sets the gui state.
double pixel_ratio() const
More MacOS non-sense.
Definition: application.h:413
bool ImGui_firsttime_init_
Definition: application.h:594
virtual void post_draw()
This function is called after all drawing operations.
const std::string & name() const
Gets the name of this application.
Definition: application.h:93
virtual void create_window()
Creates the window using GLFW.
const std::string & get_style() const
Gets the style.
Definition: application.h:115
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.
virtual ~Application()
Application destructor.
index_t get_frame_buffer_height() const
Gets the height of the window.
Definition: application.h:288
void restore()
Restores this application.
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.
ApplicationData * impl_data()
Gets a pointer to the implementation-specific data.
Definition: application.h:383
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
Common include file, providing basic definitions. Should be included before anything else by all head...
#define GEOGRAM_GFX_API
Linkage declaration for geogram symbols.
Definition: defs.h:55
Global Vorpaline namespace.
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329