Ticket #4146: 0001-Fixes-ticket-4146.patch

File 0001-Fixes-ticket-4146.patch, 5.5 KB (added by negusnyul, 12 years ago)
  • src/apps/magnify/Magnify.cpp

    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)  
    228228    fInfo->SetMagView(fFatBits);
    229229
    230230    ResizeWindow(fHPixelCount, fVPixelCount);
     231    UpdateInfoBarOnResize();
    231232
    232233    AddShortcut('S', B_COMMAND_KEY, new BMessage(msg_save));
    233234    AddShortcut('C', B_COMMAND_KEY, new BMessage(msg_copy_image));
    TWindow::MessageReceived(BMessage* m)  
    261262            break;
    262263
    263264        case msg_show_info:
    264             if (active)
     265            if (active) {
     266                fInfoBarState = !fInfoBarState;
    265267                ShowInfo(!fShowInfo);
     268            }
    266269            break;
    267270
    268271        case msg_toggle_grid:
    ALMOST_DONE: // clean up and try to position the window  
    450453DONE:
    451454    fShowGrid = showGrid;
    452455    fShowInfo = showInfo;
     456    fInfoBarState = showInfo;
    453457    fHPixelCount = (overridePixelCount == -1) ? hPixelCount : overridePixelCount;
    454458    fVPixelCount = (overridePixelCount == -1) ? vPixelCount : overridePixelCount;
    455459    fPixelSize = pixelSize;
    TWindow::FrameResized(float w, float h)  
    497501{
    498502    CalcViewablePixels();
    499503    fFatBits->InitBuffers(fHPixelCount, fVPixelCount, fPixelSize, ShowGrid());
     504    UpdateInfoBarOnResize();
    500505}
    501506
    502507
    TWindow::ShowInfo(bool i)  
    643648
    644649    fFatBits->SetSelection(fShowInfo);
    645650    ResizeWindow(fHPixelCount, fVPixelCount);
     651    fInfo->SetInfoTextVisible(i);
    646652}
    647653
    648654
    TWindow::UpdateInfo()  
    661667
    662668
    663669void
     670TWindow::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
     684void
    664685TWindow::AddCrossHair()
    665686{
    666687    fFatBits->AddCrossHair();
    TInfoView::TInfoView(BRect frame)  
    857878    fRGBStr[0] = 0;
    858879    fCH1Str[0] = 0;
    859880    fCH2Str[0] = 0;
     881
     882    fInfoTextVisible = true;
    860883}
    861884
    862885
    TInfoView::Draw(BRect updateRect)  
    907930    FillRect(invalRect);
    908931    SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
    909932    strcpy(fInfoStr, dimensionsInfo);
    910     DrawString(fInfoStr);
     933    if (fInfoTextVisible) {
     934        DrawString(fInfoStr);
     935    }
    911936
    912937    rgb_color color = { 0, 0, 0, 255 };
    913938    if (fMagView)
    TInfoView::Draw(BRect updateRect)  
    922947    FillRect(invalRect);
    923948    SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
    924949    strcpy(fRGBStr,str);
    925     DrawString(fRGBStr);
     950    if (fInfoTextVisible) {
     951        DrawString(fRGBStr);
     952    }
    926953
    927954    bool ch1Showing, ch2Showing;
    928955    dynamic_cast<TWindow*>(Window())->CrossHairsShowing(&ch1Showing, &ch2Showing);
    TInfoView::Draw(BRect updateRect)  
    941968            FillRect(invalRect);
    942969            SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
    943970            strcpy(fCH2Str,str);
    944             DrawString(fCH2Str);
     971            if (fInfoTextVisible) {
     972                DrawString(fCH2Str);
     973            }
    945974        }
    946975
    947976        if (ch1Showing && ch2Showing) {
    TInfoView::Draw(BRect updateRect)  
    953982            FillRect(invalRect);
    954983            SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
    955984            strcpy(fCH1Str,str);
    956             DrawString(fCH1Str);
     985            if (fInfoTextVisible) {
     986                DrawString(fCH1Str);
     987            }
    957988        } else if (ch1Showing) {
    958989            MovePenTo(10, h-10);
    959990            sprintf(str, "x: %li  y: %li", (int32)pt1.x, (int32)pt1.y);
    TInfoView::Draw(BRect updateRect)  
    962993            FillRect(invalRect);
    963994            SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
    964995            strcpy(fCH1Str,str);
    965             DrawString(fCH1Str);
     996            if (fInfoTextVisible) {
     997                DrawString(fCH1Str);
     998            }
    966999        }
    9671000    }
    9681001
    TInfoView::SetMagView(TMagnify* magView)  
    9971030}
    9981031
    9991032
     1033void
     1034TInfoView::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
     1051bool
     1052TInfoView::isInfoTextVisible()
     1053{
     1054    return fInfoTextVisible;
     1055}
     1056
     1057
     1058void
     1059TInfoView::SetInfoTextVisible(bool visible)
     1060{
     1061    fInfoTextVisible = visible;
     1062    Draw(Bounds());
     1063}
     1064
     1065
    10001066//  #pragma mark -
    10011067
    10021068
  • src/apps/magnify/Magnify.h

    diff --git a/src/apps/magnify/Magnify.h b/src/apps/magnify/Magnify.h
    index 2e3e7a4..7420b85 100644
    a b class TInfoView : public BBox {  
    165165        virtual void    AttachedToWindow();
    166166        virtual void    Draw(BRect updateRect);
    167167        virtual void    FrameResized(float width, float height);
     168        virtual void    GetPreferredSize(float* _width, float* height);
    168169
    169170        void            AddMenu();
    170171        void            SetMagView(TMagnify* magView);
     172        void            SetInfoTextVisible(bool visible);
     173        bool            isInfoTextVisible();
    171174
    172175    private:
    173176        float           fFontHeight;
    class TInfoView : public BBox {  
    188191        char            fRGBStr[64];
    189192        char            fCH1Str[64];
    190193        char            fCH2Str[64];
     194       
     195        bool            fInfoTextVisible;
    191196};
    192197
    193198class TWindow : public BWindow {
    class TWindow : public BWindow {  
    219224        void            ShowInfo(bool);
    220225        bool            InfoIsShowing();
    221226        void            UpdateInfo();
     227        void            UpdateInfoBarOnResize();
    222228
    223229        void            AddCrossHair();
    224230        void            RemoveCrossHair();
    class TWindow : public BWindow {  
    240246        float           fFontHeight;
    241247
    242248        bool            fShowGrid;
     249        bool            fInfoBarState;
    243250
    244251        int32           fHPixelCount;
    245252        int32           fVPixelCount;