18 #ifndef SELECTIONAREA_H_ 19 #define SELECTIONAREA_H_ 22 #define _USE_MATH_DEFINES 30 #define SELECTIONAREA_DEFAULT_BOX_DIMENSION 100. 56 #ifdef PIXMAP_ORIG_VER 57 gdk_cairo_set_source_pixmap(cr, pixmap, 0., 0.);
59 cairo_set_source_surface(cr,
surface, 0., 0.);
77 cairo_t *cr=gdk_cairo_create(
getWindow());
87 movingBox.
setXY(x-width/2., y-height/2.);
101 cairo_t *cr=gdk_cairo_create(
getWindow());
106 movingBox.
setXY(x-width/2., y-height/2.);
112 staticBox.
setXY(x-width/2., y-height/2.);
136 int x=(int)fabs((
float)staticBox.
getX()-xIn);
137 int y=(int)fabs((
float)staticBox.
getY()-yIn);
138 if (constrainAspectRatio){
139 float hyp=sqrt(pow((
float)staticBox.
getX()-xIn,2.)+pow((
float)staticBox.
getY()-yIn,2.));
140 float hypOrig=sqrt(x*x+y*y);
141 float factor=hyp/hypOrig;
142 cout<<
"hyp "<<hyp<<
" hypOrig"<<hypOrig<<
" factor "<<factor<<endl;
143 cout<<
"old x,y "<<x<<
','<<y<<
'\t'<<
"new x,y ";
144 x=(int)((
float)x*factor);
145 y=(int)((
float)y*factor);
146 cout<<x<<
','<<y<<endl;
150 if (!constrainAspectRatio)
158 cairo_t *cr=gdk_cairo_create(
getWindow());
161 movingBox.
setXY(0.-width, 0.-height);
171 constrainAspectRatio=
false;
176 staticSurface= cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
177 movingSurface= cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
191 movingSurface=staticSurface=NULL;
192 init(boxWidth, boxHeight);
198 cairo_surface_destroy(staticSurface);
201 cairo_surface_destroy(movingSurface);
228 getSize(rect.width, rect.height);
232 gdk_window_invalidate_rect(
getWindow(), &rect,
true);
238 cairo_t *cr=gdk_cairo_create(
getWindow());
250 if (constrainAspectRatio)
251 rect.height=(int)((
float)movingBox.
getHeight()/(float)movingBox.
getWidth()*(float)width);
255 if (constrainAspectRatio)
256 rect.height=(int)((
float)staticBox.
getHeight()/(float)staticBox.
getWidth()*(float)width);
262 getSize(rect.width, rect.height);
263 gdk_window_invalidate_rect(
getWindow(), &rect,
true);
273 if (constrainAspectRatio)
274 rect.width=(int)((
float)movingBox.
getWidth()/(float)movingBox.
getHeight()*(float)height);
278 if (constrainAspectRatio)
279 rect.width=(int)((
float)staticBox.
getWidth()/(float)staticBox.
getHeight()*(float)height);
285 getSize(rect.width, rect.height);
286 gdk_window_invalidate_rect(
getWindow(), &rect,
true);
295 if (width>0 || height>0) {
298 if (constrainAspectRatio)
299 rect.height=(int)((
float)movingBox.
getHeight()/(float)movingBox.
getWidth()*(float)width);
303 if (constrainAspectRatio)
304 rect.height=(int)((
float)staticBox.
getHeight()/(float)staticBox.
getWidth()*(float)width);
312 if (constrainAspectRatio)
313 rect.width=(int)((
float)movingBox.
getWidth()/(float)movingBox.
getHeight()*(float)height);
317 if (constrainAspectRatio)
318 rect.width=(int)((
float)staticBox.
getWidth()/(float)staticBox.
getHeight()*(float)height);
325 getSize(rect.width, rect.height);
326 gdk_window_invalidate_rect(
getWindow(), &rect,
true);
334 constrainAspectRatio=kAR;
342 staticBox.
setXY(x, y);
345 getSize(rect.width, rect.height);
346 gdk_window_invalidate_rect(
getWindow(), &rect,
true);
350 #endif // SELECTIONAREA_H_
void keepAspectRatio(bool kAR)
void centerStaticBox(void)
virtual void reDrawBoxes(cairo_t *cr)
void setWidthHeight(int widthIn, int heightIn)
bool constrainAspectRatio
If set, then retain the aspect ratio when setting the width or height.
cairo_surface_t * movingSurface
The original pixmap rectangle for the moving box.
ColourLineSpec staticColour
The colour of the static button clicked box.
virtual void reSize(GtkWidget *widget, gdouble xIn, gdouble yIn)
void setBoxHeights(int height)
ColourLineSpec movingColour
The colour of the static button clicked box.
void init(float w, float h)
CairoBox movingBox
The box which highlights the current hover point.
#define SELECTIONAREA_DEFAULT_BOX_DIMENSION
The default width/height of the box to draw.
virtual void move(GtkWidget *widget, gdouble x, gdouble y)
void setBoxsWidthHeight(int width, int height)
cairo_surface_t * surface
The backing surface for the drawing area.
CairoBox staticBox
The box which is drawn on the mouse click.
virtual void leaveEvent()
void clearMovingBox(cairo_t *cr)
void clearBoxes(cairo_t *cr)
Reraw the backing pixmap as appropriate.
void draw(cairo_t *cr, float xBase, float yBase, float w, float h, bool fill)
SelectionArea()
Constructor.
void setBoxWidths(int width)
ColourLineSpec backgroundColour
The colour of the background.
virtual void erase(GtkWidget *widget, gdouble x, gdouble y)
void boxSettings(float xBase, float yBase, float w, float h, bool fill)
CairoBox getStaticBox(void)
void setStaticXY(float x, float y)
cairo_surface_t * staticSurface
The original pixmap rectangle for the static box.
void setXY(float xBase, float yBase)
virtual void draw(GtkWidget *widget, gdouble x, gdouble y)
SelectionArea(float boxWidth, float boxHeight)
encapsulates a method to specify colour and line or point plotting This class tries to encapsulate oc...
virtual ~SelectionArea()
Destructor.