~ubuntu-branches/ubuntu/trusty/manaplus/trusty-proposed

« back to all changes in this revision

Viewing changes to src/gui/widgets/window.cpp

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2013-07-11 10:09:41 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20130711100941-f0rwuvcwgl8ulqo8
Tags: 1.3.7.7.1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include "client.h"
26
26
#include "configuration.h"
 
27
#include "dragdrop.h"
27
28
#include "graphicsvertexes.h"
28
29
#include "soundmanager.h"
29
30
 
64
65
    mStickyRect(),
65
66
    mGripRect(),
66
67
    mWindowName("window"),
67
 
    mShowTitle(true),
68
 
    mModal(modal),
69
 
    mCloseButton(false),
70
 
    mDefaultVisible(false),
71
 
    mSaveVisible(false),
72
 
    mStickyButton(false),
73
 
    mSticky(false),
74
 
    mStickyButtonLock(false),
75
68
    mMinWinWidth(100),
76
69
    mMinWinHeight(40),
77
70
    mMaxWinWidth(mainGraphics->mWidth),
84
77
    mGripPadding(2),
85
78
    mResizeHandles(-1),
86
79
    mOldResizeHandles(-1),
87
 
    mPlayVisibleSound(false),
88
 
    mCaptionFont(getFont())
 
80
    mCaptionFont(getFont()),
 
81
    mShowTitle(true),
 
82
    mModal(modal),
 
83
    mCloseButton(false),
 
84
    mDefaultVisible(false),
 
85
    mSaveVisible(false),
 
86
    mStickyButton(false),
 
87
    mSticky(false),
 
88
    mStickyButtonLock(false),
 
89
    mPlayVisibleSound(false)
89
90
{
90
91
    logger->log("Window::Window(\"%s\")", caption.c_str());
91
92
 
108
109
 
109
110
    int childPalette = 1;
110
111
    // Loads the skin
111
 
    if (Theme::instance())
 
112
    Theme *const theme = Theme::instance();
 
113
    if (theme)
112
114
    {
113
 
        mSkin = Theme::instance()->load(skin, "window.xml");
 
115
        mSkin = theme->load(skin, "window.xml");
114
116
        if (mSkin)
115
117
        {
116
118
            setPadding(mSkin->getPadding());
140
142
        }
141
143
    }
142
144
 
143
 
 
144
145
    // Add this window to the window container
145
146
    windowContainer->add(this);
146
147
 
186
187
 
187
188
    if (mSkin)
188
189
    {
189
 
        if (Theme::instance())
190
 
            Theme::instance()->unload(mSkin);
 
190
        Theme *const theme = Theme::instance();
 
191
        if (theme)
 
192
            theme->unload(mSkin);
191
193
        mSkin = nullptr;
192
194
    }
193
195
    if (mGrip)
197
199
    }
198
200
}
199
201
 
200
 
void Window::setWindowContainer(WindowContainer *wc)
 
202
void Window::setWindowContainer(WindowContainer *const wc)
201
203
{
202
204
    windowContainer = wc;
203
205
}
317
319
void Window::setContentSize(int width, int height)
318
320
{
319
321
    width = width + 2 * mPadding;
320
 
    height = height + mPadding + getTitleBarHeight();
 
322
    height = height + mPadding + mTitleBarHeight;
321
323
 
322
 
    if (getMinWidth() > width)
323
 
        width = getMinWidth();
324
 
    else if (getMaxWidth() < width)
325
 
        width = getMaxWidth();
326
 
    if (getMinHeight() > height)
327
 
        height = getMinHeight();
328
 
    else if (getMaxHeight() < height)
329
 
        height = getMaxHeight();
 
324
    if (mMinWinWidth > width)
 
325
        width = mMinWinWidth;
 
326
    else if (mMaxWinWidth < width)
 
327
        width = mMaxWinWidth;
 
328
    if (mMinWinHeight > height)
 
329
        height = mMinWinHeight;
 
330
    else if (mMaxWinHeight < height)
 
331
        height = mMaxWinHeight;
330
332
 
331
333
    setSize(width, height);
332
334
}
409
411
    setPosition(offsetX, offsetY);
410
412
}
411
413
 
412
 
void Window::setMinWidth(int width)
 
414
void Window::setMinWidth(const int width)
413
415
{
414
416
    if (mSkin)
415
417
    {
422
424
    }
423
425
}
424
426
 
425
 
void Window::setMinHeight(int height)
 
