/
gui_preview.h
174 lines (150 loc) · 4.78 KB
/
gui_preview.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
/*
Copyright (C) 2009 Kai Sterker <kaisterker@linuxgames.com>
Part of the Adonthell Project http://adonthell.linuxgames.com
Adonthell is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Adonthell is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Adonthell; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* @file modeller/gui_preview.h
*
* @author Kai Sterker
* @brief Where the model is displayed and assembled
*/
#ifndef GUI_PREVIEW_H
#define GUI_PREVIEW_H
#include "mdl_renderer.h"
/**
* This shows the model as it is assembled from sprites and shapes.
* Allows to position the sprites and shapes relative to each other
* and to manipulate the size and shape of shapes.
*/
class GuiPreview
{
public:
/**
* Create new preview.
* @param drawing_area the surface to draw on
* @param shape_data gui elements for displaying shape information.
*/
GuiPreview (GtkWidget *drawing_area, GtkEntry** shape_data, GtkTreeModel *models);
/**
* Update (part of) the screen from backing pixmap.
* @param sx x coordinate
* @param sy y coordinate
* @param l length
* @param h height
*/
void draw (const int & sx, const int & sy, const int & l, const int & h);
/**
* Update size of the preview.
* @param widget widget containing the new size.
*/
void resizeSurface (GtkWidget *widget);
/**
* Update contents of the backing pixmap.
*/
void render ();
/**
* Render the given part of the preview and update screen.
* @param sx starting x offset
* @param sy starting y offset
* @param l length of the area to render
* @param h height of the area to render
*/
void render (const int & sx, const int & sy, const int & l, const int & h);
/**
* Process mouse movement over preview area.
* @param point location of the mouse pointer.
*/
void mouseMoved (const GdkPoint *point);
/**
* Modifying selected shape.
*/
//@{
/**
* Process dragging shape handles.
* @param point location of the mouse pointer.
* @param modifier whether modifier (shift) key is pressed.
*/
void handleDragged (GdkPoint *point, const bool & modifier);
/**
* Return whether a handle is currently being dragged.
* @return true if this is the case, false otherwise.
*/
bool isHandleDragged () const
{
return PrevPos != NULL;
}
/**
* Stop dragging the current handle.
*/
void stopDragging ()
{
delete PrevPos;
PrevPos = NULL;
}
//@}
/**
* Update shape from value entered into the field.
* @param entry a text entry field.
*/
void updateShape (GtkEntry *entry);
/**
* Set the model being displayed/edited.
* @param model the model being edited.
*/
void setCurModel (world::placeable_model *model);
/**
* Set the shape being displayed/edited.
* @param shape the shape being edited.
*/
void setCurShape (world::cube3 *shape);
protected:
/**
* Indicate which value will be affected by dragging a handle.
* @param handle index of the handle being dragged.
* @param highlight true to turn indicator on, false to turn indicator off.
*/
void indicateEditingField (const s_int32 & handle, const bool & highlight);
/**
* Display size and position of current shape.
*/
void updateShapeData () const;
/**
* Fill in one piece of data of the given shape.
* @param data the index into the ShapeData array.
* @param value the new value to display.
*/
void setShapeData (const u_int32 & data, const s_int32 & value) const;
private:
/// the renderer
ModelRenderer Renderer;
/// the display widget
GtkWidget *DrawingArea;
/// the fields for displaying/editing shape data
GtkEntry **ShapeData;
/// list of model parts
GtkTreeModel *ModelList;
/// the render surface
gfx::surface *Target;
/// the shape currently being edited
world::cube3 *Shape;
/// the model currently being edited
world::placeable_model *Model;
/// the currently selected handle
int SelectedHandle;
/// previous position when dragging
GdkPoint *PrevPos;
/// the position of the edit handles
GdkPoint Handles[4];
};
#endif