xref: /haiku/src/apps/magnify/Magnify.h (revision 239222b2369c39dc52df52b0a7cdd6cc0a91bc92)
1 /*
2  * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Copyright 1999, Be Incorporated.   All Rights Reserved.
6  * This file may be used under the terms of the Be Sample Code License.
7  */
8 #ifndef MAGNIFY_H
9 #define MAGNIFY_H
10 
11 
12 #include <Application.h>
13 #include <Box.h>
14 #include <FilePanel.h>
15 #include <MenuBar.h>
16 #include <View.h>
17 #include <Window.h>
18 
19 
20 class TMagnify;
21 class TWindow;
22 
23 class TOSMagnify : public BView {
24 	public:
25 						TOSMagnify(BRect, TMagnify* parent, color_space space);
26 		virtual			~TOSMagnify();
27 
28 		void			InitObject();
29 
30 		virtual void	FrameResized(float width, float height);
31 		void			SetSpace(color_space space);
32 
33 		void			Resize(int32 width, int32 height);
34 
35 		bool			CreateImage(BPoint, bool force=false);
36 		bool			CopyScreenRect(BRect);
37 
38 		void			DrawGrid(int32 width, int32 height,
39 							BRect dest, int32 pixelSize);
40 		void			DrawSelection();
41 
42 		rgb_color		ColorAtSelection();
43 
44 		BBitmap*		Bitmap() { return fBitmap; }
45 
46 	private:
47 		color_space		fColorSpace;
48 		char*			fOldBits;
49 		long			fBytesPerPixel;
50 
51 		TMagnify*		fParent;
52 		BBitmap*		fBitmap;
53 		BBitmap*		fPixel;
54 		BView*			fPixelView;
55 };
56 
57 class TMagnify : public BView {
58 	public:
59 						TMagnify(BRect, TWindow*);
60 		virtual			~TMagnify();
61 
62 		void			InitBuffers(int32 hPixelCount, int32 vPixelCount,
63 							int32 pixelSize, bool showGrid);
64 
65 		virtual void	AttachedToWindow();
66 		virtual void	Draw(BRect);
67 
68 		virtual void	KeyDown(const char *bytes, int32 numBytes);
69 		virtual void	FrameResized(float, float);
70 		virtual void	MouseDown(BPoint where);
71 		virtual void	ScreenChanged(BRect bounds, color_space cs);
72 		virtual void	WindowActivated(bool);
73 
74 		void			SetSelection(bool state);
75 		void			MoveSelection(int32 x, int32 y);
76 		void			MoveSelectionTo(int32 x, int32 y);
77 		void			ShowSelection();
78 
79 		short 			Selection();
80 		bool			SelectionIsShowing();
81 		void			SelectionLoc(float* x, float* y);
82 		void			SetSelectionLoc(float, float);
83 		rgb_color		SelectionColor();
84 
85 		void			CrossHair1Loc(float* x, float* y);
86 		void			CrossHair2Loc(float* x, float* y);
87 		BPoint			CrossHair1Loc();
88 		BPoint			CrossHair2Loc();
89 
90 		void			NudgeMouse(float x, float y);
91 
92 		void			Update(bool force);
93 		bool			NeedToUpdate();
94 		void			SetUpdate(bool);
95 
96 		void			CopyImage();
97 
98 		long			ThreadID() { return fThread; }
99 
100 		void			MakeActive(bool);
101 		bool			Active() { return fActive; }
102 
103 		void			MakeSticked(bool);
104 		bool			Sticked() const { return fStickCoordinates; }
105 
106 		void			AddCrossHair();
107 		void			RemoveCrossHair();
108 		void			SetCrossHairsShowing(bool ch1=false, bool ch2=false);
109 		void			CrossHairsShowing(bool*, bool*);
110 
111 		void			PixelCount(int32* width, int32* height);
112 		int32 			PixelSize();
113 		bool			ShowGrid();
114 
115 		void			StartSave();
116 		void			SaveImage(entry_ref* ref, char* name, bool selectionOnly=false);
117 		void 			SaveBits(BFile* file, const BBitmap *bitmap,
118 							const char* name) const;
119 		void			EndSave();
120 
121 	private:
122 		static long		MagnifyTask(void *);
123 
124 		bool			fNeedToUpdate;
125 		long			fThread;				//	magnify thread id
126 		bool			fActive;				//	magnifying toggle
127 
128 		BBitmap*		fImageBuf;				// os buffer
129 		TOSMagnify*		fImageView;				// os view
130 		BPoint			fLastLoc;
131 
132 		short			fSelection;
133 
134 		bool			fShowSelection;
135 		BPoint			fSelectionLoc;
136 
137 		bool			fShowCrossHair1;
138 		BPoint			fCrossHair1;
139 		bool			fShowCrossHair2;
140 		BPoint			fCrossHair2;
141 
142 		TWindow*		fParent;
143 
144 		bool			fImageFrozenOnSave;
145 		bool			fStickCoordinates;
146 };
147 
148 class TMenu : public BMenu {
149 	public:
150 						TMenu(TWindow* mainWindow, const char *title = NULL,
151 							menu_layout layout = B_ITEMS_IN_COLUMN);
152 		virtual			~TMenu();
153 
154 		virtual void	AttachedToWindow();
155 
156 	private:
157 		TWindow*		fMainWindow;
158 };
159 
160 class TInfoView : public BBox {
161 	public:
162 						TInfoView(BRect frame);
163 		virtual			~TInfoView();
164 
165 		virtual void	AttachedToWindow();
166 		virtual void	Draw(BRect updateRect);
167 		virtual void	FrameResized(float width, float height);
168 
169 		void			AddMenu();
170 		void			SetMagView(TMagnify* magView);
171 
172 	private:
173 		float	 		fFontHeight;
174 		TMagnify*		fMagView;
175 		BMenuField*	 	fPopUp;
176 		TMenu*			fMenu;
177 
178 		int32 			fHPixelCount;
179 		int32 			fVPixelCount;
180 		int32			fPixelSize;
181 
182 		rgb_color		fSelectionColor;
183 
184 		BPoint			fCH1Loc;
185 		BPoint			fCH2Loc;
186 
187 		char			fInfoStr[64];
188 		char			fRGBStr[64];
189 		char			fCH1Str[64];
190 		char			fCH2Str[64];
191 };
192 
193 class TWindow : public BWindow {
194 	public:
195 						TWindow(int32 pixelCount = -1);
196 		virtual			~TWindow();
197 
198 		virtual void	MessageReceived(BMessage* message);
199 		virtual bool	QuitRequested();
200 
201 		void			GetPrefs(int32 pixelCount = -1);
202 		void			SetPrefs();
203 
204 		virtual void	FrameResized(float width, float height);
205 		virtual void	ScreenChanged(BRect screenSize, color_space depth);
206 
207 		virtual void	Minimize(bool);
208 		virtual void	Zoom(BPoint position, float width, float height);
209 
210 		void			CalcViewablePixels();
211 		void			GetPreferredSize(float* width, float* height);
212 
213 		void			ResizeWindow(int32 rowCount, int32 columnCount);
214 		void			ResizeWindow(bool direction);
215 
216 		void			SetGrid(bool);
217 		bool			ShowGrid();
218 
219 		void			ShowInfo(bool);
220 		bool			InfoIsShowing();
221 		void			UpdateInfo();
222 
223 		void			AddCrossHair();
224 		void			RemoveCrossHair();
225 		void			CrossHairsShowing(bool* ch1, bool* ch2);
226 
227 		void			PixelCount(int32* h, int32 *v);
228 
229 		void			SetPixelSize(int32);
230 		void			SetPixelSize(bool);
231 		int32			PixelSize();
232 
233 		void			ShowHelp();
234 
235 		bool			IsActive();
236 
237 	private:
238 		float			fInfoHeight;
239 		bool			fShowInfo;
240 		float 			fFontHeight;
241 
242 		bool			fShowGrid;
243 
244 		int32			fHPixelCount;
245 		int32			fVPixelCount;
246 		int32	 		fPixelSize;
247 
248 		TMagnify*		fFatBits;
249 		TInfoView*		fInfo;
250 
251 		BFilePanel*		fSavePanel;
252 };
253 
254 class TApp : public BApplication {
255 	public:
256 						TApp(int32 pixelCount = -1);
257 
258 		virtual void	MessageReceived(BMessage* message);
259 		virtual void	ReadyToRun();
260 		virtual void	AboutRequested();
261 };
262 
263 #endif	// MAGNIFY_H
264