b6b2996b76e1b0f0e403b4be40430a445bc0873c
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

1) /* Blinker
Stefan Schuermans update copyright years

Stefan Schuermans authored 10 years ago

2)    Copyright 2011-2014 Stefan Schuermans <stefan@blinkenarea.org>
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

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"
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

14) #include "InStreamFile.h"
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

15) #include "Position.h"
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

16) #include "PositionFile.h"
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

17) #include "Size.h"
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

18) #include "SizeFile.h"
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

19) #include "StreamMgr.h"
20) #include "StreamRecv.h"
21) 
22) namespace Blinker {
23) 
24) /**
25)  * @brief constructor
26)  * @param[in] canvas owning canvas
Stefan Schuermans converted canvas module to...

Stefan Schuermans authored 12 years ago

27)  * @param[in] name name of input
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

28)  * @param[in] dirBase base directory
29)  */
Stefan Schuermans converted canvas module to...

Stefan Schuermans authored 12 years ago

30) Canvas::Input::Input(Canvas &canvas, const std::string &name,
31)                      const Directory &dirBase):
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

32)   m_canvas(canvas),
Stefan Schuermans converted canvas module to...

Stefan Schuermans authored 12 years ago

33)   m_name(name),
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

34)   m_fileInStream(dirBase.getFile("instream"), canvas.m_mgrs.m_streamMgr),
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

36)   m_fileSize(dirBase.getFile("size")),
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

38) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

39)   // set up
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

42)   getDestPos();
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

43)   m_fileInStream.setStreamRecv(this);
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

44) }
45) 
46) /// virtual destructor
47) Canvas::Input::~Input()
48) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

49)   // clean up
50)   m_fileInStream.setStreamRecv(NULL);
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

51) }
52) 
53) /// check for update of configuration
54) void Canvas::Input::updateConfig()
55) {
56)   // input stream name file was modified -> re-get input stream
57)   if (m_fileInStream.checkModified()) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

58)     m_fileInStream.update();
59)     m_canvas.redraw(); // notify canvas to redraw
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

60)   }
61) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

69) }
70) 
71) /**
72)  * @brief set current frame
73)  * @param[in] stream stream name
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

75)  */
76) void Canvas::Input::setFrame(const std::string &stream, stBlinkenFrame *pFrame)
77) {
78)   // notify canvas to redraw
79)   m_canvas.redraw();
80) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

82)   (void)stream; // unused
83) }
84) 
85) /**
86)  * @brief draw current frame to canvas
87)  * @return if a frame was available and it was drawn
88)  */
89) bool Canvas::Input::draw()
90) {
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

91)   stBlinkenFrame *pFrame;
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

92)   int destx, desty, srcx, srcy, width, height;
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

93) 
94)   // no destination position or no canvas -> leave
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

95)   if (!m_fileDestPos.m_valid || !m_canvas.m_pCanvas)
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

96)     return false;
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

97)   destx = m_fileDestPos.m_obj.m_x;
98)   desty = m_fileDestPos.m_obj.m_y;
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

99) 
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

100)   // get current frame from stream (leave if no stream or no frame)
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

101)   pFrame = m_fileInStream.getCurFrame();
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

103)     return false;
104) 
105)   // no source position -> use top left
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

106)   if (m_fileSrcPos.m_valid) {
107)     srcx = m_fileSrcPos.m_obj.m_x;
108)     srcy = m_fileSrcPos.m_obj.m_y;
109)   } else {
110)     srcx = 0;
111)     srcy = 0;
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

112)   }
113) 
114)   // no size -> use entire source frame
115)   //            (BlinkenLib will clip this if too large)
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

116)   if (m_fileSize.m_valid) {
117)     width = m_fileSize.m_obj.m_width;
118)     height = m_fileSize.m_obj.m_height;
119)   } else {
120)     width = BlinkenFrameGetWidth(pFrame);
121)     height = BlinkenFrameGetHeight(pFrame);
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

122)   }
123) 
124)   // draw rectangular area to canvas
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

125)   BlinkenFrameCopyRect(m_canvas.m_pCanvas, desty, destx,
126)                        pFrame, srcy, srcx, height, width);
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

127) 
128)   return true;
129) }
130) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

133) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

134)   // read source position from file
135)   m_fileSrcPos.update();
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

136) 
137)   // notify canvas to redraw
138)   m_canvas.redraw();
139) }
140) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

142) void Canvas::Input::getSize()
143) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

144)   // read size from file
145)   m_fileSize.update();
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

146) 
147)   // notify canvas to redraw
148)   m_canvas.redraw();
149) }
150) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

153) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

154)   // read destination position from file
155)   m_fileDestPos.update();
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

157)   // notify canvas to redraw
158)   m_canvas.redraw();