f8c42ee0671276abc906af6c594d104dbed8a214
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

1) /* Blinker
2)    Copyright 2011 Stefan Schuermans <stefan@blinkenarea.org>
3)    Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
4)    a blinkenarea.org project */
5) 
6) #include <string>
7) 
8) #include <BlinkenLib/BlinkenFrame.h>
9) 
10) #include "Canvas.h"
11) #include "CanvasInput.h"
12) #include "Directory.h"
13) #include "File.h"
14) #include "Position.h"
15) #include "SettingFile.h"
16) #include "Size.h"
17) #include "StreamMgr.h"
18) #include "StreamRecv.h"
19) 
20) namespace Blinker {
21) 
22) /**
23)  * @brief constructor
24)  * @param[in] canvas owning canvas
25)  * @param[in] dirBase base directory
26)  */
27) Canvas::Input::Input(Canvas &canvas, const Directory &dirBase):
28)   m_canvas(canvas),
29)   m_fileInStream(dirBase.getFile("instream")),
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

30)   m_fileSrcPos(dirBase.getFile("srcpos")),
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

31)   m_fileSize(dirBase.getFile("size")),
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

32)   m_fileDestPos(dirBase.getFile("destpos")),
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

33)   m_pInStream(NULL),
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

34)   m_haveSrcPos(false),
35)   m_haveSize(false),
36)   m_haveDestPos(false)
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

37) {
Stefan Schuermans typos in comments and docum...

Stefan Schuermans authored 12 years ago

38)   // get settings and attach to input stream
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

39)   getSrcPos();
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

40)   getSize();
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

41)   getDestPos();
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

42)   getInStream();
43) }
44) 
45) /// virtual destructor
46) Canvas::Input::~Input()
47) {
48)   // detach from input stream and release it
49)   releaseInStream();
50) }
51) 
52) /// check for update of configuration
53) void Canvas::Input::updateConfig()
54) {
55)   // input stream name file was modified -> re-get input stream
56)   if (m_fileInStream.checkModified()) {
57)     releaseInStream();
58)     getInStream();
59)   }
60) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

61)   // position/size files were modified -> re-get position/size
62)   if (m_fileSrcPos.checkModified())
63)     getSrcPos();
64)   if (m_fileSize.checkModified())
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

65)     getSize();
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

66)   if (m_fileDestPos.checkModified())
67)     getDestPos();
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

68) }
69) 
70) /**
71)  * @brief set current frame
72)  * @param[in] stream stream name
73)  * @param[in] pFrame current frame
74)  */
75) void Canvas::Input::setFrame(const std::string &stream, stBlinkenFrame *pFrame)
76) {
77)   // notify canvas to redraw
78)   m_canvas.redraw();
79) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

80)   (void)pFrame; // unused (frame fetched from stream when requested to draw)
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

81)   (void)stream; // unused
82) }
83) 
84) /**
85)  * @brief set current frame to none
86)  * @param[in] stream stream name
87)  */
88) void Canvas::Input::setNoFrame(const std::string &stream)
89) {
90)   // notify canvas to redraw
91)   m_canvas.redraw();
92) 
93)   (void)stream; // unused
94) }
95) 
96) /**
97)  * @brief draw current frame to canvas
98)  * @return if a frame was available and it was drawn
99)  */
100) bool Canvas::Input::draw()
101) {
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

102)   stBlinkenFrame *pFrame;
103) 
104)   // no destination position or no canvas -> leave
105)   if (!m_haveDestPos || !m_canvas.m_pCanvas)
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

106)     return false;
107) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

108)   // get current frame from stream (levae if no stream or no frame)
109)   if (!m_pInStream || !m_pInStream->getCurFrame(pFrame))
110)     return false;
111) 
112)   // no source position -> use top left
113)   if (!m_haveSrcPos) {
114)     m_srcPos.m_x = 0;
115)     m_srcPos.m_y = 0;
116)   }
117) 
118)   // no size -> use entire source frame
119)   //            (BlinkenLib will clip this if too large)
120)   if (!m_haveSize) {
121)     m_size.m_width = BlinkenFrameGetWidth(pFrame);
122)     m_size.m_height = BlinkenFrameGetHeight(pFrame);
123)   }
124) 
125)   // draw rectangular area to canvas
126)   BlinkenFrameCopyRect(m_canvas.m_pCanvas, m_destPos.m_y, m_destPos.m_x,
127)                        pFrame, m_srcPos.m_y, m_srcPos.m_x,
128)                        m_size.m_height, m_size.m_width);
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

129) 
130)   return true;
131) }
132) 
133) /// get input stream and attach to it
134) void Canvas::Input::getInStream()
135) {
136)   // get input stream
137)   m_fileInStream.getStr(m_nameInStream);
138)   m_pInStream = &m_canvas.m_streamMgr.refStream(m_nameInStream);
139) 
140)   // attach to input stream
141)   if (m_pInStream)
142)     m_pInStream->attach(this);
143) 
Stefan Schuermans typos in comments and docum...

Stefan Schuermans authored 12 years ago

144)   // redrawing canvas will happen automatically because stream will set frame
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

145) }
146) 
147) /// detach from input stream and release it
148) void Canvas::Input::releaseInStream()
149) {
150)   // detach from input stream
151)   if (m_pInStream)
152)     m_pInStream->detach(this);
153) 
154)   // unreference stream
155)   m_pInStream = NULL;
156)   m_canvas.m_streamMgr.unrefStream(m_nameInStream);
157) 
158)   // notify canvas to redraw
159)   m_canvas.redraw();
160) }
161) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

162) /// (re-)get position of area to copy from stream
163) void Canvas::Input::getSrcPos()
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

164) {
165)   std::string strPos;
166) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

167)   // read source position from file and parse it
168)   m_haveSrcPos = m_fileSrcPos.getStr(strPos) && m_srcPos.fromStr(strPos);
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

169) 
170)   // notify canvas to redraw
171)   m_canvas.redraw();
172) }
173) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

174) /// (re-)get size of area to copy from stream
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

175) void Canvas::Input::getSize()
176) {
177)   std::string strSize;
178) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

179)   // read size from file and parse it
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

180)   m_haveSize = m_fileSize.getStr(strSize) && m_size.fromStr(strSize);
181) 
182)   // notify canvas to redraw
183)   m_canvas.redraw();
184) }
185) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

186) /// (re-)get destination position on canvas
187) void Canvas::Input::getDestPos()
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

188) {
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

189)   std::string strPos;
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

190) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

191)   // read destination position from file and parse it
192)   m_haveDestPos = m_fileDestPos.getStr(strPos) && m_destPos.fromStr(strPos);
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

193) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

194)   // notify canvas to redraw
195)   m_canvas.redraw();