-
Notifications
You must be signed in to change notification settings - Fork 2
/
PImageCanvas.h
114 lines (94 loc) · 4.49 KB
/
PImageCanvas.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
#ifndef __PImageCanvas_h__
#define __PImageCanvas_h__
#include <Xm/Xm.h>
#include "PScrollBar.h"
#include "PListener.h"
#include "PDrawable.h"
#include "TextSpec.h"
// masks for CreateCanvas() routine
enum {
kScrollLeftMask = 1 << kScrollLeft,
kScrollRightMask = 1 << kScrollRight,
kScrollBottomMask = 1 << kScrollBottom,
kScrollAllMask = kScrollLeftMask | kScrollRightMask | kScrollBottomMask
};
enum EPrintFlags {
kPrintLandscape = 0x01
};
enum EDirtyFlags {
kDirtyNormal = 0x0001, // image requires redrawing
kDirtyPix = 0x8000 // pixmap requires redrawing
};
class PImageWindow;
struct Node;
class PImageCanvas : public PScrollHandler, public PListener {
public:
PImageCanvas(PImageWindow *owner, Widget canvas, EventMask eventMask=0);
virtual ~PImageCanvas();
void CreateCanvas(char *name, int scrollBarMask=0);
void SetCanvas(Widget canvas);
Widget GetCanvas() { return mCanvas; }
void Draw(); // called to draw image in canvas and copy to screen
void Prepare();
void SetCursor(int type);
void DrawLabel(int x,int y,ETextAlign_q align);
int IsInLabel(int x, int y);
void ShowLabel(int on);
void AllowLabel(int on);
int IsLabelOn() { return mDrawLabel; }
virtual void Listen(int message, void *dataPt);
virtual int Print(char *filename, int flags=0); // print image to postscript file
virtual void DrawSelf(); // override by derived types to perform drawing
virtual void AfterDrawing() { } // called after any drawing to screen
virtual void Resize() { SetDirty(); } // called before drawing if canvas was resized
virtual void SetScrolls() { } // set scrollbars of owner window
virtual void SetToHome(int n=0) { } // set image to home position
virtual void HandleEvents(XEvent *event) { }
virtual void SetCursorForPos(int x, int y);
virtual void Transform(Node *node, int num_nodes) { }
virtual void TransformHits() { sLastTransformHits = this; }
void SetDirty(int flag=kDirtyNormal);
int IsDirty() { return mDirty; }
int IsDirtyPix() { return mDirty & kDirtyPix; }
PImageWindow * GetOwner() { return mOwner; }
// convenience functions for accessing mDrawable
int GetScaling() { return mDrawable->GetScaling(); }
void SetForeground(int col_num) { mDrawable->SetForeground(col_num); }
void SetFont(XFontStruct *font) { mDrawable->SetFont(font); }
XFontStruct * GetFont() { return mDrawable->GetFont(); }
void SetLineWidth(float width) { mDrawable->SetLineWidth(width); }
void SetLineType(ELineType type) { mDrawable->SetLineType(type); }
void DrawSegments(XSegment *segments, int num) { mDrawable->DrawSegments(segments,num); }
void DrawLine(int x1,int y1,int x2,int y2) { mDrawable->DrawLine(x1,y1,x2,y2); }
void FillRectangle(int x,int y,int w, int h) { mDrawable->FillRectangle(x,y,w,h); }
void FillPolygon(XPoint *point, int num) { mDrawable->FillPolygon(point,num); }
void DrawString(int x, int y, char *str,ETextAlign_q align)
{ mDrawable->DrawString(x,y,str,align); }
void DrawArc(int cx,int cy,int rx,int ry,float ang1=0.0,float ang2=360.0)
{ mDrawable->DrawArc(cx,cy,rx,ry,ang1,ang2); }
void FillArc(int cx,int cy,int rx,int ry,float ang1=0.0,float ang2=360.0)
{ mDrawable->FillArc(cx,cy,rx,ry,ang1,ang2); }
protected:
int GetCanvasSize();
PImageWindow * mOwner; // owner window
Display * mDpy; // pointer to X window display
PDrawable * mDrawable; // pointer to drawable object
Widget mCanvas; // X drawing canvas
Dimension mWidth; // image width
Dimension mHeight; // image height
EventMask mEventMask; // mask for events accepted by canvas
int mDrawLabel; // flag true if label should be drawn
TextSpec * mLabelText; // pointer to label string spec (or NULL if no label)
int mLabelHeight; // pixel height for label
int mAllowLabel; // non-zero if label is allowed
int mDirty; // flag set if need redrawing
private:
Dimension mCanvasWidth; // full width of canvas (incl. label region)
Dimension mCanvasHeight; // full height of canvas (incl. label region)
static void CanvasResizeProc(Widget w, PImageCanvas *anImage, XmDrawingAreaCallbackStruct *call_data);
static void CanvasExposeProc(Widget w, PImageCanvas *anImage, XmDrawingAreaCallbackStruct *call_data);
static void CanvasMotionProc(Widget w, PImageCanvas *anImage, XEvent *event);
public:
PImageCanvas * sLastTransformHits;
};
#endif // __PImageCanvas_h__