From 5a7405f7cd60b6dad44a2185980c8da7da5db1bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tam=C3=A1s=20Krutki?= <ktamas@wartime-tbs.org>
Date: Tue, 14 Aug 2012 15:56:34 +0000
Subject: [PATCH] Fixes ticket #4146
---
src/apps/magnify/Magnify.cpp | 78 ++++++++++++++++++++++++++++++++++++++++----
src/apps/magnify/Magnify.h | 7 ++++
2 files changed, 79 insertions(+), 6 deletions(-)
diff --git a/src/apps/magnify/Magnify.cpp b/src/apps/magnify/Magnify.cpp
index 954196a..cc14fd6 100644
a
|
b
|
TWindow::TWindow(int32 pixelCount)
|
228 | 228 | fInfo->SetMagView(fFatBits); |
229 | 229 | |
230 | 230 | ResizeWindow(fHPixelCount, fVPixelCount); |
| 231 | UpdateInfoBarOnResize(); |
231 | 232 | |
232 | 233 | AddShortcut('S', B_COMMAND_KEY, new BMessage(msg_save)); |
233 | 234 | AddShortcut('C', B_COMMAND_KEY, new BMessage(msg_copy_image)); |
… |
… |
TWindow::MessageReceived(BMessage* m)
|
261 | 262 | break; |
262 | 263 | |
263 | 264 | case msg_show_info: |
264 | | if (active) |
| 265 | if (active) { |
| 266 | fInfoBarState = !fInfoBarState; |
265 | 267 | ShowInfo(!fShowInfo); |
| 268 | } |
266 | 269 | break; |
267 | 270 | |
268 | 271 | case msg_toggle_grid: |
… |
… |
ALMOST_DONE: // clean up and try to position the window
|
450 | 453 | DONE: |
451 | 454 | fShowGrid = showGrid; |
452 | 455 | fShowInfo = showInfo; |
| 456 | fInfoBarState = showInfo; |
453 | 457 | fHPixelCount = (overridePixelCount == -1) ? hPixelCount : overridePixelCount; |
454 | 458 | fVPixelCount = (overridePixelCount == -1) ? vPixelCount : overridePixelCount; |
455 | 459 | fPixelSize = pixelSize; |
… |
… |
TWindow::FrameResized(float w, float h)
|
497 | 501 | { |
498 | 502 | CalcViewablePixels(); |
499 | 503 | fFatBits->InitBuffers(fHPixelCount, fVPixelCount, fPixelSize, ShowGrid()); |
| 504 | UpdateInfoBarOnResize(); |
500 | 505 | } |
501 | 506 | |
502 | 507 | |
… |
… |
TWindow::ShowInfo(bool i)
|
643 | 648 | |
644 | 649 | fFatBits->SetSelection(fShowInfo); |
645 | 650 | ResizeWindow(fHPixelCount, fVPixelCount); |
| 651 | fInfo->SetInfoTextVisible(i); |
646 | 652 | } |
647 | 653 | |
648 | 654 | |
… |
… |
TWindow::UpdateInfo()
|
661 | 667 | |
662 | 668 | |
663 | 669 | void |
| 670 | TWindow::UpdateInfoBarOnResize() |
| 671 | { |
| 672 | float infoWidth, infoHeight; |
| 673 | fInfo->GetPreferredSize(&infoWidth, &infoHeight); |
| 674 | |
| 675 | if (infoWidth > Bounds().Width() || |
| 676 | infoHeight > Bounds().Height()) { |
| 677 | ShowInfo(false); |
| 678 | } else { |
| 679 | ShowInfo(true); |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | |
| 684 | void |
664 | 685 | TWindow::AddCrossHair() |
665 | 686 | { |
666 | 687 | fFatBits->AddCrossHair(); |
… |
… |
TInfoView::TInfoView(BRect frame)
|
857 | 878 | fRGBStr[0] = 0; |
858 | 879 | fCH1Str[0] = 0; |
859 | 880 | fCH2Str[0] = 0; |
| 881 | |
| 882 | fInfoTextVisible = true; |
860 | 883 | } |
861 | 884 | |
862 | 885 | |
… |
… |
TInfoView::Draw(BRect updateRect)
|
907 | 930 | FillRect(invalRect); |
908 | 931 | SetHighColor(ui_color(B_PANEL_TEXT_COLOR)); |
909 | 932 | strcpy(fInfoStr, dimensionsInfo); |
910 | | DrawString(fInfoStr); |
| 933 | if (fInfoTextVisible) { |
| 934 | DrawString(fInfoStr); |
| 935 | } |
911 | 936 | |
912 | 937 | rgb_color color = { 0, 0, 0, 255 }; |
913 | 938 | if (fMagView) |
… |
… |
TInfoView::Draw(BRect updateRect)
|
922 | 947 | FillRect(invalRect); |
923 | 948 | SetHighColor(ui_color(B_PANEL_TEXT_COLOR)); |
924 | 949 | strcpy(fRGBStr,str); |
925 | | DrawString(fRGBStr); |
| 950 | if (fInfoTextVisible) { |
| 951 | DrawString(fRGBStr); |
| 952 | } |
926 | 953 | |
927 | 954 | bool ch1Showing, ch2Showing; |
928 | 955 | dynamic_cast<TWindow*>(Window())->CrossHairsShowing(&ch1Showing, &ch2Showing); |
… |
… |
TInfoView::Draw(BRect updateRect)
|
941 | 968 | FillRect(invalRect); |
942 | 969 | SetHighColor(ui_color(B_PANEL_TEXT_COLOR)); |
943 | 970 | strcpy(fCH2Str,str); |
944 | | DrawString(fCH2Str); |
| 971 | if (fInfoTextVisible) { |
| 972 | DrawString(fCH2Str); |
| 973 | } |
945 | 974 | } |
946 | 975 | |
947 | 976 | if (ch1Showing && ch2Showing) { |
… |
… |
TInfoView::Draw(BRect updateRect)
|
953 | 982 | FillRect(invalRect); |
954 | 983 | SetHighColor(ui_color(B_PANEL_TEXT_COLOR)); |
955 | 984 | strcpy(fCH1Str,str); |
956 | | DrawString(fCH1Str); |
| 985 | if (fInfoTextVisible) { |
| 986 | DrawString(fCH1Str); |
| 987 | } |
957 | 988 | } else if (ch1Showing) { |
958 | 989 | MovePenTo(10, h-10); |
959 | 990 | sprintf(str, "x: %li y: %li", (int32)pt1.x, (int32)pt1.y); |
… |
… |
TInfoView::Draw(BRect updateRect)
|
962 | 993 | FillRect(invalRect); |
963 | 994 | SetHighColor(ui_color(B_PANEL_TEXT_COLOR)); |
964 | 995 | strcpy(fCH1Str,str); |
965 | | DrawString(fCH1Str); |
| 996 | if (fInfoTextVisible) { |
| 997 | DrawString(fCH1Str); |
| 998 | } |
966 | 999 | } |
967 | 1000 | } |
968 | 1001 | |
… |
… |
TInfoView::SetMagView(TMagnify* magView)
|
997 | 1030 | } |
998 | 1031 | |
999 | 1032 | |
| 1033 | void |
| 1034 | TInfoView::GetPreferredSize(float* _width, float* _height) |
| 1035 | { |
| 1036 | if(_width) { |
| 1037 | float str1Width = StringWidth(fCH1Str) |
| 1038 | + StringWidth(fCH2Str) |
| 1039 | + StringWidth(fRGBStr) |
| 1040 | + 30; |
| 1041 | float str2Width = StringWidth(fInfoStr) + 30; |
| 1042 | *_width = str1Width > str2Width ? str1Width : str2Width; |
| 1043 | } |
| 1044 | |
| 1045 | if(_height) { |
| 1046 | *_height = fFontHeight * 2 + 10; |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | |
| 1051 | bool |
| 1052 | TInfoView::isInfoTextVisible() |
| 1053 | { |
| 1054 | return fInfoTextVisible; |
| 1055 | } |
| 1056 | |
| 1057 | |
| 1058 | void |
| 1059 | TInfoView::SetInfoTextVisible(bool visible) |
| 1060 | { |
| 1061 | fInfoTextVisible = visible; |
| 1062 | Draw(Bounds()); |
| 1063 | } |
| 1064 | |
| 1065 | |
1000 | 1066 | // #pragma mark - |
1001 | 1067 | |
1002 | 1068 | |
diff --git a/src/apps/magnify/Magnify.h b/src/apps/magnify/Magnify.h
index 2e3e7a4..7420b85 100644
a
|
b
|
class TInfoView : public BBox {
|
165 | 165 | virtual void AttachedToWindow(); |
166 | 166 | virtual void Draw(BRect updateRect); |
167 | 167 | virtual void FrameResized(float width, float height); |
| 168 | virtual void GetPreferredSize(float* _width, float* height); |
168 | 169 | |
169 | 170 | void AddMenu(); |
170 | 171 | void SetMagView(TMagnify* magView); |
| 172 | void SetInfoTextVisible(bool visible); |
| 173 | bool isInfoTextVisible(); |
171 | 174 | |
172 | 175 | private: |
173 | 176 | float fFontHeight; |
… |
… |
class TInfoView : public BBox {
|
188 | 191 | char fRGBStr[64]; |
189 | 192 | char fCH1Str[64]; |
190 | 193 | char fCH2Str[64]; |
| 194 | |
| 195 | bool fInfoTextVisible; |
191 | 196 | }; |
192 | 197 | |
193 | 198 | class TWindow : public BWindow { |
… |
… |
class TWindow : public BWindow {
|
219 | 224 | void ShowInfo(bool); |
220 | 225 | bool InfoIsShowing(); |
221 | 226 | void UpdateInfo(); |
| 227 | void UpdateInfoBarOnResize(); |
222 | 228 | |
223 | 229 | void AddCrossHair(); |
224 | 230 | void RemoveCrossHair(); |
… |
… |
class TWindow : public BWindow {
|
240 | 246 | float fFontHeight; |
241 | 247 | |
242 | 248 | bool fShowGrid; |
| 249 | bool fInfoBarState; |
243 | 250 | |
244 | 251 | int32 fHPixelCount; |
245 | 252 | int32 fVPixelCount; |