1 /* 2 * Copyright 2003-2006, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Fernando Francisco de Oliveira 7 * Michael Wilber 8 * Michael Pfeiffer 9 */ 10 #ifndef SHOW_IMAGE_VIEW_H 11 #define SHOW_IMAGE_VIEW_H 12 13 14 #include "Filter.h" 15 #include "ShowImageUndo.h" 16 17 #include <Bitmap.h> 18 #include <Entry.h> 19 #include <NodeInfo.h> 20 #include <String.h> 21 #include <TranslatorRoster.h> 22 #include <View.h> 23 24 25 // delay scaling operation, so that a sequence of zoom in/out operations works smoother 26 #define DELAYED_SCALING 1 27 // width of the black border stroked arround the bitmap 28 #define PEN_SIZE 1.0f 29 30 class ShowImageView : public BView { 31 public: 32 ShowImageView(BRect rect, const char *name, uint32 resizingMode, 33 uint32 flags); 34 virtual ~ShowImageView(); 35 36 virtual void AttachedToWindow(); 37 virtual void Draw(BRect updateRect); 38 virtual void FrameResized(float width, float height); 39 virtual void MouseDown(BPoint point); 40 virtual void MouseMoved(BPoint point, uint32 state, const BMessage *message); 41 virtual void MouseUp(BPoint point); 42 virtual void KeyDown(const char *bytes, int32 numBytes); 43 virtual void Pulse(); 44 45 virtual void MessageReceived(BMessage *message); 46 47 void SetTrackerMessenger(const BMessenger& trackerMessenger); 48 status_t SetImage(const entry_ref *ref); 49 const entry_ref* Image() const { return &fCurrentRef; } 50 51 void SaveToFile(BDirectory* dir, const char* name, BBitmap* bitmap, 52 const translation_format* format); 53 void SetDither(bool dither); 54 bool GetDither() const { return fDither; } 55 void SetShowCaption(bool show); 56 void SetShrinkToBounds(bool enable); 57 bool GetShrinkToBounds() const { return fShrinkToBounds; } 58 void SetZoomToBounds(bool enable); 59 bool GetZoomToBounds() const { return fZoomToBounds; } 60 void SetBorder(bool hasBorder); 61 bool HasBorder() const { return fHasBorder; } 62 void SetAlignment(alignment horizontal, vertical_alignment vertical); 63 BBitmap *GetBitmap(); 64 void GetName(BString *name); 65 void GetPath(BString *name); 66 void FlushToLeftTop(); 67 void SetScaleBilinear(bool b); 68 bool GetScaleBilinear() { return fScaleBilinear; } 69 70 void FixupScrollBar(orientation o, float bitmapLength, float viewLength); 71 void FixupScrollBars(); 72 73 int32 CurrentPage(); 74 int32 PageCount(); 75 76 void Undo(); 77 void Cut(); 78 void Paste(); 79 void SelectAll(); 80 void ClearSelection(); 81 82 void CopySelectionToClipboard(); 83 84 void FirstPage(); 85 void LastPage(); 86 void NextPage(); 87 void PrevPage(); 88 void GoToPage(int32 page); 89 bool NextFile(); 90 bool PrevFile(); 91 bool HasNextFile(); 92 bool HasPrevFile(); 93 void SetSlideShowDelay(float seconds); 94 float GetSlideShowDelay() const { return fSlideShowDelay / 10.0; } 95 bool SlideShowStarted() const { return fSlideShow; } 96 void StartSlideShow(); 97 void StopSlideShow(); 98 void SetZoom(float zoom); 99 void ZoomIn(); 100 void ZoomOut(); 101 102 // Image manipulation 103 void Rotate(int degree); // 90 and 270 only 104 void Flip(bool vertical); 105 void Invert(); 106 107 void SetIcon(bool clear); 108 109 private: 110 ShowImageUndo fUndo; 111 enum image_orientation { 112 k0, // 0 113 k90, // 1 114 k180, // 2 115 k270, // 3 116 k0V, // 4 117 k90V, // 5 118 k0H, // 6 119 k270V, // 7 120 kNumberOfOrientations, 121 }; 122 void InitPatterns(); 123 void RotatePatterns(); 124 void RemoveSelection(bool bToClipboard); 125 bool HasSelection() { return fHasSelection; } 126 void SetHasSelection(bool bHasSelection); 127 void AnimateSelection(bool a); 128 void Notify(const char* status); 129 void AddToRecentDocuments(); 130 void AddWhiteRect(BRect &rect); 131 void GetMergeRects(BBitmap *merge, BRect selection, BRect &srcBits, BRect &destRect); 132 void GetSelMergeRects(BRect &srcBits, BRect &destRect); 133 status_t SetSelection(const entry_ref *pref, BPoint point); 134 status_t PasteBitmap(BBitmap *bitmap, BPoint point); 135 void MergeWithBitmap(BBitmap *merge, BRect selection); 136 void MergeSelection(); 137 void DeleteScaler(); 138 void DeleteBitmap(); 139 void DeleteSelBitmap(); 140 int32 BytesPerPixel(color_space cs) const; 141 void CopyPixel(uchar* dest, int32 destX, int32 destY, int32 destBPR, 142 uchar* src, int32 x, int32 y, int32 bpr, int32 bpp); 143 void InvertPixel(int32 x, int32 y, uchar* dest, int32 destBPR, uchar* src, 144 int32 bpr, int32 bpp); 145 void DoImageOperation(enum ImageProcessor::operation op, bool quiet = false); 146 void UserDoImageOperation(enum ImageProcessor::operation op, bool quiet = false); 147 BRect AlignBitmap(); 148 void Setup(BRect r); 149 BPoint ImageToView(BPoint p) const; 150 BPoint ViewToImage(BPoint p) const; 151 BRect ImageToView(BRect r) const; 152 bool IsImage(const entry_ref* pref); 153 static int CompareEntries(const void* a, const void* b); 154 void FreeEntries(BList* entries); 155 void SetTrackerSelectionToCurrent(); 156 bool FindNextImageByDir(entry_ref *in_current, entry_ref *out_image, 157 bool next, bool rewind); 158 bool FindNextImage(entry_ref *in_current, entry_ref *out_image, 159 bool next, bool rewind); 160 bool ShowNextImage(bool next, bool rewind); 161 bool FirstFile(); 162 void ConstrainToImage(BPoint &point); 163 void ConstrainToImage(BRect &rect); 164 BBitmap* CopyFromRect(BRect srcRect); 165 BBitmap* CopySelection(uchar alpha = 255, bool imageSize = true); 166 bool AddSupportedTypes(BMessage* msg, BBitmap* bitmap); 167 void BeginDrag(BPoint sourcePoint); 168 void SendInMessage(BMessage* msg, BBitmap* bitmap, translation_format* format); 169 bool OutputFormatForType(BBitmap* bitmap, const char* type, 170 translation_format* format); 171 void HandleDrop(BMessage* msg); 172 void MoveImage(); 173 uint32 GetMouseButtons(); 174 void UpdateSelectionRect(BPoint point, bool final); 175 void DrawBorder(BRect border); 176 void LayoutCaption(BFont &font, BPoint &textPos, BRect &background); 177 void DrawCaption(); 178 void UpdateCaption(); 179 void DrawSelectionBox(); 180 Scaler* GetScaler(BRect rect); 181 void DrawImage(BRect rect); 182 float LimitToRange(float v, orientation o, bool absolute); 183 void ScrollRestricted(float x, float y, bool absolute); 184 void ScrollRestrictedTo(float x, float y); 185 void ScrollRestrictedBy(float x, float y); 186 void MouseWheelChanged(BMessage* msg); 187 void ShowPopUpMenu(BPoint screen); 188 void SettingsSetBool(const char* name, bool value); 189 void SetIcon(bool clear, icon_size which); 190 void ToggleSlideShow(); 191 void ExitFullScreen(); 192 193 BMessenger fTrackerMessenger; // of the window that this was launched from 194 entry_ref fCurrentRef; // of the image 195 bool fDither; // dither the image 196 int32 fDocumentIndex; // of the image in the file 197 int32 fDocumentCount; // number of images in the file 198 BBitmap *fBitmap; // the original image 199 BBitmap *fDisplayBitmap; 200 // the image to be displayed 201 // (== fBitmap if the bitmap can be displayed as is) 202 BBitmap *fSelBitmap; // the bitmap in the selection 203 float fZoom; // factor to be used to display the image 204 bool fScaleBilinear; // use bilinear scaling? 205 Scaler* fScaler; // holds the scaled image if bilinear scaling is enabled 206 bool fShrinkToBounds; 207 bool fZoomToBounds; 208 bool fShrinkOrZoomToBounds; 209 bool fHasBorder; // should the image have a border? 210 alignment fHAlignment; // horizontal alignment (left and centered only) 211 vertical_alignment fVAlignment; // vertical alignment (left and centered only) 212 float fLeft; // the origin of the image in the view 213 float fTop; 214 float fScaleX; // to convert image from/to view coordinates 215 float fScaleY; 216 bool fMovesImage; // is the image being moved with the mouse 217 bool fMakesSelection; // is a selection being made 218 BPoint fFirstPoint; // first point in image space of selection 219 bool fAnimateSelection; // marching ants 220 bool fHasSelection; // is fSelectionRect valid 221 BRect fSelectionRect; // the current location of the selection rectangle 222 BRect fCopyFromRect; 223 // the portion of the background bitmap the selection is made from 224 pattern fPatternUp, fPatternDown, fPatternLeft, fPatternRight; 225 226 bool fSlideShow; // is slide show enabled? 227 int fSlideShowDelay; // in pulse rate units 228 int fSlideShowCountDown; // shows next image if it reaches zero 229 #if DELAYED_SCALING 230 int fScalingCountDown; 231 #endif 232 233 bool fShowCaption; // display caption? 234 BString fCaption; // caption text 235 236 bool fInverted; 237 238 bool fShowingPopUpMenu; 239 240 enum image_orientation fImageOrientation; 241 static enum image_orientation fTransformation[ 242 ImageProcessor::kNumberOfAffineTransformations][kNumberOfOrientations]; 243 }; 244 245 #endif // SHOW_IMAGE_VIEW_H 246