427
void Window::setMinHeight(const int height)
426
428
{
427
429
    if (mSkin)
428
430
    {
429
 
        mMinWinHeight = height > mSkin->getMinHeight() ?
430
 
                        height : mSkin->getMinHeight();
 
431
        mMinWinHeight = height > mSkin->getMinHeight()
 
432
            ? height : mSkin->getMinHeight();
431
433
    }
432
434
    else
433
435
    {
485
487
    if (showClose)
486
488
    {
487
489
        const Image *const button = mSkin->getCloseImage(false);
488
 
        const int x = mDimension.width - button->getWidth() - closePadding;
489
 
        mCloseRect.x = x;
 
490
        const int buttonWidth = button->getWidth();
 
491
        mCloseRect.x = mDimension.width - buttonWidth - closePadding;
490
492
        mCloseRect.y = closePadding;
491
 
        mCloseRect.width = button->getWidth();
 
493
        mCloseRect.width = buttonWidth;
492
494
        mCloseRect.height = button->getHeight();
493
495
    }
494
496
    if (mStickyButton)
496
498
        const Image *const button = mSkin->getStickyImage(mSticky);
497
499
        if (button)
498
500
        {
499
 
            int x = mDimension.width - button->getWidth()
 
501
            const int buttonWidth = button->getWidth();
 
502
            int x = mDimension.width - buttonWidth
500
503
                - getOption("stickySpacing") - closePadding;
501
504
 
502
505
            if (showClose)
504
507
 
505
508
            mStickyRect.x = x;
506
509
            mStickyRect.y = getOption("stickyPadding");
507
 
            mStickyRect.width = button->getWidth();
 
510
            mStickyRect.width = buttonWidth;
508
511
            mStickyRect.height = button->getHeight();
509
512
        }
510
513
    }
564
567
    setVisible(visible, false);
565
568
}
566
569
 
567
 
void Window::setVisible(bool visible, bool forceSticky)
 
570
void Window::setVisible(const bool visible, const bool forceSticky)
568
571
{
569
 
    if (visible == isWindowVisible())
 
572
    if (visible == mVisible)
570
573
        return;
571
574
 
572
575
    // Check if the window is off screen...
579
582
        mResizeHandles = 0;
580
583
    }
581
584
 
582
 
    if (isStickyButtonLock())
 
585
    if (mStickyButtonLock)
583
586
        gcn::Window::setVisible(visible);
584
587
    else
585
 
        gcn::Window::setVisible((!forceSticky && isSticky()) || visible);
 
588
        gcn::Window::setVisible((!forceSticky && mSticky) || visible);
586
589
    if (visible)
587
590
    {
588
591
        if (mPlayVisibleSound)
589
592
            soundManager.playGuiSound(SOUND_SHOW_WINDOW);
590
593
        if (gui)
591
594
        {
592
 
            gcn::MouseEvent *event = reinterpret_cast<gcn::MouseEvent*>(
 
595
            gcn::MouseEvent *const event = reinterpret_cast<gcn::MouseEvent*>(
593
596
                gui->createMouseEvent(this));
594
597
            if (event)
595
598
            {
688
691
    if (!gui)
689
692
        return;
690
693
 
 
694
    if (!dragDrop.isEmpty())
 
695
        return;
 
696
 
691
697
    mResizeHandles = getResizeHandles(event);
692
698
 
693
699
    // Changes the custom mouse cursor based on it's current position.
711
717
            break;
712
718
        default:
713
719
            gui->setCursorType(Cursor::CURSOR_POINTER);
 
720
            break;
714
721
    }
715
722
}
716
723
 
760
767
            const int newHeight = newDim.height
761
768
                + ((mouseResize & TOP) ? -dy : dy);
762
769
            newDim.height = std::min(mMaxWinHeight,
763
 
                                     std::max(mMinWinHeight, newHeight));
 
770
                std::max(mMinWinHeight, newHeight));
764
771
 
765
772
            if (mouseResize & TOP)
766
773
                newDim.y -= newDim.height - getHeight();
771
778
            const int newWidth = newDim.width
772
779
                + ((mouseResize & LEFT) ? -dx : dx);
773
780
            newDim.width = std::min(mMaxWinWidth,
774
 
                                    std::max(mMinWinWidth, newWidth));
 
781
                std::max(mMinWinWidth, newWidth));
775
782
 
776
783
            if (mouseResize & LEFT)
777
784
                newDim.x -= newDim.width - mDimension.width;
805
812
    }
806
813
}
807
814
 
808
 
void Window::setModal(bool modal)
 
815
void Window::setModal(const bool modal)
809
816
{
810
817
    if (mModal != modal)
811
818
    {
916
923
    }
917
924
}
918
925
 
919
 
