comparison OrthancStone/Sources/Viewport/SdlViewport.h @ 1576:92fca2b3ba3d

sanitizing the handling of canvas size
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 24 Sep 2020 16:40:30 +0200
parents 85e117739eca
children
comparison
equal deleted inserted replaced
1575:e4a52cbbdd70 1576:92fca2b3ba3d
93 93
94 virtual void Invalidate() ORTHANC_OVERRIDE 94 virtual void Invalidate() ORTHANC_OVERRIDE
95 { 95 {
96 that_.SendRefreshEvent(); 96 that_.SendRefreshEvent();
97 } 97 }
98
99 virtual void RefreshCanvasSize() ORTHANC_OVERRIDE
100 {
101 that_.RefreshCanvasSize();
102 }
98 }; 103 };
99 104
100 void ClearCompositor() 105 void ClearCompositor()
101 { 106 {
102 compositor_.reset(); 107 compositor_.reset();
103 } 108 }
104 109
105 void AcquireCompositor(ICompositor* compositor /* takes ownership */); 110 void AcquireCompositor(ICompositor* compositor /* takes ownership */);
106 111
112 virtual void RefreshCanvasSize() = 0;
113
107 protected: 114 protected:
108 SdlViewport(); 115 SdlViewport();
116
109 void PostConstructor(); 117 void PostConstructor();
110 118
111 public: 119 public:
112
113 bool IsRefreshEvent(const SDL_Event& event) const 120 bool IsRefreshEvent(const SDL_Event& event) const
114 { 121 {
115 return (event.type == refreshEvent_); 122 return (event.type == refreshEvent_);
116 } 123 }
117 124
120 return new SdlLock(*this); 127 return new SdlLock(*this);
121 } 128 }
122 129
123 virtual uint32_t GetSdlWindowId() = 0; 130 virtual uint32_t GetSdlWindowId() = 0;
124 131
125 virtual void UpdateSize(unsigned int width, 132 void UpdateSize(unsigned int width,
126 unsigned int height) = 0; 133 unsigned int height);
127 134
128 virtual void ToggleMaximize() = 0; 135 virtual void ToggleMaximize() = 0;
129 136
130 // Must be invoked from the main SDL thread 137 // Must be invoked from the main SDL thread
131 virtual void Paint() = 0; 138 virtual void Paint() = 0;
135 class SdlOpenGLViewport : public SdlViewport 142 class SdlOpenGLViewport : public SdlViewport
136 { 143 {
137 private: 144 private:
138 SdlOpenGLContext context_; 145 SdlOpenGLContext context_;
139 146
140 private:
141 SdlOpenGLViewport(const std::string& title, 147 SdlOpenGLViewport(const std::string& title,
142 unsigned int width, 148 unsigned int width,
143 unsigned int height, 149 unsigned int height,
144 bool allowDpiScaling = true); 150 bool allowDpiScaling = true);
151
152 protected:
153 virtual void RefreshCanvasSize() ORTHANC_OVERRIDE;
154
145 public: 155 public:
146 static boost::shared_ptr<SdlOpenGLViewport> Create(const std::string&, 156 static boost::shared_ptr<SdlOpenGLViewport> Create(const std::string&,
147 unsigned int width, 157 unsigned int width,
148 unsigned int height, 158 unsigned int height,
149 bool allowDpiScaling = true); 159 bool allowDpiScaling = true);
153 163
154 virtual uint32_t GetSdlWindowId() ORTHANC_OVERRIDE; 164 virtual uint32_t GetSdlWindowId() ORTHANC_OVERRIDE;
155 165
156 virtual void Paint() ORTHANC_OVERRIDE; 166 virtual void Paint() ORTHANC_OVERRIDE;
157 167
158 virtual void UpdateSize(unsigned int width,
159 unsigned int height) ORTHANC_OVERRIDE;
160
161 virtual void ToggleMaximize() ORTHANC_OVERRIDE; 168 virtual void ToggleMaximize() ORTHANC_OVERRIDE;
162 }; 169 };
163 170
164 171
165 class SdlCairoViewport : public SdlViewport 172 class SdlCairoViewport : public SdlViewport
168 SdlWindow window_; 175 SdlWindow window_;
169 SDL_Surface* sdlSurface_; 176 SDL_Surface* sdlSurface_;
170 177
171 void CreateSdlSurfaceFromCompositor(const CairoCompositor& compositor); 178 void CreateSdlSurfaceFromCompositor(const CairoCompositor& compositor);
172 179
173 private:
174 SdlCairoViewport(const char* title, 180 SdlCairoViewport(const char* title,
175 unsigned int width, 181 unsigned int width,
176 unsigned int height, 182 unsigned int height,
177 bool allowDpiScaling = true); 183 bool allowDpiScaling = true);
184
185 protected:
186 virtual void RefreshCanvasSize() ORTHANC_OVERRIDE;
187
178 public: 188 public:
179 static boost::shared_ptr<SdlCairoViewport> Create(const char* title, 189 static boost::shared_ptr<SdlCairoViewport> Create(const char* title,
180 unsigned int width, 190 unsigned int width,
181 unsigned int height, 191 unsigned int height,
182 bool allowDpiScaling = true); 192 bool allowDpiScaling = true);
186 196
187 virtual uint32_t GetSdlWindowId() ORTHANC_OVERRIDE; 197 virtual uint32_t GetSdlWindowId() ORTHANC_OVERRIDE;
188 198
189 virtual void Paint() ORTHANC_OVERRIDE; 199 virtual void Paint() ORTHANC_OVERRIDE;
190 200
191 virtual void UpdateSize(unsigned int width,
192 unsigned int height) ORTHANC_OVERRIDE;
193
194 virtual void ToggleMaximize() ORTHANC_OVERRIDE; 201 virtual void ToggleMaximize() ORTHANC_OVERRIDE;
195 }; 202 };
196 } 203 }