3534d9ac8f9b2b25d33aa6854358ceff94f8a511
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
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

73)  * @param[in] pFrame current frame (NULL for none)
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

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 draw current frame to canvas
86)  * @return if a frame was available and it was drawn
87)  */
88) bool Canvas::Input::draw()
89) {
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

90)   stBlinkenFrame *pFrame;
91) 
92)   // no destination position or no canvas -> leave
93)   if (!m_haveDestPos || !m_canvas.m_pCanvas)
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

94)     return false;
95) 
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

96)   // get current frame from stream (leave if no stream or no frame)
97)   if (!m_pInStream)
98)     return false;
Stefan Schuermans simplified interface of get...

Stefan Schuermans authored 12 years ago

99)   pFrame = m_pInStream->getCurFrame();
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

100)   if (!pFrame)
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

101)     return false;
102) 
103)   // no source position -> use top left
104)   if (!m_haveSrcPos) {
105)     m_srcPos.m_x = 0;
106)     m_srcPos.m_y = 0;
107)   }
108) 
109)   // no size -> use entire source frame
110)   //            (BlinkenLib will clip this if too large)
111)   if (!m_haveSize) {
112)     m_size.m_width = BlinkenFrameGetWidth(pFrame);
113)     m_size.m_height = BlinkenFrameGetHeight(pFrame);
114)   }
115) 
116)   // draw rectangular area to canvas
117)   BlinkenFrameCopyRect(m_canvas.m_pCanvas, m_destPos.m_y, m_destPos.m_x,
118)                        pFrame, m_srcPos.m_y, m_srcPos.m_x,
119)                        m_size.m_height, m_size.m_width);
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

120) 
121)   return true;
122) }
123) 
124) /// get input stream and attach to it
125) void Canvas::Input::getInStream()
126) {
127)   // get input stream
128)   m_fileInStream.getStr(m_nameInStream);
129)   m_pInStream = &m_canvas.m_streamMgr.refStream(m_nameInStream);
130) 
131)   // attach to input stream
132)   if (m_pInStream)
133)     m_pInStream->attach(this);
134) 
Stefan Schuermans typos in comments and docum...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

136) }
137) 
138) /// detach from input stream and release it
139) void Canvas::Input::releaseInStream()
140) {
141)   // detach from input stream
142)   if (m_pInStream)
143)     m_pInStream->detach(this);
144) 
145)   // unreference stream
146)   m_pInStream = NULL;
147)   m_canvas.m_streamMgr.unrefStream(m_nameInStream);
148) 
149)   // notify canvas to redraw
150)   m_canvas.redraw();
151) }
152) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

155) {
156)   std::string strPos;
157) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

160) 
161)   // notify canvas to redraw
162)   m_canvas.redraw();
163) }
164) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

166) void Canvas::Input::getSize()
167) {
168)   std::string strSize;
169) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

171)   m_haveSize = m_fileSize.getStr(strSize) && m_size.fromStr(strSize);
172) 
173)   // notify canvas to redraw
174)   m_canvas.redraw();
175) }
176) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

185)   // notify canvas to redraw
186)   m_canvas.redraw();