Ocean
FramePreviewWindow.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_PLATFORM_WXWIDGETS_FRAME_PREVIEW_WINDOW_H
9 #define META_OCEAN_PLATFORM_WXWIDGETS_FRAME_PREVIEW_WINDOW_H
10 
12 
14 
15 namespace Ocean
16 {
17 
18 namespace Platform
19 {
20 
21 namespace WxWidgets
22 {
23 
24 /**
25  * This class implements a frame preview window.
26  * @ingroup platformwxw
27  */
28 class OCEAN_PLATFORM_WXWIDGETS_EXPORT FramePreviewWindow : public wxPanel
29 {
30  public:
31 
32  /**
33  * Definition of a selection callback function.
34  * The first parameter defines the index of the selection.<br>
35  */
37 
38  private:
39 
40  /**
41  * This class implements a preview element.
42  */
43  class Element
44  {
45  public:
46 
47  /**
48  * Creates a default element.
49  */
50  Element() = default;
51 
52  /**
53  * Creates a new element.
54  * @param index Index of the preview frame
55  * @param virtualPositionStart Virtual horizontal start position of this element
56  * @param displayId Display id
57  */
58  inline Element(const unsigned int index, const int virtualPositionStart, const unsigned int displayId);
59 
60  /**
61  * Returns the frame index of this element.
62  * @return Frame index
63  */
64  inline unsigned int index() const;
65 
66  /**
67  * Returns the virtual horizontal start position.
68  * @return Virtual horizotnal start position
69  */
70  inline int virtualPositionStart() const;
71 
72  /**
73  * Returns the display id of this element.
74  * @return Display id
75  */
76  inline unsigned int displayId() const;
77 
78  /**
79  * Returns the horizontal display start position of this element.
80  * @param windowVirtualPositionStart Virtual horizontal start position of the display window
81  * @param zoom Zoom of the display window
82  * @return Resulting horizontal display start position
83  */
84  inline int displayPositionStart(const int windowVirtualPositionStart, const unsigned int zoom) const;
85 
86  /**
87  * Returns the horizontal display stop position (inclusive position) of this element.
88  * @param windowVirtualPositionStart Virtual horizontal start position of the display window
89  * @param previewWidth Width of the preview frame
90  * @param zoom Zoom of the display window
91  * @return Resulting horizontal display stop position (including)
92  */
93  inline int displayPositionStop(const int windowVirtualPositionStart, const unsigned int previewWidth, const unsigned int zoom) const;
94 
95  /**
96  * Returns the horizontal display end position (exclusive position) of this element.
97  * @param windowVirtualPositionStart Virtual horizontal start position of the display window
98  * @param previewWidth Width of the preview frame
99  * @param zoom Zoom of the display window
100  * @return Resulting horizontal display end position (exclusive)
101  */
102  inline int displayPositionEnd(const int windowVirtualPositionStart, const unsigned int previewWidth, const unsigned int zoom) const;
103 
104  /**
105  * Returns whether this element stores a valid preview frame.
106  * @return True, if so
107  */
108  explicit inline operator bool() const;
109 
110  private:
111 
112  /// Index of the preview frame.
113  unsigned int index_ = (unsigned int)(-1);
114 
115  /// Virtual horizontal start position.
116  int virtualPositionStart_ = 0;
117 
118  /// Display id.
119  unsigned int displayId_ = 0u;
120  };
121 
122  /**
123  * Definition of a vector holding elements.
124  */
125  typedef std::vector<Element> Elements;
126 
127  public:
128 
129  /**
130  * Creates a new main window object.
131  * @param title Tile of the bitmap window to be created
132  * @param parent Parent window
133  * @param pos Position of the bitmap window
134  * @param size Size of the bitmap window
135  */
136  FramePreviewWindow(const wxString& title, wxWindow* parent = nullptr, const wxPoint& pos = wxPoint(-1, -1), const wxSize& size = wxSize(-1, 100));
137 
138  /**
139  * Destructs the window.
140  */
142 
143  /**
144  * Sets a frame provider and exchanges the previous one.
145  * @param frameProvider Frame provider to be set
146  */
147  void setFrameProvider(const Media::MovieFrameProviderRef& frameProvider);
148 
149  /**
150  * Returns the current selection index.
151  * @return Selection index
152  */
153  inline unsigned int selectionIndex() const;
154 
155  /**
156  * Returns whether the frame index is displayed.
157  * @return True, if so (default)
158  */
159  inline bool displayFrameIndex() const;
160 
161  /**
162  * Sets whether the frame index will be displayed.
163  * @param display True, to display the frame index, false otherwise
164  */
165  inline void setDisplayFrameIndex(const bool display);
166 
167  /**
168  * Sets or changes the selection callback function.
169  * Set an empty callback function to remove the callback that has been set before.<br>
170  * Remove the callback function before the window is disposed.<br>
171  * @param selection Selection callback function to be set
172  */
173  inline void setSelectionCallback(const SelectionCallback& selection);
174 
175  protected:
176 
177  /// WxWidgets event table.
179 
180  protected:
181 
182  /**
183  * Paint event function.
184  * @param event Event command
185  */
186  virtual void onPaint(wxPaintEvent& event);
187 
188  /**
189  * Size event function.
190  * @param event Event command
191  */
192  virtual void onSize(wxSizeEvent& event);
193 
194  /**
195  * Left mouse click down event function.
196  * @param event Event command
197  */
198  virtual void onMouseLeftDown(wxMouseEvent& event);
199 
200  /**
201  * Left mouse click up event function.
202  * @param event Event command
203  */
204  virtual void onMouseLeftUp(wxMouseEvent& event);
205 
206  /**
207  * Left mouse double click down event function.
208  * @param event Event command
209  */
210  virtual void onMouseLeftDblClick(wxMouseEvent& event);
211 
212  /**
213  * Middle mouse click down event function.
214  * @param event Event command
215  */
216  virtual void onMouseMiddleDown(wxMouseEvent& event);
217 
218  /**
219  * Middle mouse click up event function.
220  * @param event Event command
221  */
222  virtual void onMouseMiddleUp(wxMouseEvent& event);
223 
224  /**
225  * Right mouse click down event function.
226  * @param event Event command
227  */
228  virtual void onMouseRightDown(wxMouseEvent& event);
229 
230  /**
231  * Right mouse click up event function.
232  * @param event Event command
233  */
234  virtual void onMouseRightUp(wxMouseEvent& event);
235 
236  /**
237  * Right mouse double click down event function.
238  * @param event Event command
239  */
240  virtual void onMouseRightDblClick(wxMouseEvent& event);
241 
242  /**
243  * Mouse wheel event function.
244  * @param event Event command
245  */
246  virtual void onMouseWheel(wxMouseEvent& event);
247 
248  /**
249  * Mouse move event function.
250  * @param event Event command
251  */
252  virtual void onMouseMove(wxMouseEvent& event);
253 
254  /**
255  * Background erase event function.
256  * @param event Event command
257  */
258  void onEraseBackground(wxEraseEvent& event);
259 
260  /**
261  * Event function for new frames.
262  * @param index Index of the frame
263  */
264  void onPreviewFrame(const unsigned int index);
265 
266  /**
267  * Frame provider event function.
268  * @param eventType Type of the event
269  * @param value Parameter of the event
270  */
271  void onEvent(const Media::MovieFrameProvider::EventType eventType, const unsigned long long value);
272 
273  /**
274  * Updates the display parameters.
275  */
277 
278  /**
279  * Calculates the first visible preview frame.
280  * @param windowVirtualPositionStart Virtual horizontal start position of the display window
281  * @param previewWidth Width of the preview frame in pixels
282  * @param separatorWidth Width of the seperator between preview frames
283  * @param zoom Preview frame zooming factor
284  * @param adjust2zoom True, if the resulting index is adjusted to the zooming factor
285  * @param index Resulting index of the first visible preview frame
286  * @return True, if succeeded
287  */
288  static bool calculateFirstVisibleElement(const int windowVirtualPositionStart, const unsigned int previewWidth, const unsigned int separatorWidth, const unsigned int zoom, const bool adjust2zoom, int& index);
289 
290  /**
291  * Calculates the last visible preview frame.
292  * @param windowVirtualPositionStart Virtual horizontal start position of the display window
293  * @param displayWidth Width of the display window in pixels
294  * @param previewWidth Width of the preview frame in pixels
295  * @param separatorWidth Width of the seperator between preview frames
296  * @param zoom Preview frame zooming factor
297  * @param adjust2zoom True, if the resulting index is adjusted to the zooming factor
298  * @param index Resulting index of the last visible preview frame
299  * @return True, if succeeded
300  */
301  static bool calculateLastVisibleElement(const int windowVirtualPositionStart, const unsigned int displayWidth, const unsigned int previewWidth, const unsigned int separatorWidth, const unsigned int zoom, const bool adjust2zoom, int& index);
302 
303  /**
304  * Calculates the virtual horizontal start position of a preview frame.
305  * @param index Index of the preview frame
306  * @param previewWidth Width of the preview frame in pixel
307  * @param separatorWidth Width of the separator between preview frames
308  * @param zoom Preview frame zooming factor
309  * @param position Resulting virtual horizontal start position
310  * @return True, if succeeded
311  */
312  static bool calculateVirtualPositionStart(const unsigned int index, const unsigned int previewWidth, const unsigned int separatorWidth, const unsigned int zoom, int& position);
313 
314  /**
315  * Draws a frame into a given device context.
316  * @param dc Device context in that the frame will be drawn
317  * @param frame The frame to be drawn
318  * @param frameIndex Index of frame
319  * @param displayPositionLeft Horizontal display position
320  * @param selection True, if the frame is selected
321  */
322  void drawFrame(wxDC& dc, const Frame& frame, const unsigned int frameIndex, const int displayPositionLeft, const bool selection);
323 
324  protected:
325 
326  /// Frame provider of this window.
328 
329  /// Current, estimated, or actual frame number.
330  unsigned int frameNumber_ = 0u;
331 
332  /// Width of the separator between preview frame, in pixel.
333  unsigned int separatorWidth_ = 2u;
334 
335  /// Virtual width of the window, in pixel.
336  unsigned int virtualWidth_ = 0u;
337 
338  /// Virtual position, in pixel.
339  int virtualPositionStart_ = 0;
340 
341  /// Width of a preview frame in pixel.
342  unsigned int previewWidth_ = 0u;
343 
344  /// Height of the preview frame in pixel.
345  unsigned int previewHeight_ = 0u;
346 
347  /// Preview zoom factor.
348  unsigned int previewZoom_ = 50u;
349 
350  /// Preview elements.
352 
353  /// Preview frame selection index.
354  unsigned int selectionIndex_ = (unsigned int)(-1);
355 
356  /// True to display the frame index; False, to hide it
357  bool displayFrameIndex_ = true;
358 
359  /// Selection changed callback function.
361 
362  /// True, if a new previous frame has arrived.
363  bool newPreviewFrame_ = false;
364 };
365 
366 inline FramePreviewWindow::Element::Element(const unsigned int index, const int virtualPositionStart, const unsigned int displayId) :
367  index_(index),
368  virtualPositionStart_(virtualPositionStart),
369  displayId_(displayId)
370 {
371  // nothing to do here
372 }
373 
374 inline unsigned int FramePreviewWindow::Element::index() const
375 {
376  return index_;
377 }
378 
380 {
381  return virtualPositionStart_;
382 }
383 
384 inline unsigned int FramePreviewWindow::Element::displayId() const
385 {
386  return displayId_;
387 }
388 
389 inline int FramePreviewWindow::Element::displayPositionStart(const int windowVirtualPositionStart, const unsigned int zoom) const
390 {
391  return virtualPositionStart_ / int(zoom) - windowVirtualPositionStart / int(zoom);
392 }
393 
394 inline int FramePreviewWindow::Element::displayPositionStop(const int windowVirtualPositionStart, const unsigned int previewWidth, const unsigned int zoom) const
395 {
396  return virtualPositionStart_ / int(zoom) - windowVirtualPositionStart / int(zoom) + int(previewWidth) - 1;
397 }
398 
399 inline int FramePreviewWindow::Element::displayPositionEnd(const int windowVirtualPositionStart, const unsigned int previewWidth, const unsigned int zoom) const
400 {
401  return virtualPositionStart_ / int(zoom) - windowVirtualPositionStart / int(zoom) + int(previewWidth);
402 }
403 
404 inline FramePreviewWindow::Element::operator bool() const
405 {
406  return index_ != (unsigned int)-1;
407 }
408 
409 inline unsigned int FramePreviewWindow::selectionIndex() const
410 {
411  return selectionIndex_;
412 }
413 
414 inline void FramePreviewWindow::setSelectionCallback(const SelectionCallback& selectionCallback)
415 {
416  selectionCallback_ = selectionCallback;
417 }
418 
420 {
421  return displayFrameIndex_;
422 }
423 
424 inline void FramePreviewWindow::setDisplayFrameIndex(const bool display)
425 {
426  displayFrameIndex_ = display;
427 }
428 
429 }
430 
431 }
432 
433 }
434 
435 #endif // META_OCEAN_PLATFORM_WXWIDGETS_FRAME_PREVIEW_WINDOW_H
This class implements Ocean's image class.
Definition: Frame.h:1760
EventType
Definition of individual event types.
Definition: MovieFrameProvider.h:50
This class implements a preview element.
Definition: FramePreviewWindow.h:44
unsigned int index() const
Returns the frame index of this element.
Definition: FramePreviewWindow.h:374
unsigned int displayId() const
Returns the display id of this element.
Definition: FramePreviewWindow.h:384
int displayPositionEnd(const int windowVirtualPositionStart, const unsigned int previewWidth, const unsigned int zoom) const
Returns the horizontal display end position (exclusive position) of this element.
Definition: FramePreviewWindow.h:399
int displayPositionStart(const int windowVirtualPositionStart, const unsigned int zoom) const
Returns the horizontal display start position of this element.
Definition: FramePreviewWindow.h:389
int displayPositionStop(const int windowVirtualPositionStart, const unsigned int previewWidth, const unsigned int zoom) const
Returns the horizontal display stop position (inclusive position) of this element.
Definition: FramePreviewWindow.h:394
Element()=default
Creates a default element.
int virtualPositionStart() const
Returns the virtual horizontal start position.
Definition: FramePreviewWindow.h:379
This class implements a frame preview window.
Definition: FramePreviewWindow.h:29
virtual void onSize(wxSizeEvent &event)
Size event function.
bool displayFrameIndex() const
Returns whether the frame index is displayed.
Definition: FramePreviewWindow.h:419
virtual void onMouseRightUp(wxMouseEvent &event)
Right mouse click up event function.
virtual void onMouseMiddleDown(wxMouseEvent &event)
Middle mouse click down event function.
void onEvent(const Media::MovieFrameProvider::EventType eventType, const unsigned long long value)
Frame provider event function.
unsigned int selectionIndex_
Preview frame selection index.
Definition: FramePreviewWindow.h:354
bool displayFrameIndex_
True to display the frame index; False, to hide it.
Definition: FramePreviewWindow.h:357
int virtualPositionStart_
Virtual position, in pixel.
Definition: FramePreviewWindow.h:339
Media::MovieFrameProviderRef frameProvider_
Frame provider of this window.
Definition: FramePreviewWindow.h:327
void setDisplayFrameIndex(const bool display)
Sets whether the frame index will be displayed.
Definition: FramePreviewWindow.h:424
void onEraseBackground(wxEraseEvent &event)
Background erase event function.
virtual void onMouseRightDblClick(wxMouseEvent &event)
Right mouse double click down event function.
unsigned int selectionIndex() const
Returns the current selection index.
Definition: FramePreviewWindow.h:409
virtual void onPaint(wxPaintEvent &event)
Paint event function.
Elements elements_
Preview elements.
Definition: FramePreviewWindow.h:351
virtual void onMouseRightDown(wxMouseEvent &event)
Right mouse click down event function.
~FramePreviewWindow() override
Destructs the window.
Callback< void, const unsigned int > SelectionCallback
Definition of a selection callback function.
Definition: FramePreviewWindow.h:36
void updateDispalyParameter()
Updates the display parameters.
virtual void onMouseWheel(wxMouseEvent &event)
Mouse wheel event function.
SelectionCallback selectionCallback_
Selection changed callback function.
Definition: FramePreviewWindow.h:360
static bool calculateVirtualPositionStart(const unsigned int index, const unsigned int previewWidth, const unsigned int separatorWidth, const unsigned int zoom, int &position)
Calculates the virtual horizontal start position of a preview frame.
virtual void onMouseMiddleUp(wxMouseEvent &event)
Middle mouse click up event function.
void onPreviewFrame(const unsigned int index)
Event function for new frames.
FramePreviewWindow(const wxString &title, wxWindow *parent=nullptr, const wxPoint &pos=wxPoint(-1, -1), const wxSize &size=wxSize(-1, 100))
Creates a new main window object.
void drawFrame(wxDC &dc, const Frame &frame, const unsigned int frameIndex, const int displayPositionLeft, const bool selection)
Draws a frame into a given device context.
static bool calculateFirstVisibleElement(const int windowVirtualPositionStart, const unsigned int previewWidth, const unsigned int separatorWidth, const unsigned int zoom, const bool adjust2zoom, int &index)
Calculates the first visible preview frame.
void setFrameProvider(const Media::MovieFrameProviderRef &frameProvider)
Sets a frame provider and exchanges the previous one.
virtual void onMouseLeftUp(wxMouseEvent &event)
Left mouse click up event function.
virtual void onMouseMove(wxMouseEvent &event)
Mouse move event function.
void setSelectionCallback(const SelectionCallback &selection)
Sets or changes the selection callback function.
Definition: FramePreviewWindow.h:414
virtual void onMouseLeftDown(wxMouseEvent &event)
Left mouse click down event function.
std::vector< Element > Elements
Definition of a vector holding elements.
Definition: FramePreviewWindow.h:125
virtual void onMouseLeftDblClick(wxMouseEvent &event)
Left mouse double click down event function.
static bool calculateLastVisibleElement(const int windowVirtualPositionStart, const unsigned int displayWidth, const unsigned int previewWidth, const unsigned int separatorWidth, const unsigned int zoom, const bool adjust2zoom, int &index)
Calculates the last visible preview frame.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15