-
Notifications
You must be signed in to change notification settings - Fork 0
/
ccc_msw.h
191 lines (174 loc) · 5.42 KB
/
ccc_msw.h
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#ifndef CCC_MSW_H
#define CCC_MSW_H
#include <string>
using namespace std;
#include <windows.h>
// avoid conflicts with Windows function names
#define Polygon CCC_WIN_Polygon
#define Ellipse CCC_WIN_Ellipse
#define Rectangle CCC_WIN_Rectangle
#include "ccc_shap.h"
/**
A conduit to a display window.
*/
class GraphicWindow
{
public:
/**
Default constructor. Constructs a window with the standard
coordinate system with corners (-10, -10) and (10, 10).
*/
GraphicWindow();
/**
Sets the coordinate system of this window.
@param x1 the minimum x-value
@param y1 the minimum y-value
@param x2 the maximum x-value
@param y2 the maximum y-value
*/
void coord(double xmin, double ymin, double xmax, double ymax);
/**
Clears this window.
*/
void clear();
/**
Displays a point on this window.
@param p the point to display (as a small circle)
@return a reference to this window
*/
GraphicWindow& operator<<(Point p);
/**
Displays a circle on this window.
@param c the circle to display
@return a reference to this window
*/
GraphicWindow& operator<<(Circle c);
/**
Displays a line on this window.
@param s the line to display
@return a reference to this window
*/
GraphicWindow& operator<<(Line s);
/**
Displays a message on this window.
@param t the message to display
@return a reference to this window
*/
GraphicWindow& operator<<(Message t);
/**
Prompts the user for a string.
@param s the prompt text
@return the string that the user entered.
*/
string get_string(string out_string);
/**
Prompts the user for an integer.
@param s the prompt text
@return the number that the user entered
*/
int get_int(const string& out_string);
/**
Prompts the user for a floating-point value.
@param s the prompt text
@return the number that the user entered
*/
double get_double(const string& out_string);
/**
Prompts the user to click on a point.
@param s the prompt text
@return the point on which the user clicked.
*/
Point get_mouse(string out_string);
/**
Opens the window.
@param hwnd the window handle
@param mainwin_hdc the device context for the main window
*/
void open(HWND hwnd, HDC mainwin_hdc);
/**
Deallocates resources for this window.
*/
void close();
/**
Repaints with the saved bitmap--use when resizing.
@param ps a pointer to the PAINTSTRUCT in WinProc
*/
void repaint(PAINTSTRUCT& ps);
void color(int r, int g, int b);
private:
/**
Scales an x-coordinate from user to display coordinates.
@param x a coordinate position in user coordinates
@return the scaled coordinate
*/
int user_to_disp_x(double x) const;
/**
Scales a y-coordinate from user to display coordinates.
@param y a coordinate position in user coordinates
@return the scaled coordinate
*/
int user_to_disp_y(double y) const;
/**
Scales an x-coordinate from display to user coordinates.
@param x a coordinate position in display coordinates
@return the scaled coordinate
*/
double disp_to_user_x(int x) const;
/**
Scales an y-coordinate from display to user coordinates.
@param y a coordinate position in display coordinates
@return the scaled coordinate
*/
double disp_to_user_y(int y) const;
/**
Displays a prompt on the status line.
@param s the prompt
*/
void statusline_prompt(string s);
/**
Plots a point.
@param x the x-coordinate of the point
@param y the y-coordinate of the point
*/
void point(double x, double y);
/**
Plots a line.
@param xfrom the x-coordinate of the starting point
@param yfrom the y-coordinate of the starting point
@param xto the x-coordinate of the ending point
@param yto the y-coordinate of the ending point
*/
void line(double xfrom, double yfrom, double xto, double yto);
/**
Plots a line.
@param x the x-coordinate of the center point
@param y the y-coordinate of the center point
@param rx the radius in x-direction
@param ry the radius in y-direction
*/
void ellipse(double x, double y, double ra, double rb);
/**
Plots text.
@param t the text string
@param x the x-coordinate of the top left corner point
@param y the y-coordinate of the top left corner point
*/
void text(string t, double x, double y);
double _user_xmin; // the user's window's logical window coords
double _user_xmax;
double _user_ymin;
double _user_ymax;
int _disp_xmax; // the physical window dimension (in pixels)
int _disp_ymax;
HWND child_hwnd;
HWND edit_hwnd;
HDC _hdc; // device context to the display
int _mlength; // length of text extent for message child window
int _elength; // length of text extent for edit child window
HDC _bitmap_hdc; // a long-lived device context
HBITMAP _hbm, _hbm_saved; // handles to the created bitmap objects
int _bitmap_xmax; // width of the bitmap (in bits)
int _bitmap_ymax; // height of the bitmap (in bits)
};
extern GraphicWindow cwin;
#endif