1 /* 2 OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira 3 */ 4 5 #include <stdio.h> 6 #include <Bitmap.h> 7 #include <Message.h> 8 #include <ScrollBar.h> 9 #include <StopWatch.h> 10 #include <Alert.h> 11 #include <MenuBar.h> 12 #include <MenuItem.h> 13 14 #include "ShowImageConstants.h" 15 #include "ShowImageView.h" 16 17 ShowImageView::ShowImageView(BRect r, const char* name, uint32 resizingMode, uint32 flags) 18 : BView(r, name, resizingMode, flags), m_pBitmap(NULL) 19 { 20 Selecting = false; 21 Selected = false; 22 PointOn = false; 23 24 SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) ); 25 } 26 27 ShowImageView::~ShowImageView() 28 { 29 delete m_pBitmap; 30 } 31 32 void ShowImageView::SetBitmap(BBitmap* pBitmap) 33 { 34 m_pBitmap = pBitmap; 35 } 36 37 void ShowImageView::AttachedToWindow() 38 { 39 FixupScrollBars(); 40 } 41 42 void ShowImageView::Draw(BRect updateRect) 43 { 44 if ( m_pBitmap ) 45 { 46 DrawBitmap( m_pBitmap, updateRect, updateRect ); 47 48 if ( Selected && PointOn ) { 49 SetDrawingMode( B_OP_INVERT /*B_OP_ALPHA */); 50 51 StrokeRect( BRect( IniPoint, EndPoint ), B_MIXED_COLORS ); 52 53 SetDrawingMode(B_OP_COPY); 54 } 55 } 56 } 57 58 void ShowImageView::FrameResized(float /* width */, float /* height */) 59 { 60 FixupScrollBars(); 61 } 62 63 void ShowImageView::MessageReceived(BMessage* msg) 64 { 65 switch (msg->what) { 66 default: 67 BView::MessageReceived(msg); 68 break; 69 } 70 } 71 72 void ShowImageView::FixupScrollBars() 73 { 74 if (! m_pBitmap) 75 return; 76 77 BRect vBds = Bounds(), bBds = m_pBitmap->Bounds(); 78 float prop; 79 float range; 80 81 BScrollBar* sb = ScrollBar(B_HORIZONTAL); 82 if (sb) { 83 range = bBds.Width() - vBds.Width(); 84 if (range < 0) range = 0; 85 prop = vBds.Width() / bBds.Width(); 86 if (prop > 1.0f) prop = 1.0f; 87 sb->SetRange(0, range); 88 sb->SetProportion(prop); 89 sb->SetSteps(10, 100); 90 } 91 sb = ScrollBar(B_VERTICAL); 92 if (sb) { 93 range = bBds.Height() - vBds.Height(); 94 if (range < 0) range = 0; 95 prop = vBds.Height() / bBds.Height(); 96 if (prop > 1.0f) prop = 1.0f; 97 sb->SetRange(0, range); 98 sb->SetProportion(prop); 99 sb->SetSteps(10, 100); 100 } 101 } 102 103 void ShowImageView::MouseDown( BPoint point ) 104 { 105 if ( Selected && SelectedRect.Contains( point ) ) { 106 return; 107 } 108 109 uint32 buttons; 110 111 GetMouse(&point, &buttons); 112 113 if ( buttons == B_PRIMARY_MOUSE_BUTTON ) { 114 115 if ( Selected ) { 116 Selected = false; 117 Invalidate( BRect( IniPoint, EndPoint ) ); 118 } 119 120 BRect rect(point, point); 121 BeginRectTracking(rect, B_TRACK_RECT_CORNER); 122 123 IniPoint = point; 124 do { 125 snooze(30 * 1000); 126 GetMouse(&point, &buttons); 127 } while ( buttons ); 128 129 EndRectTracking(); 130 131 Selected = true; 132 133 rect.SetRightBottom(point); 134 135 EndPoint = point; 136 137 SelectedRect = BRect( IniPoint, EndPoint ); 138 139 Invalidate( SelectedRect ); 140 141 PointOn = true; 142 143 BMenuItem * pMenuCopy; 144 pMenuCopy = pBar->FindItem( B_COPY ); 145 pMenuCopy->SetEnabled( true ); 146 } 147 } 148 149 void ShowImageView::MouseUp( BPoint point ) 150 { 151 } 152 153 void ShowImageView::MouseMoved( BPoint point, uint32 transit, const BMessage *message ) 154 { 155 } 156 157 void ShowImageView::Pulse(void) 158 { 159 if ( Selected ) { 160 PushState(); 161 162 PointOn = ! PointOn; 163 164 SetDrawingMode( B_OP_INVERT ); 165 166 StrokeRect( SelectedRect, B_MIXED_COLORS ); 167 168 //SetDrawingMode(B_OP_COPY); 169 PopState(); 170 } 171 } 172