Nori  24
gui.h
1 /*
2  This file is part of Nori, a simple educational ray tracer
3 
4  Copyright (c) 2015 by Wenzel Jakob, Romain Prévost
5 
6  Nori is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Nori is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #if !defined(__NORI_GUI_H)
20 #define __NORI_GUI_H
21 
22 #include <nori/common.h>
23 #include <nanogui/screen.h>
24 #include <nanogui/renderpass.h>
25 #include <nanogui/shader.h>
26 #include <nanogui/canvas.h>
27 #include <nori/render.h>
28 
29 NORI_NAMESPACE_BEGIN
30 
31 class NoriCanvas : public nanogui::Canvas {
32 public:
33  NoriCanvas(nanogui::Widget* parent, const ImageBlock& block);
34  void draw_contents() override;
35  void update();
36  void set_scale(float scale) {
37  m_scale = scale;
38  }
39 private:
40  const ImageBlock& m_block;
41  nanogui::ref<nanogui::Shader> m_shader;
42  nanogui::ref<nanogui::Texture> m_texture;
43  nanogui::ref<nanogui::RenderPass> m_renderPass;
44  float m_scale = 1.f;
45 };
46 
47 class NoriScreen : public nanogui::Screen {
48 public:
49  NoriScreen(ImageBlock& block);
50  void draw_contents() override;
51 
52  virtual bool keyboard_event(int key, int scancode, int action, int modifiers) override;
53  virtual bool drop_event(const std::vector<std::string>& filenames) override;
54 
55  void updateLayout();
56 
57  void requestLayoutUpdate() {
58  m_requiresLayoutUpdate = true;
59  }
60 
61  void adjustWindow(Vector2i blockSize);
62 
63  void openXML(const std::string& filename);
64  void openEXR(const std::string& filename);
65 
66 private:
67  ImageBlock& m_block;
68  nanogui::ref<NoriCanvas> m_render_canvas;
69  nanogui::ref<nanogui::Shader> m_shader;
70  nanogui::ref<nanogui::RenderPass> m_renderPass;
71  nanogui::Slider* m_slider = nullptr;
72  nanogui::ProgressBar* m_progressBar = nullptr;
73  nanogui::ref<nanogui::Texture> m_texture;
74  bool m_requiresLayoutUpdate = false;
75  float m_scale = 1.f;
76  Widget* panel = nullptr;
77 
78  RenderThread m_renderThread;
79 };
80 
81 NORI_NAMESPACE_END
82 
83 #endif /* __NORI_GUI_H */
Weighted pixel storage for a rectangular subregion of an image.
Definition: block.h:48
Definition: gui.h:31
Definition: gui.h:47