-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPImageCanvas.h
137 lines (115 loc) · 6.75 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//==============================================================================
// File: PImageCanvas.h
//
// Copyright (c) 2017, Phil Harvey, Queen's University
//==============================================================================
#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,
kDirtyCursor = 0x4000,
kDirtyPix = 0x8000
};
const int kTimerEvent = 999; // bogus event generated by our timer
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; }
void ArmTimer(unsigned millisec=300);
void ResetTimer();
// convenience functions for accessing mDrawable
int GetScaling() { return mDrawable->GetScaling(); }
void SetForeground(int col_num, int a=0xffff) { mDrawable->SetForeground(col_num,a); }
void SetFont(XFontStruct *font) { mDrawable->SetFont(font); }
int GetTextWidth(char *str) { return mDrawable->GetTextWidth(str); }
#ifdef ANTI_ALIAS
void SetFont(XftFont *font) { mDrawable->SetFont(font); }
XftFont * GetXftFont() { return mDrawable->GetXftFont(); }
int IsSmoothText() { return mDrawable->IsSmoothText(); }
#endif
XFontStruct * GetFont() { return mDrawable->GetFont(); }
int GetFontAscent() { return mDrawable->GetFontAscent(); }
int GetFontDescent() { return mDrawable->GetFontDescent(); }
void SetLineWidth(float width) { mDrawable->SetLineWidth(width); }
void SetLineType(ELineType type) { mDrawable->SetLineType(type); }
void DrawSegments(XSegment *segments, int num, int smooth=1)
{ mDrawable->DrawSegments(segments,num,smooth); }
void DrawPoint(int x, int y) { mDrawable->DrawPoint(x,y); }
void DrawLine(int x1,int y1,int x2,int y2) { mDrawable->DrawLine(x1,y1,x2,y2); }
void DrawRectangle(int x,int y,int w, int h) { mDrawable->DrawRectangle(x,y,w,h); }
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
XtIntervalId mTimer; // interval timer
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__