[haiku-commits] haiku: hrev45301 - src/apps/magnify

  • From: mattmadia@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 18 Feb 2013 03:32:26 +0100 (CET)

hrev45301 adds 3 changesets to branch 'master'
old head: 819c63ad65e53c432099eeed2e5a1d00f8f0b79e
new head: 936ad115209091f4e0744f4ca74bae2f51455b27
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=936ad11+%5E819c63a

----------------------------------------------------------------------------

da2db35: Allow Magnify to resize to smaller sizes more gracefully.
  
  Fixes ticket #4146
  
  Signed-off-by: Matt Madia <mattmadia@xxxxxxxxx>

                                   [ Tamás Krutki <ktamas@xxxxxxxxxxxxxxx> ]

e92b401: Automatic whitespace cleanup. No functional change.

                                        [ Matt Madia <mattmadia@xxxxxxxxx> ]

936ad11: Style fixes from #4146 comment:11.

                                        [ Matt Madia <mattmadia@xxxxxxxxx> ]

----------------------------------------------------------------------------

2 files changed, 79 insertions(+), 12 deletions(-)
src/apps/magnify/Magnify.cpp | 84 ++++++++++++++++++++++++++++++++++------
src/apps/magnify/Magnify.h   |  7 ++++

############################################################################

Commit:      da2db35956d4fede85d397cff49719ef882a1758
URL:         http://cgit.haiku-os.org/haiku/commit/?id=da2db35
Author:      Tamás Krutki <ktamas@xxxxxxxxxxxxxxx>
Date:        Tue Aug 14 15:56:34 2012 UTC
Committer:   Matt Madia <mattmadia@xxxxxxxxx>
Commit-Date: Mon Feb 18 02:31:05 2013 UTC

Ticket:      https://dev.haiku-os.org/ticket/4146

Allow Magnify to resize to smaller sizes more gracefully.

Fixes ticket #4146

Signed-off-by: Matt Madia <mattmadia@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/apps/magnify/Magnify.cpp b/src/apps/magnify/Magnify.cpp
index 091d1ad..6b486c2 100644
--- a/src/apps/magnify/Magnify.cpp
+++ b/src/apps/magnify/Magnify.cpp
@@ -222,6 +222,7 @@ TWindow::TWindow(int32 pixelCount)
        fInfo->SetMagView(fFatBits);
 
        ResizeWindow(fHPixelCount, fVPixelCount);
+       UpdateInfoBarOnResize();
 
        AddShortcut('S', B_COMMAND_KEY, new BMessage(msg_save));
        AddShortcut('C', B_COMMAND_KEY, new BMessage(msg_copy_image));
@@ -251,8 +252,10 @@ TWindow::MessageReceived(BMessage* m)
 
        switch (m->what) {
                case msg_show_info:
-                       if (active)
+                       if (active) {
+                               fInfoBarState = !fInfoBarState;
                                ShowInfo(!fShowInfo);
+                       }
                        break;
 
                case msg_toggle_grid:
@@ -440,6 +443,7 @@ ALMOST_DONE:        //      clean up and try to position 
the window
 DONE:
        fShowGrid = showGrid;
        fShowInfo = showInfo;
+       fInfoBarState = showInfo;
        fHPixelCount = (overridePixelCount == -1) ? hPixelCount : 
overridePixelCount;
        fVPixelCount = (overridePixelCount == -1) ? vPixelCount : 
overridePixelCount;
        fPixelSize = pixelSize;
@@ -487,6 +491,7 @@ TWindow::FrameResized(float w, float h)
 {
        CalcViewablePixels();
        fFatBits->InitBuffers(fHPixelCount, fVPixelCount, fPixelSize, 
ShowGrid());
+       UpdateInfoBarOnResize();
 }
 
 
@@ -633,6 +638,7 @@ TWindow::ShowInfo(bool i)
 
        fFatBits->SetSelection(fShowInfo);
        ResizeWindow(fHPixelCount, fVPixelCount);
+       fInfo->SetInfoTextVisible(i);
 }
 
 
@@ -651,6 +657,21 @@ TWindow::UpdateInfo()
 
 
 void
