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 AddCrossHair(); 104 void RemoveCrossHair(); 105 void SetCrossHairsShowing(bool ch1=false, bool ch2=false); 106 void CrossHairsShowing(bool*, bool*); 107 108 void PixelCount(int32* width, int32* height); 109 int32 PixelSize(); 110 bool ShowGrid(); 111 112 void StartSave(); 113 void SaveImage(entry_ref* ref, char* name, bool selectionOnly=false); 114 void SaveBits(BFile* file, const BBitmap *bitmap, char* name) const; 115 void EndSave(); 116 117 private: 118 static long MagnifyTask(void *); 119 120 bool fNeedToUpdate; 121 long fThread; // magnify thread id 122 bool fActive; // magnifying toggle 123 124 BBitmap* fImageBuf; // os buffer 125 TOSMagnify* fImageView; // os view 126 BPoint fLastLoc; 127 128 short fSelection; 129 130 bool fShowSelection; 131 BPoint fSelectionLoc; 132 133 bool fShowCrossHair1; 134 BPoint fCrossHair1; 135 bool fShowCrossHair2; 136 BPoint fCrossHair2; 137 138 TWindow* fParent; 139 140 bool fImageFrozenOnSave; 141 }; 142 143 class TMenu : public BMenu { 144 public: 145 TMenu(TWindow* mainWindow, const char *title = NULL, 146 menu_layout layout = B_ITEMS_IN_COLUMN); 147 virtual ~TMenu(); 148 149 virtual void AttachedToWindow(); 150 151 private: 152 TWindow* fMainWindow; 153 }; 154 155 class TInfoView : public BBox { 156 public: 157 TInfoView(BRect frame); 158 virtual ~TInfoView(); 159 160 virtual void AttachedToWindow(); 161 virtual void Draw(BRect updateRect); 162 virtual void FrameResized(float width, float height); 163 164 void AddMenu(); 165 void SetMagView(TMagnify* magView); 166 167 private: 168 float fFontHeight; 169 TMagnify* fMagView; 170 BMenuField* fPopUp; 171 TMenu* fMenu; 172 173 int32 fHPixelCount; 174 int32 fVPixelCount; 175 int32 fPixelSize; 176 177 rgb_color fSelectionColor; 178 179 BPoint fCH1Loc; 180 BPoint fCH2Loc; 181 182 char fInfoStr[64]; 183 char fRGBStr[64]; 184 char fCH1Str[64]; 185 char fCH2Str[64]; 186 }; 187 188 class TWindow : public BWindow { 189 public: 190 TWindow(int32 pixelCount = -1); 191 virtual ~TWindow(); 192 193 virtual void MessageReceived(BMessage* message); 194 virtual bool QuitRequested(); 195 196 void GetPrefs(int32 pixelCount = -1); 197 void SetPrefs(); 198 199 virtual void FrameResized(float width, float height); 200 virtual void ScreenChanged(BRect screenSize, color_space depth); 201 202 virtual void Minimize(bool); 203 virtual void Zoom(BPoint position, float width, float height); 204 205 void CalcViewablePixels(); 206 void GetPreferredSize(float* width, float* height); 207 208 void ResizeWindow(int32 rowCount, int32 columnCount); 209 void ResizeWindow(bool direction); 210 211 void SetGrid(bool); 212 bool ShowGrid(); 213 214 void ShowInfo(bool); 215 bool InfoIsShowing(); 216 void UpdateInfo(); 217 218 void AddCrossHair(); 219 void RemoveCrossHair(); 220 void CrossHairsShowing(bool* ch1, bool* ch2); 221 222 void PixelCount(int32* h, int32 *v); 223 224 void SetPixelSize(int32); 225 void SetPixelSize(bool); 226 int32 PixelSize(); 227 228 void ShowHelp(); 229 230 bool IsActive(); 231 232 private: 233 float fInfoHeight; 234 bool fShowInfo; 235 float fFontHeight; 236 237 bool fShowGrid; 238 239 int32 fHPixelCount; 240 int32 fVPixelCount; 241 int32 fPixelSize; 242 243 TMagnify* fFatBits; 244 TInfoView* fInfo; 245 246 BFilePanel* fSavePanel; 247 }; 248 249 class TApp : public BApplication { 250 public: 251 TApp(int32 pixelCount = -1); 252 253 virtual void MessageReceived(BMessage* message); 254 virtual void ReadyToRun(); 255 virtual void AboutRequested(); 256 }; 257 258 #endif // MAGNIFY_H 259