-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoriginalView.cpp
119 lines (92 loc) · 2.74 KB
/
originalView.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//
// originalview.cpp
//
// The code maintaining the original view of the input images
//
#include "impressionist.h"
#include "impressionistDoc.h"
#include "originalView.h"
#ifndef WIN32
#define min(a, b) ( ( (a)<(b) ) ? (a) : (b) )
#endif
OriginalView::OriginalView(int x,
int y,
int w,
int h,
const char* l)
: Fl_Gl_Window(x,y,w,h,l)
{
m_nWindowWidth = w;
m_nWindowHeight = h;
bMarker = false;
bToggleEdge = false;
}
void OriginalView::draw()
{
if(!valid())
{
glClearColor(0.7f, 0.7f, 0.7f, 1.0);
// We're only using 2-D, so turn off depth
glDisable( GL_DEPTH_TEST );
// Tell openGL to read from the front buffer when capturing
// out paint strokes
glReadBuffer( GL_FRONT );
ortho();
}
glClear( GL_COLOR_BUFFER_BIT );
if ( m_pDoc->m_ucBitmap )
{
// note that both OpenGL pixel storage and the Windows BMP format
// store pixels left-to-right, BOTTOM-to-TOP!! thus all the fiddling
// around with startrow.
m_nWindowWidth=w();
m_nWindowHeight=h();
int drawWidth, drawHeight;
GLvoid* bitstart;
// we are not using a scrollable window, so ignore it
Point scrollpos; // = GetScrollPosition();
scrollpos.x=scrollpos.y=0;
drawWidth = min( m_nWindowWidth, m_pDoc->m_nWidth );
drawHeight = min( m_nWindowHeight, m_pDoc->m_nHeight );
int startrow = m_pDoc->m_nHeight - (scrollpos.y + drawHeight);
if ( startrow < 0 )
startrow = 0;
if(this->bToggleEdge){
bitstart = m_pDoc->m_ucEdgeImage + 3 * ((m_pDoc->m_nWidth * startrow) + scrollpos.x);
} else {
bitstart = m_pDoc->m_ucBitmap + 3 * ((m_pDoc->m_nWidth * startrow) + scrollpos.x);}
// just copy image to GLwindow conceptually
glRasterPos2i( 0, m_nWindowHeight - drawHeight );
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
glPixelStorei( GL_UNPACK_ROW_LENGTH, m_pDoc->m_nWidth );
glDrawBuffer( GL_BACK );
glDrawPixels( drawWidth, drawHeight, GL_RGB, GL_UNSIGNED_BYTE, bitstart );}
if(bMarker)
drawMarker();
glFlush();
}
void OriginalView::refresh()
{
redraw();
}
void OriginalView::resizeWindow(int width,
int height)
{
resize(x(), y(), width, height);
}
void OriginalView::setMarker(bool bMarker, Point source){
this->bMarker = bMarker;
this->marker = source;}
void OriginalView::drawMarker(){
float dX = 5;
float dY = 5;
glBegin( GL_LINES );
glColor3f(1.0, 0.0, 0.0);
glVertex2d( marker.x + dX, marker.y + dY);
glVertex2d( marker.x - dX, marker.y - dY);
glVertex2d( marker.x - dX, marker.y + dY);
glVertex2d( marker.x + dX, marker.y - dY);
glEnd();}
void OriginalView::toggleEdge(){
this->bToggleEdge = !this->bToggleEdge;
this->refresh();}