Numworks Epsilon  1.4.1
Graphing Calculator Operating System
view.h
Go to the documentation of this file.
1 #ifndef ESCHER_VIEW_H
2 #define ESCHER_VIEW_H
3 
4 extern "C" {
5 #include <stdint.h>
6 #include <kandinsky.h>
7 }
8 
9 #if ESCHER_VIEW_LOGGING
10 #include <iostream>
11 #endif
12 
13 /* Key concepts
14  * - A View always clips: you cannot draw outside its frame
15  * - A View can redraw its whole hierarchy, but a very important optimization is
16  * for it not to do this all the time. So a View will try to track which parts
17  * of it really need to be redrawn.
18  * - A view can be offscreen. Until it's attached to the screen, it shouldn't
19  * send any display command. */
20 
21 class Window;
22 
23 class View {
24  // We only want Window to be able to invoke View::redraw
25  friend class Window;
26 public:
27  View();
28  virtual ~View();
29  View(const View& other) = delete;
30  View(View&& other) = delete;
31  View& operator=(const View& other) = delete;
32  View& operator=(View&& other) = delete;
33  void resetSuperview();
34  /* The drawRect method should be implemented by each View subclass. In a
35  * typical drawRect implementation, a subclass will make drawing calls to the
36  * Kandinsky library using the provided context. */
37  virtual void drawRect(KDContext * ctx, KDRect rect) const;
38 
39  void setSize(KDSize size);
40  void setFrame(KDRect frame);
42 
43  KDRect bounds() const;
44  View * subview(int index);
45 
46  virtual KDSize minimalSizeForOptimalDisplay() const;
47 
48 #if ESCHER_VIEW_LOGGING
49  friend std::ostream &operator<<(std::ostream &os, View &view);
50 #endif
51 protected:
52  /* The whole point of the dirty-tracking mechanism is to identify which
53  * pixels have to be redrawn. So in the end it doesn't really need to be bound
54  * to a view, it's really absolute pixels that count.
55  *
56  * That being said, what are the case of dirtyness that we know of?
57  * - Scrolling -> well, everything has to be redrawn anyway
58  * - Moving a cursor -> In that case, there's really a much more efficient way
59  * - ... and that's all I can think of.
60  */
61  void markRectAsDirty(KDRect rect);
62 #if ESCHER_VIEW_LOGGING
63  virtual const char * className() const;
64  virtual void logAttributes(std::ostream &os) const;
65 #endif
67 private:
68  virtual int numberOfSubviews() const;
69  virtual View * subviewAtIndex(int index);
70  virtual void layoutSubviews();
71  virtual const Window * window() const;
72  KDRect redraw(KDRect rect, KDRect forceRedrawRect = KDRectZero);
73  KDPoint absoluteOrigin() const;
74  KDRect absoluteVisibleFrame() const;
75 
76  View * m_superview;
77  KDRect m_dirtyRect;
78 };
79 
80 #endif
View & operator=(const View &other)=delete
virtual int numberOfSubviews() const override
Definition: window.cpp:30
Definition: window.h:6
void setFrame(KDRect frame)
Definition: view.cpp:125
void markRectAsDirty(KDRect rect)
Definition: view.cpp:39
virtual ~View()
Definition: view.cpp:13
virtual View * subviewAtIndex(int index) override
Definition: window.cpp:34
virtual void drawRect(KDContext *ctx, KDRect rect) const
Definition: view.cpp:26
Definition: point.h:6
void setSize(KDSize size)
Definition: view.cpp:120
Definition: size.h:6
KDRect m_frame
Definition: view.h:66
void redraw(bool force=false)
Definition: window.cpp:12
virtual KDSize minimalSizeForOptimalDisplay() const
Definition: view.cpp:183
constexpr KDRect KDRectZero
Definition: rect.h:70
Definition: rect.h:26
View()
Definition: view.cpp:6
Definition: view.h:23
virtual void layoutSubviews() override
Definition: window.cpp:39
View * subview(int index)
Definition: view.cpp:111
void resetSuperview()
Definition: view.cpp:22
KDRect bounds() const
Definition: view.cpp:157
KDPoint pointFromPointInView(View *view, KDPoint point)
Definition: view.cpp:153