+TWindow::UpdateInfoBarOnResize()
+{
+       float infoWidth, infoHeight;
+       fInfo->GetPreferredSize(&infoWidth, &infoHeight);
+
+       if (infoWidth > Bounds().Width() ||
+               infoHeight > Bounds().Height()) {
+               ShowInfo(false);
+       } else {
+               ShowInfo(true);
+       }
+}
+
+
+void
 TWindow::AddCrossHair()
 {
        fFatBits->AddCrossHair();
@@ -771,6 +792,8 @@ TInfoView::TInfoView(BRect frame)
        fRGBStr[0] = 0;
        fCH1Str[0] = 0;
        fCH2Str[0] = 0;
+
+       fInfoTextVisible = true;
 }
 
 
@@ -821,7 +844,9 @@ TInfoView::Draw(BRect updateRect)
        FillRect(invalRect);
        SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
        strcpy(fInfoStr, dimensionsInfo);
-       DrawString(fInfoStr);
+       if (fInfoTextVisible) {
+               DrawString(fInfoStr);
+       }
 
        rgb_color color = { 0, 0, 0, 255 };
        if (fMagView)
@@ -836,7 +861,9 @@ TInfoView::Draw(BRect updateRect)
        FillRect(invalRect);
        SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
        strcpy(fRGBStr,str);
-       DrawString(fRGBStr);
+       if (fInfoTextVisible) {
+               DrawString(fRGBStr);
+       }
 
        bool ch1Showing, ch2Showing;
        dynamic_cast<TWindow*>(Window())->CrossHairsShowing(&ch1Showing, 
&ch2Showing);
@@ -855,7 +882,9 @@ TInfoView::Draw(BRect updateRect)
                        FillRect(invalRect);
                        SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
                        strcpy(fCH2Str,str);
-                       DrawString(fCH2Str);
+                       if (fInfoTextVisible) {
+                               DrawString(fCH2Str);
+                       }
                }
 
                if (ch1Showing && ch2Showing) {
@@ -867,7 +896,9 @@ TInfoView::Draw(BRect updateRect)
                        FillRect(invalRect);
                        SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
                        strcpy(fCH1Str,str);
-                       DrawString(fCH1Str);
+                       if (fInfoTextVisible) {
+                               DrawString(fCH1Str);
+                       }
                } else if (ch1Showing) {
                        MovePenTo(10, h-10);
                        sprintf(str, "x: %li  y: %li", (int32)pt1.x, 
(int32)pt1.y);
@@ -876,7 +907,9 @@ TInfoView::Draw(BRect updateRect)
                        FillRect(invalRect);
                        SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
                        strcpy(fCH1Str,str);
-                       DrawString(fCH1Str);
+                       if (fInfoTextVisible) {
+                               DrawString(fCH1Str);
+                       }
                }
        }
 
@@ -965,6 +998,39 @@ TMenu::AttachedToWindow()
 }
 
 
+void
+TInfoView::GetPreferredSize(float* _width, float* _height)
+{
+       if(_width) {
+               float str1Width = StringWidth(fCH1Str)
+                       + StringWidth(fCH2Str)
+                       + StringWidth(fRGBStr)
+                       + 30;
+               float str2Width = StringWidth(fInfoStr) + 30;
+               *_width = str1Width > str2Width ? str1Width : str2Width;
+       }
+
+       if(_height) {
+               *_height = fFontHeight * 2 + 10;
+       }
+}
+
+
+bool
+TInfoView::isInfoTextVisible()
+{
+       return fInfoTextVisible;
+}
+
+
+void
+TInfoView::SetInfoTextVisible(bool visible)
+{
+       fInfoTextVisible = visible;
+       Draw(Bounds());
+}
+
+
 //     #pragma mark -
 
 
