-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample-linemap-python.cpp
139 lines (112 loc) · 3.14 KB
/
example-linemap-python.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* Line Map Example for Python Interaction.
*
* Loads dsengine.py and runs init,think,mouseclick
* Renders a linelist given as a python 2D iteratable with color.
*
*
* */
#include<dslab.h>
#include<iostream>
using namespace std;
enum {
MENU_ZOOMFIT=500,
MENU_ZOOMIN,
MENU_ZOOMOUT
};
class MyDataEngine :public DataEngine
{
private:
double theta[3];
dsOrthoZoomPan zoompan;
public:
virtual void Init()
{
cout << "Initialization" << endl;
zoompan.setMBR(0,10,0,10);
glEnable(GL_DEPTH_TEST);
wxToolBar *toolbar;
toolbar = new wxToolBar(getFrame(),-1);
toolbar->AddTool(MENU_ZOOMIN,wxT("Zoom In"),wxBitmap((const char *const *) &xpm_viewmagp));
toolbar->AddTool(MENU_ZOOMOUT,wxT("Zoom Out"),wxBitmap((const char *const *) &xpm_viewmagm));
toolbar->AddTool(MENU_ZOOMFIT,wxT("Zoom Fit"),wxBitmap((const char *const *) &xpm_viewmag1));
toolbar->AddSeparator();
toolbar->AddTool(wxID_ABOUT,wxT("About"),wxBitmap((const char *const *) &xpm_mdsg));
toolbar->Realize();
getFrame()->SetToolBar(toolbar);
}
virtual void think(double iElapsed)
{
zoompan.animate(iElapsed);
}
virtual void createMenu(wxMenu *menuDataEngine)
{
// start of from 500
menuDataEngine->Append(500,wxT("First"),wxT("Help"));
menuDataEngine->Append(501,wxT("Second"),wxT("Help2"));
}
virtual void extendViewMenu(wxMenu *menuDataEngine)
{
// start of from 500
menuDataEngine->Append(502,wxT("First View"),wxT("Help"));
menuDataEngine->Append(503,wxT("Second View"),wxT("Help2"));
DS_start_rendering();
}
virtual void handleMenu(int id)
{
switch (id)
{
case MENU_ZOOMFIT:
zoompan.zoomFitAnimated(500); // start animation here
break;
case MENU_ZOOMIN:
zoompan.zoom(1); break;
case MENU_ZOOMOUT:
zoompan.zoom(-1); break;
default:
cout << "Menu Item " << id << " ignored" << endl;
break;
}
}
virtual void beforeQuit(){
// Do some data cleanup / file sync / close
cout << "Preparing DataEngine for exit" << endl;
};
virtual void render(size_t width, size_t height)
{
zoompan.setViewport(0,0,width,height);
zoompan.glViewport();
glMatrixMode( GL_PROJECTION );
glLoadIdentity( );
zoompan.glProject();
glMatrixMode( GL_MODELVIEW );
glClearColor( 0.0, 0.0, 0.0, 0.0 );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glColor3f( 1.0, 0.0, 0.0 );
glBegin(GL_POLYGON);
glColor3f( 1.0, 1.0, 0 );
glVertex2f( 1,1 );
glVertex2f( 8,1 );
glVertex2f( 8,8 );
glEnd();
}
virtual void mouseClick(size_t x, size_t y)
{
}
virtual void mouseDragging(size_t from_x,size_t from_y, size_t to_x,size_t to_y)
{
std::pair<double,double> from = zoompan.clientProject(from_x,from_y);
std::pair<double,double> to = zoompan.clientProject(to_x,to_y);
zoompan.x -= (to.first - from.first);
zoompan.y -= (to.second - from.second);
}
virtual void mouseWheel(size_t x, size_t y, int steps) {
zoompan.fixZoom(x,y,steps);
};
};
/*Instantiate it and make it available to the library*/
MyDataEngine eng;
DataEngine *getDataEngineImplementation()
{
return (DataEngine*) ŋ
}