void Window::setDefaultSize(int defaultX, int defaultY,
 
926
void Window::setDefaultSize(const int defaultX, const int defaultY,
920
927
                            int defaultWidth, int defaultHeight)
921
928
{
922
 
    if (getMinWidth() > defaultWidth)
923
 
        defaultWidth = getMinWidth();
924
 
    else if (getMaxWidth() < defaultWidth)
925
 
        defaultWidth = getMaxWidth();
926
 
    if (getMinHeight() > defaultHeight)
927
 
        defaultHeight = getMinHeight();
928
 
    else if (getMaxHeight() < defaultHeight)
929
 
        defaultHeight = getMaxHeight();
 
929
    if (mMinWinWidth > defaultWidth)
 
930
        defaultWidth = mMinWinWidth;
 
931
    else if (mMaxWinWidth < defaultWidth)
 
932
        defaultWidth = mMaxWinWidth;
 
933
    if (mMinWinHeight > defaultHeight)
 
934
        defaultHeight = mMinWinHeight;
 
935
    else if (mMaxWinHeight < defaultHeight)
 
936
        defaultHeight = mMaxWinHeight;
930
937
 
931
938
    mDefaultX = defaultX;
932
939
    mDefaultY = defaultY;
942
949
    mDefaultHeight = mDimension.height;
943
950
}
944
951
 
945
 
void Window::setDefaultSize(int defaultWidth, int defaultHeight,
 
952
void Window::setDefaultSize(const int defaultWidth, const int defaultHeight,
946
953
                            const ImageRect::ImagePosition &position,
947
954
                            const int offsetX, const int offsetY)
948
955
{
949
 
    int x = 0, y = 0;
 
956
    int x = 0;
 
957
    int y = 0;
950
958
 
951
959
    if (position == ImageRect::UPPER_LEFT)
952
960
    {
1004
1012
void Window::adjustPositionAfterResize(const int oldScreenWidth,
1005
1013
                                       const int oldScreenHeight)
1006
1014
{
1007
 
    gcn::Rectangle dimension = getDimension();
1008
 
 
1009
1015
    // If window was aligned to the right or bottom, keep it there
1010
1016
    const int rightMargin = oldScreenWidth - (mDimension.x + mDimension.width);
1011
1017
    const int bottomMargin = oldScreenHeight
1012
1018
        - (mDimension.y + mDimension.height);
1013
1019
    if (mDimension.x > 0 && mDimension.x > rightMargin)
1014
 
        dimension.x = mainGraphics->mWidth - rightMargin - mDimension.width;
 
1020
        mDimension.x = mainGraphics->mWidth - rightMargin - mDimension.width;
1015
1021
    if (mDimension.y > 0 && mDimension.y > bottomMargin)
1016
 
        dimension.y = mainGraphics->mHeight - bottomMargin - mDimension.height;
 
1022
    {
 
1023
        mDimension.y = mainGraphics->mHeight
 
1024
            - bottomMargin - mDimension.height;
 
1025
    }
1017
1026
 
1018
 
    setDimension(dimension);
1019
1027
    ensureOnScreen();
1020
1028
}
1021
1029
 
1075
1083
    return false;
1076
1084
}
1077
1085
 
1078
 
int Window::getGuiAlpha()
 
1086
int Window::getGuiAlpha() const
1079
1087
{
1080
1088
    const float alpha = std::max(Client::getGuiAlpha(),
1081
1089
        Theme::instance()->getMinimumOpacity());
1151
1159
    if (mDimension.width == 0 && mDimension.height == 0)
1152
1160
        return;
1153
1161
 
1154
 
    gcn::Rectangle dimension = getDimension();
1155
 
 
1156
1162
    // Check the left and bottom screen boundaries
1157
 
    if (dimension.x + dimension.width > mainGraphics->mWidth)
1158
 
        dimension.x = mainGraphics->mWidth - dimension.width;
1159
 
    if (dimension.y + dimension.height > mainGraphics->mHeight)
1160
 
        dimension.y = mainGraphics->mHeight - dimension.height;
 
1163
    if (mDimension.x + mDimension.width > mainGraphics->mWidth)
 
1164
        mDimension.x = mainGraphics->mWidth - mDimension.width;
 
1165
    if (mDimension.y + mDimension.height > mainGraphics->mHeight)
 
1166
        mDimension.y = mainGraphics->mHeight - mDimension.height;
1161
1167
 
1162
1168
    // But never allow the windows to disappear in to the right and top
1163
 
    if (dimension.x < 0)
1164
 
        dimension.x = 0;
1165
 
    if (dimension.y < 0)
1166
 
        dimension.y = 0;
1167
 
 
1168
 
    setDimension(dimension);
 
1169
    if (mDimension.x < 0)
 
1170
        mDimension.x = 0;
 
1171
    if (mDimension.y < 0)
 
1172
        mDimension.y = 0;
1169
1173
}
1170
1174
 
1171
1175
gcn::Rectangle Window::getWindowArea() const
1188
1192
    return def;
1189
1193
}
1190
1194
 
1191
 
bool Window::getOptionBool(std::string name)
 
1195
bool Window::getOptionBool(const std::string &name) const
1192
1196
{
1193
1197
    if (mSkin)
1194
1198
        return mSkin->getOption(name) != 0;
1195
1199
    return 0;
1196
1200
}
 
1201
 
 
1202
#ifdef USE_PROFILER
 
1203
void Window::logic()
 
1204
{
 
1205
    logicChildren();
 
1206
}
 
1207
#endif