diff --git a/src/apps/magnify/Magnify.h b/src/apps/magnify/Magnify.h
index 44c9f82..9c7e8db 100644
--- a/src/apps/magnify/Magnify.h
+++ b/src/apps/magnify/Magnify.h
@@ -165,9 +165,12 @@ class TInfoView : public BBox {
                virtual void    AttachedToWindow();
                virtual void    Draw(BRect updateRect);
                virtual void    FrameResized(float width, float height);
+               virtual void    GetPreferredSize(float* _width, float* height);
 
                void                    AddMenu();
                void                    SetMagView(TMagnify* magView);
+               void                    SetInfoTextVisible(bool visible);
+               bool                    isInfoTextVisible();
 
        private:
                float                   fFontHeight;
@@ -188,6 +191,8 @@ class TInfoView : public BBox {
                char                    fRGBStr[64];
                char                    fCH1Str[64];
                char                    fCH2Str[64];
+
+               bool                    fInfoTextVisible;
 };
 
 class TWindow : public BWindow {
@@ -219,6 +224,7 @@ class TWindow : public BWindow {
                void                    ShowInfo(bool);
                bool                    InfoIsShowing();
                void                    UpdateInfo();
+               void                    UpdateInfoBarOnResize();
 
                void                    AddCrossHair();
                void                    RemoveCrossHair();
@@ -238,6 +244,7 @@ class TWindow : public BWindow {
                float                   fFontHeight;
 
                bool                    fShowGrid;
+               bool                    fInfoBarState;
 
                int32                   fHPixelCount;
                int32                   fVPixelCount;

############################################################################

Commit:      e92b40188a6d07a041004d56cdcb987d450ed0eb
URL:         http://cgit.haiku-os.org/haiku/commit/?id=e92b401
Author:      Matt Madia <mattmadia@xxxxxxxxx>
Date:        Mon Feb 18 02:31:35 2013 UTC

Automatic whitespace cleanup. No functional change.

----------------------------------------------------------------------------

diff --git a/src/apps/magnify/Magnify.cpp b/src/apps/magnify/Magnify.cpp
index 6b486c2..5b34a4e 100644
--- a/src/apps/magnify/Magnify.cpp
+++ b/src/apps/magnify/Magnify.cpp
@@ -135,7 +135,7 @@ BuildInfoMenu(BMenu *menu)
        menu->AddItem(menuItem);
 //     menuItem = new BMenuItem(B_TRANSLATE("Save selection"), new 
BMessage(msg_save),'S');
 //     menu->AddItem(menuItem);
-       menuItem = new BMenuItem(B_TRANSLATE("Copy image"), 
+       menuItem = new BMenuItem(B_TRANSLATE("Copy image"),
                new BMessage(msg_copy_image),'C');
        menu->AddItem(menuItem);
        menu->AddSeparatorItem();
@@ -1506,7 +1506,7 @@ TMagnify::CopyImage()
 
        BMessage *message = be_clipboard->Data();
        if (!message) {
-               printf(B_TRANSLATE_CONTEXT("no clip msg\n", 
+               printf(B_TRANSLATE_CONTEXT("no clip msg\n",
                        "In console, when clipboard is empty after clicking 
Copy image"));
                return;
        }
@@ -2044,7 +2044,7 @@ main(int argc, char* argv[])
 
        if (argc > 2) {
                printf(B_TRANSLATE_CONTEXT(
-                       "usage: magnify [size] (magnify size * size pixels)\n", 
+                       "usage: magnify [size] (magnify size * size pixels)\n",
                        "Console"));
                exit(1);
        } else {
@@ -2053,17 +2053,17 @@ main(int argc, char* argv[])
 
                        if ((pixelCount > 100) || (pixelCount < 4)) {
                                printf(B_TRANSLATE_CONTEXT(
-                                       "usage: magnify [size] (magnify size * 
size pixels)\n", 
+                                       "usage: magnify [size] (magnify size * 
size pixels)\n",
                                        "Console"));
                                printf(B_TRANSLATE_CONTEXT(
-                                       "  size must be > 4 and a multiple of 
4\n", 
+                                       "  size must be > 4 and a multiple of 
4\n",
                                        "Console"));
                                exit(1);
                        }
 
                        if (pixelCount % 4) {
                                printf(B_TRANSLATE_CONTEXT(
-                                       "magnify: size must be a multiple of 
4\n", 
+                                       "magnify: size must be a multiple of 
4\n",
                                        "Console"));
                                exit(1);
                        }

############################################################################

Revision:    hrev45301
Commit:      936ad115209091f4e0744f4ca74bae2f51455b27
URL:         http://cgit.haiku-os.org/haiku/commit/?id=936ad11
Author:      Matt Madia <mattmadia@xxxxxxxxx>
Date:        Mon Feb 18 02:32:04 2013 UTC

Ticket:      https://dev.haiku-os.org/ticket/4146

Style fixes from #4146 comment:11.

----------------------------------------------------------------------------

diff --git a/src/apps/magnify/Magnify.cpp b/src/apps/magnify/Magnify.cpp
index 5b34a4e..c757b63 100644
--- a/src/apps/magnify/Magnify.cpp
+++ b/src/apps/magnify/Magnify.cpp
@@ -662,8 +662,8 @@ TWindow::UpdateInfoBarOnResize()
        float infoWidth, infoHeight;
        fInfo->GetPreferredSize(&infoWidth, &infoHeight);
 
-       if (infoWidth > Bounds().Width() ||
-               infoHeight > Bounds().Height()) {
+       if (infoWidth > Bounds().Width()
+               || infoHeight > Bounds().Height()) {
                ShowInfo(false);
        } else {
                ShowInfo(true);
@@ -844,9 +844,8 @@ TInfoView::Draw(BRect updateRect)
        FillRect(invalRect);
        SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
        strcpy(fInfoStr, dimensionsInfo);
-       if (fInfoTextVisible) {
+       if (fInfoTextVisible)
                DrawString(fInfoStr);
-       }
 
        rgb_color color = { 0, 0, 0, 255 };
        if (fMagView)
@@ -861,9 +860,8 @@ TInfoView::Draw(BRect updateRect)
        FillRect(invalRect);
        SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
        strcpy(fRGBStr,str);
-       if (fInfoTextVisible) {
+       if (fInfoTextVisible)
                DrawString(fRGBStr);
-       }
 
        bool ch1Showing, ch2Showing;
        dynamic_cast<TWindow*>(Window())->CrossHairsShowing(&ch1Showing, 
&ch2Showing);
@@ -882,9 +880,8 @@ TInfoView::Draw(BRect updateRect)
                        FillRect(invalRect);
                        SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
                        strcpy(fCH2Str,str);
-                       if (fInfoTextVisible) {
+                       if (fInfoTextVisible)
                                DrawString(fCH2Str);
-                       }
                }
 
                if (ch1Showing && ch2Showing) {
@@ -896,9 +893,8 @@ TInfoView::Draw(BRect updateRect)
                        FillRect(invalRect);
                        SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
                        strcpy(fCH1Str,str);
-                       if (fInfoTextVisible) {
+                       if (fInfoTextVisible)
                                DrawString(fCH1Str);
-                       }
                } else if (ch1Showing) {
                        MovePenTo(10, h-10);
                        sprintf(str, "x: %li  y: %li", (int32)pt1.x, 
(int32)pt1.y);
@@ -907,9 +903,8 @@ TInfoView::Draw(BRect updateRect)
                        FillRect(invalRect);
                        SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
                        strcpy(fCH1Str,str);
-                       if (fInfoTextVisible) {
+                       if (fInfoTextVisible)
                                DrawString(fCH1Str);
-                       }
                }
        }
 
@@ -1001,7 +996,7 @@ TMenu::AttachedToWindow()
 void
 TInfoView::GetPreferredSize(float* _width, float* _height)
 {
-       if(_width) {
+       if (_width) {
                float str1Width = StringWidth(fCH1Str)
                        + StringWidth(fCH2Str)
                        + StringWidth(fRGBStr)
@@ -1010,14 +1005,13 @@ TInfoView::GetPreferredSize(float* _width, float* 
_height)
                *_width = str1Width > str2Width ? str1Width : str2Width;
        }
 
-       if(_height) {
+       if (_height)
                *_height = fFontHeight * 2 + 10;
-       }
 }
 
 
 bool
-TInfoView::isInfoTextVisible()
+TInfoView::IsInfoTextVisible()
 {
        return fInfoTextVisible;
 }
diff --git a/src/apps/magnify/Magnify.h b/src/apps/magnify/Magnify.h
index 9c7e8db..c4d468c 100644
--- a/src/apps/magnify/Magnify.h
+++ b/src/apps/magnify/Magnify.h
@@ -165,12 +165,12 @@ class TInfoView : public BBox {
                virtual void    AttachedToWindow();
                virtual void    Draw(BRect updateRect);
                virtual void    FrameResized(float width, float height);
-               virtual void    GetPreferredSize(float* _width, float* height);
+               virtual void    GetPreferredSize(float* _width, float* _height);
 
                void                    AddMenu();
                void                    SetMagView(TMagnify* magView);
                void                    SetInfoTextVisible(bool visible);
-               bool                    isInfoTextVisible();
+               bool                    IsInfoTextVisible();
 
        private:
                float                   fFontHeight;


Other related posts:

  • » [haiku-commits] haiku: hrev45301 - src/apps/magnify - mattmadia