Ticket #7394: 0001-Fix-7394.-Add-Zoom-level-to-StatusBar.-Improve-graph.patch
File 0001-Fix-7394.-Add-Zoom-level-to-StatusBar.-Improve-graph.patch, 12.3 KB (added by , 9 years ago) |
---|
-
src/apps/showimage/ShowImageStatusView.cpp
From 02f215e9f222dbdbf923677b310c30c837fccb04 Mon Sep 17 00:00:00 2001 From: Janus <janus2@ymail.com> Date: Sun, 1 Mar 2015 13:38:59 +0000 Subject: [PATCH] Fix #7394. Add Zoom level to StatusBar. Improve graphics and resize the StatusBar to best fit --- src/apps/showimage/ShowImageStatusView.cpp | 194 ++++++++++++++++++++++------- src/apps/showimage/ShowImageStatusView.h | 27 +++- src/apps/showimage/ShowImageView.cpp | 4 + src/apps/showimage/ShowImageWindow.cpp | 55 ++------ src/apps/showimage/ShowImageWindow.h | 2 +- 5 files changed, 183 insertions(+), 99 deletions(-) diff --git a/src/apps/showimage/ShowImageStatusView.cpp b/src/apps/showimage/ShowImageStatusView.cpp index 0092b4e..319bab1 100644
a b 11 11 12 12 #include "ShowImageStatusView.h" 13 13 14 #include <ControlLook.h> 14 15 #include <Entry.h> 15 16 #include <MenuItem.h> 16 17 #include <Path.h> 17 18 #include <PopUpMenu.h> 19 #include <ScrollView.h> 18 20 19 21 #include <tracker_private.h> 20 22 #include "DirMenu.h" … … 22 24 #include "ShowImageView.h" 23 25 #include "ShowImageWindow.h" 24 26 27 const float kHorzSpacing = 5.f; 25 28 26 ShowImageStatusView::ShowImageStatusView(BRect rect, const char* name, 27 uint32 resizingMode, uint32 flags) 29 ShowImageStatusView::ShowImageStatusView(BScrollView* scrollView) 28 30 : 29 BView(rect, name, resizingMode, flags) 31 BView(BRect(), "statusview", B_FOLLOW_BOTTOM | B_FOLLOW_LEFT, B_WILL_DRAW), 32 fScrollView(scrollView), 33 fPreferredSize(0.0, 0.0) 30 34 { 31 SetViewColor(B_TRANSPARENT_32_BIT); 32 SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 33 SetHighColor(0, 0, 0, 255); 34 35 BFont font; 36 GetFont(&font); 37 font.SetSize(10.0); 38 SetFont(&font); 35 memset(fCellWidth, 0, sizeof(fCellWidth)); 36 } 37 38 39 void 40 ShowImageStatusView::AttachedToWindow() 41 { 42 SetFont(be_plain_font); 43 SetFontSize(10.0); 44 45 BScrollBar* scrollBar = fScrollView->ScrollBar(B_HORIZONTAL); 46 MoveTo(0.0, scrollBar->Frame().top); 47 rgb_color color = B_TRANSPARENT_COLOR; 48 BView* parent = Parent(); 49 if (parent != NULL) 50 color = parent->ViewColor(); 51 52 if (color == B_TRANSPARENT_COLOR) 53 color = ui_color(B_PANEL_BACKGROUND_COLOR); 54 55 SetViewColor(color); 56 57 ResizeToPreferred(); 58 } 59 60 61 void 62 ShowImageStatusView::GetPreferredSize(float* _width, float* _height) 63 { 64 _ValidatePreferredSize(); 65 66 if (_width) 67 *_width = fPreferredSize.width; 68 69 if (_height) 70 *_height = fPreferredSize.height; 71 } 72 73 74 void 75 ShowImageStatusView::ResizeToPreferred() 76 { 77 float width, height; 78 GetPreferredSize(&width, &height); 79 80 if (Bounds().Width() > width) 81 width = Bounds().Width(); 82 83 BView::ResizeTo(width, height); 39 84 } 40 85 41 86 42 87 void 43 88 ShowImageStatusView::Draw(BRect updateRect) 44 89 { 45 rgb_color darkShadow = tint_color(LowColor(), B_DARKEN_2_TINT); 46 rgb_color shadow = tint_color(LowColor(), B_DARKEN_1_TINT); 47 rgb_color light = tint_color(LowColor(), B_LIGHTEN_MAX_TINT); 48 49 BRect b(Bounds()); 50 51 BeginLineArray(5); 52 AddLine(BPoint(b.left, b.top), 53 BPoint(b.right, b.top), darkShadow); 54 b.top += 1.0; 55 AddLine(BPoint(b.left, b.top), 56 BPoint(b.right, b.top), light); 57 AddLine(BPoint(b.right, b.top + 1.0), 58 BPoint(b.right, b.bottom), shadow); 59 AddLine(BPoint(b.right - 1.0, b.bottom), 60 BPoint(b.left + 1.0, b.bottom), shadow); 61 AddLine(BPoint(b.left, b.bottom), 62 BPoint(b.left, b.top + 1.0), light); 63 EndLineArray(); 64 65 b.InsetBy(1.0, 1.0); 66 67 // Truncate and layout text 68 BString truncated(fText); 69 BFont font; 70 GetFont(&font); 71 font.TruncateString(&truncated, B_TRUNCATE_MIDDLE, b.Width() - 4.0); 72 font_height fh; 73 font.GetHeight(&fh); 74 75 FillRect(b, B_SOLID_LOW); 76 SetDrawingMode(B_OP_OVER); 77 DrawString(truncated.String(), BPoint(b.left + 2.0, 78 floorf(b.top + b.Height() / 2.0 + fh.ascent / 2.0))); 90 if (fPreferredSize.width <= 0) 91 return; 92 93 if (be_control_look != NULL) { 94 BRect bounds(Bounds()); 95 be_control_look->DrawMenuBarBackground(this, 96 bounds, updateRect, ViewColor()); 97 } 98 99 BRect bounds(Bounds()); 100 rgb_color highColor = HighColor(); 101 SetHighColor(tint_color(ViewColor(), B_DARKEN_2_TINT)); 102 StrokeLine(bounds.LeftTop(), bounds.RightTop()); 103 104 float x = bounds.left; 105 for (size_t i = 0; i < kStatusCellCount - 1; i++) { 106 x += fCellWidth[i]; 107 StrokeLine(BPoint(x, bounds.top + 3), BPoint(x, bounds.bottom - 3)); 108 } 109 110 SetLowColor(ViewColor()); 111 SetHighColor(highColor); 112 113 font_height fontHeight; 114 GetFontHeight(&fontHeight); 115 116 x = bounds.left; 117 float y = (bounds.bottom + bounds.top 118 + ceilf(fontHeight.ascent) - ceilf(fontHeight.descent)) / 2; 119 120 for (size_t i = 0; i < kStatusCellCount; i++) { 121 if (fCellText[i].Length() == 0) 122 continue; 123 DrawString(fCellText[i], BPoint(x + kHorzSpacing, y)); 124 x += fCellWidth[i]; 125 } 79 126 } 80 127 81 128 … … ShowImageStatusView::MouseDown(BPoint where) 101 148 102 149 103 150 void 104 ShowImageStatusView::Update(const entry_ref& ref, const BString& text) 151 ShowImageStatusView::Update(const entry_ref& ref, const BString& text, 152 const BString& imageType, float zoom) 105 153 { 106 fText = text;107 154 fRef = ref; 108 155 156 fCellText[0] = text; 157 fCellText[1] = ""; 158 fCellText[1] << (int) (zoom * 100 + 0.5) << "%"; 159 fCellText[2] = imageType; 160 161 _ValidatePreferredSize(); 162 Invalidate(); 163 } 164 165 166 void 167 ShowImageStatusView::SetZoom(float zoom) 168 { 169 fCellText[1] = ""; 170 fCellText[1] << (int) (zoom * 100 + 0.5) << "%"; 171 172 _ValidatePreferredSize(); 109 173 Invalidate(); 110 174 } 111 175 176 177 void 178 ShowImageStatusView::_ValidatePreferredSize() 179 { 180 float orgWidth = fPreferredSize.width; 181 // width 182 fPreferredSize.width = 0.f; 183 for (size_t i = 0; i < kStatusCellCount; i++) { 184 if (fCellText[i].Length() == 0) { 185 fCellWidth[i] = 0; 186 continue; 187 } 188 float width = ceilf(StringWidth(fCellText[i])); 189 if (width > 0) 190 width += kHorzSpacing * 2; 191 fCellWidth[i] = width; 192 fPreferredSize.width += fCellWidth[i]; 193 } 194 195 // height 196 font_height fontHeight; 197 GetFontHeight(&fontHeight); 198 199 fPreferredSize.height = ceilf(fontHeight.ascent + fontHeight.descent 200 + fontHeight.leading); 201 202 if (fPreferredSize.height < B_H_SCROLL_BAR_HEIGHT) 203 fPreferredSize.height = B_H_SCROLL_BAR_HEIGHT; 204 205 float delta = fPreferredSize.width - orgWidth; 206 ResizeBy(delta, 0); 207 BScrollBar* scrollBar = fScrollView->ScrollBar(B_HORIZONTAL); 208 scrollBar->ResizeBy(-delta, 0); 209 scrollBar->MoveBy(delta, 0); 210 } 211 -
src/apps/showimage/ShowImageStatusView.h
diff --git a/src/apps/showimage/ShowImageStatusView.h b/src/apps/showimage/ShowImageStatusView.h index 05807b4..4b4e07b 100644
a b 15 15 #include <View.h> 16 16 17 17 18 enum { 19 kFrameSizeCell, 20 kZoomCell, 21 kImageTypeCell, 22 kStatusCellCount 23 }; 24 25 18 26 class ShowImageStatusView : public BView { 19 27 public: 20 ShowImageStatusView(BRect rect, 21 const char* name, uint32 resizingMode, 22 uint32 flags); 28 ShowImageStatusView(BScrollView* scrollView); 23 29 30 virtual void AttachedToWindow(); 31 virtual void GetPreferredSize(float* _width, float* _height); 32 virtual void ResizeToPreferred(); 24 33 virtual void Draw(BRect updateRect); 25 34 virtual void MouseDown(BPoint where); 26 35 27 36 void Update(const entry_ref& ref, 28 const BString& text); 29 37 const BString& text, const BString& imageType, 38 float zoom); 39 void SetZoom(float zoom); 30 40 private: 31 BString fText; 41 void _ValidatePreferredSize(); 42 43 BScrollView* fScrollView; 44 BSize fPreferredSize; 45 BString fCellText[kStatusCellCount]; 46 float fCellWidth[kStatusCellCount]; 32 47 entry_ref fRef; 33 48 }; 34 49 -
src/apps/showimage/ShowImageView.cpp
diff --git a/src/apps/showimage/ShowImageView.cpp b/src/apps/showimage/ShowImageView.cpp index fa55542..3279972 100644
a b ShowImageView::SetZoom(float zoom, BPoint where) 1587 1587 offset.y = (int)(where.y * fZoom / oldZoom + 0.5) - offset.y; 1588 1588 ScrollTo(offset); 1589 1589 } 1590 1591 BMessage message(MSG_UPDATE_STATUS_ZOOM); 1592 message.AddFloat("zoom", fZoom); 1593 _SendMessageToWindow(&message); 1590 1594 } 1591 1595 1592 1596 -
src/apps/showimage/ShowImageWindow.cpp
diff --git a/src/apps/showimage/ShowImageWindow.cpp b/src/apps/showimage/ShowImageWindow.cpp index 0015b5f..b4068f2 100644
a b ShowImageWindow::ShowImageWindow(BRect frame, const entry_ref& ref, 224 224 | B_FRAME_EVENTS); 225 225 // wrap a scroll view around the view 226 226 fScrollView = new BScrollView("image_scroller", fImageView, 227 B_FOLLOW_ALL, 0, false, false, B_PLAIN_BORDER);227 B_FOLLOW_ALL, 0, true, true, B_PLAIN_BORDER); 228 228 contentView->AddChild(fScrollView); 229 229 230 const int32 kstatusWidth = 190; 231 BRect rect; 232 rect = contentView->Bounds(); 233 rect.top = viewFrame.bottom + 1; 234 rect.left = viewFrame.left + kstatusWidth; 235 rect.right = viewFrame.right + 1; 236 rect.bottom += 1; 237 BScrollBar* horizontalScrollBar = new BScrollBar(rect, "hscroll", 238 fImageView, 0, 150, B_HORIZONTAL); 239 contentView->AddChild(horizontalScrollBar); 240 241 rect.left = 0; 242 rect.right = kstatusWidth - 1; 243 rect.bottom -= 1; 244 fStatusView = new ShowImageStatusView(rect, "status_view", B_FOLLOW_BOTTOM, 245 B_WILL_DRAW); 246 contentView->AddChild(fStatusView); 247 248 rect = contentView->Bounds(); 249 rect.top = viewFrame.top - 1; 250 rect.left = viewFrame.right + 1; 251 rect.bottom = viewFrame.bottom + 1; 252 rect.right += 1; 253 fVerticalScrollBar = new BScrollBar(rect, "vscroll", fImageView, 254 0, 150, B_VERTICAL); 255 contentView->AddChild(fVerticalScrollBar); 230 fStatusView = new ShowImageStatusView(fScrollView); 231 fScrollView->AddChild(fStatusView); 256 232 257 233 // Update minimum window size 258 234 float toolBarMinWidth = fToolBar->MinSize().width; … … ShowImageWindow::MessageReceived(BMessage* message) 967 943 fImageView->ZoomOut(); 968 944 break; 969 945 946 case MSG_UPDATE_STATUS_ZOOM: 947 fStatusView->SetZoom(fImageView->Zoom()); 948 break; 949 970 950 case kMsgOriginalSize: 971 951 if (message->FindInt32("behavior") == BButton::B_TOGGLE_BEHAVIOR) { 972 952 bool force = (message->FindInt32("be:value") == B_CONTROL_ON); … … ShowImageWindow::MessageReceived(BMessage* message) 1034 1014 fToolBar->MoveBy(0, offset); 1035 1015 fScrollView->ResizeBy(0, -offset); 1036 1016 fScrollView->MoveBy(0, offset); 1037 fVerticalScrollBar->ResizeBy(0, -offset);1038 fVerticalScrollBar->MoveBy(0, offset);1039 1017 UpdateIfNeeded(); 1040 1018 snooze(15000); 1041 1019 } … … ShowImageWindow::MessageReceived(BMessage* message) 1055 1033 frame.top = fToolBar->Frame().bottom + 1; 1056 1034 fScrollView->MoveTo(fScrollView->Frame().left, frame.top); 1057 1035 fScrollView->ResizeTo(fScrollView->Bounds().Width(), 1058 frame.Height() - B_H_SCROLL_BAR_HEIGHT + 1); 1059 fVerticalScrollBar->MoveTo( 1060 frame.right - B_V_SCROLL_BAR_WIDTH + 1, frame.top); 1061 fVerticalScrollBar->ResizeTo( 1062 fVerticalScrollBar->Bounds().Width(), 1063 frame.Height() - B_H_SCROLL_BAR_HEIGHT + 1); 1036 frame.Height() + 1); 1064 1037 } 1065 1038 break; 1066 1039 } … … ShowImageWindow::_UpdateStatusText(const BMessage* message) 1079 1052 if (fImageView->Bitmap() != NULL) { 1080 1053 BRect bounds = fImageView->Bitmap()->Bounds(); 1081 1054 status << bounds.IntegerWidth() + 1 1082 << "x" << bounds.IntegerHeight() + 1 << ", " << fImageType; 1083 } 1084 1085 BString text; 1086 if (message != NULL && message->FindString("status", &text) == B_OK 1087 && text.Length() > 0) { 1088 status << ", " << text; 1055 << "x" << bounds.IntegerHeight() + 1; 1089 1056 } 1090 1057 1091 fStatusView->Update(fNavigator.CurrentRef(), status );1058 fStatusView->Update(fNavigator.CurrentRef(), status, fImageType, fImageView->Zoom()); 1092 1059 } 1093 1060 1094 1061 … … ShowImageWindow::_SetToolBarVisible(bool visible, bool animate) 1540 1507 } else { 1541 1508 fScrollView->ResizeBy(0, -diff); 1542 1509 fScrollView->MoveBy(0, diff); 1543 fVerticalScrollBar->ResizeBy(0, -diff);1544 fVerticalScrollBar->MoveBy(0, diff);1545 1510 fToolBar->MoveBy(0, diff); 1546 1511 if (!visible) 1547 1512 fToolBar->Hide(); -
src/apps/showimage/ShowImageWindow.h
diff --git a/src/apps/showimage/ShowImageWindow.h b/src/apps/showimage/ShowImageWindow.h index ea593a3..12c960d 100644
a b enum { 35 35 MSG_MODIFIED = 'mMOD', 36 36 MSG_UPDATE_STATUS = 'mUPS', 37 37 MSG_UPDATE_STATUS_TEXT = 'mUPT', 38 MSG_UPDATE_STATUS_ZOOM = 'mUPZ', 38 39 MSG_SELECTION = 'mSEL', 39 40 MSG_FILE_NEXT = 'mFLN', 40 41 MSG_FILE_PREV = 'mFLP', … … private: 117 118 BToolBar* fToolBar; 118 119 bool fToolBarVisible; 119 120 BScrollView* fScrollView; 120 BScrollBar* fVerticalScrollBar;121 121 ShowImageView* fImageView; 122 122 ShowImageStatusView* fStatusView; 123 123 ProgressWindow* fProgressWindow;