00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "MyGUI_Precompiled.h"
00025 #include "MyGUI_ScrollViewBase.h"
00026 #include "MyGUI_VScroll.h"
00027 #include "MyGUI_HScroll.h"
00028
00029 namespace MyGUI
00030 {
00031
00032 ScrollViewBase::ScrollViewBase() :
00033 mVScroll(nullptr),
00034 mHScroll(nullptr),
00035 mClient(nullptr),
00036 mVisibleHScroll(true),
00037 mVisibleVScroll(true),
00038 mVRange(0),
00039 mHRange(0),
00040 mChangeContentByResize(false)
00041 {
00042 }
00043
00044 void ScrollViewBase::updateScrollSize()
00045 {
00046 eraseContent();
00047 IntSize contentSize = getContentSize();
00048 IntSize viewSize = getViewSize();
00049
00050
00051 if (contentSize.height > viewSize.height)
00052 {
00053 if (mVScroll != nullptr)
00054 {
00055 if (( ! mVScroll->isVisible()) && (mVisibleVScroll))
00056 {
00057 mVScroll->setVisible(true);
00058 mClient->setSize(mClient->getWidth() - mVScroll->getWidth(), mClient->getHeight());
00059
00060
00061 if (mChangeContentByResize)
00062 {
00063 eraseContent();
00064 contentSize = getContentSize();
00065 viewSize = getViewSize();
00066 }
00067
00068 if (mHScroll != nullptr)
00069 {
00070 mHScroll->setSize(mHScroll->getWidth() - mVScroll->getWidth(), mHScroll->getHeight());
00071
00072
00073
00074 if ((contentSize.width > viewSize.width) && ( ! mHScroll->isVisible()) && (mVisibleHScroll))
00075 {
00076 mHScroll->setVisible(true);
00077 mClient->setSize(mClient->getWidth(), mClient->getHeight() - mHScroll->getHeight());
00078 mVScroll->setSize(mVScroll->getWidth(), mVScroll->getHeight() - mHScroll->getHeight());
00079
00080
00081 if (mChangeContentByResize)
00082 {
00083 eraseContent();
00084 contentSize = getContentSize();
00085 viewSize = getViewSize();
00086 }
00087
00088 }
00089 }
00090 }
00091 }
00092 }
00093
00094 else
00095 {
00096 if (mVScroll != nullptr)
00097 {
00098 if (mVScroll->isVisible())
00099 {
00100 mVScroll->setVisible(false);
00101 mClient->setSize(mClient->getWidth() + mVScroll->getWidth(), mClient->getHeight());
00102
00103
00104 if (mChangeContentByResize)
00105 {
00106 eraseContent();
00107 contentSize = getContentSize();
00108 viewSize = getViewSize();
00109 }
00110
00111 if (mHScroll != nullptr)
00112 {
00113 mHScroll->setSize(mHScroll->getWidth() + mVScroll->getWidth(), mHScroll->getHeight());
00114
00115
00116
00117 if ((contentSize.width <= viewSize.width) && (mHScroll->isVisible()))
00118 {
00119 mHScroll->setVisible(false);
00120 mClient->setSize(mClient->getWidth(), mClient->getHeight() + mHScroll->getHeight());
00121 mVScroll->setSize(mVScroll->getWidth(), mVScroll->getHeight() + mHScroll->getHeight());
00122
00123
00124 if (mChangeContentByResize)
00125 {
00126 eraseContent();
00127 contentSize = getContentSize();
00128 viewSize = getViewSize();
00129 }
00130
00131 }
00132 }
00133 }
00134 }
00135 }
00136
00137
00138
00139 if (contentSize.width > viewSize.width)
00140 {
00141 if (mHScroll != nullptr)
00142 {
00143 if (( ! mHScroll->isVisible()) && (mVisibleHScroll))
00144 {
00145 mHScroll->setVisible(true);
00146 mClient->setSize(mClient->getWidth(), mClient->getHeight() - mHScroll->getHeight());
00147
00148
00149 if (mChangeContentByResize)
00150 {
00151 eraseContent();
00152 contentSize = getContentSize();
00153 viewSize = getViewSize();
00154 }
00155
00156 if (mVScroll != nullptr)
00157 {
00158 mVScroll->setSize(mVScroll->getWidth(), mVScroll->getHeight() - mHScroll->getHeight());
00159
00160
00161
00162 if ((contentSize.height > viewSize.height) && ( ! mVScroll->isVisible()) && (mVisibleVScroll))
00163 {
00164 mVScroll->setVisible(true);
00165 mClient->setSize(mClient->getWidth() - mVScroll->getWidth(), mClient->getHeight());
00166 mHScroll->setSize(mHScroll->getWidth() - mVScroll->getWidth(), mHScroll->getHeight());
00167
00168
00169 if (mChangeContentByResize)
00170 {
00171 eraseContent();
00172 contentSize = getContentSize();
00173 viewSize = getViewSize();
00174 }
00175
00176 }
00177 }
00178 }
00179 }
00180 }
00181
00182 else
00183 {
00184 if (mHScroll != nullptr)
00185 {
00186 if (mHScroll->isVisible())
00187 {
00188 mHScroll->setVisible(false);
00189 mClient->setSize(mClient->getWidth(), mClient->getHeight() + mHScroll->getHeight());
00190
00191
00192 if (mChangeContentByResize)
00193 {
00194 eraseContent();
00195 contentSize = getContentSize();
00196 viewSize = getViewSize();
00197 }
00198
00199 if (mVScroll != nullptr)
00200 {
00201 mVScroll->setSize(mVScroll->getWidth(), mVScroll->getHeight() + mHScroll->getHeight());
00202
00203
00204
00205 if ((contentSize.height <= viewSize.height) && (mVScroll->isVisible()))
00206 {
00207 mVScroll->setVisible(false);
00208 mClient->setSize(mClient->getWidth() + mVScroll->getWidth(), mClient->getHeight());
00209 mHScroll->setSize(mHScroll->getWidth() + mVScroll->getWidth(), mHScroll->getHeight());
00210
00211
00212 if (mChangeContentByResize)
00213 {
00214 eraseContent();
00215 contentSize = getContentSize();
00216 viewSize = getViewSize();
00217 }
00218 }
00219 }
00220 }
00221 }
00222 }
00223
00224 mVRange = (viewSize.height >= contentSize.height) ? 0 : contentSize.height - viewSize.height;
00225 mHRange = (viewSize.width >= contentSize.width) ? 0 : contentSize.width - viewSize.width;
00226
00227 if (mVScroll != nullptr)
00228 {
00229 size_t page = getVScrollPage();
00230 mVScroll->setScrollPage(page);
00231 mVScroll->setScrollViewPage(viewSize.width > (int)page ? viewSize.width : page);
00232 mVScroll->setScrollRange(mVRange + 1);
00233 if (contentSize.height) mVScroll->setTrackSize(int (float(mVScroll->getLineSize() * viewSize.height) / float(contentSize.height)));
00234 }
00235 if (mHScroll != nullptr)
00236 {
00237 size_t page = getHScrollPage();
00238 mHScroll->setScrollPage(page);
00239 mHScroll->setScrollViewPage(viewSize.height > (int)page ? viewSize.height : page);
00240 mHScroll->setScrollRange(mHRange + 1);
00241 if (contentSize.width) mHScroll->setTrackSize(int (float(mHScroll->getLineSize() * viewSize.width) / float(contentSize.width)));
00242 }
00243 }
00244
00245 void ScrollViewBase::updateScrollPosition()
00246 {
00247
00248 IntSize contentSize = getContentSize();
00249
00250 IntPoint contentPoint = getContentPosition();
00251
00252 IntPoint offset = contentPoint;
00253
00254 IntSize viewSize = getViewSize();
00255
00256 Align align = getContentAlign();
00257
00258 if (contentSize.width > viewSize.width)
00259 {
00260
00261 if ((offset.left + viewSize.width) > contentSize.width)
00262 {
00263 offset.left = contentSize.width - viewSize.width;
00264 }
00265
00266 else if (offset.left < 0)
00267 {
00268 offset.left = 0;
00269 }
00270 }
00271 else
00272 {
00273 if (align.isLeft())
00274 {
00275 offset.left = 0;
00276 }
00277 else if (align.isRight())
00278 {
00279 offset.left = contentSize.width - viewSize.width;
00280 }
00281 else
00282 {
00283 offset.left = (contentSize.width - viewSize.width) / 2;
00284 }
00285 }
00286
00287 if (contentSize.height > viewSize.height)
00288 {
00289
00290 if ((offset.top + viewSize.height) > contentSize.height)
00291 {
00292 offset.top = contentSize.height - viewSize.height;
00293 }
00294
00295 else if (offset.top < 0)
00296 {
00297 offset.top = 0;
00298 }
00299 }
00300 else
00301 {
00302 if (align.isTop())
00303 {
00304 offset.top = 0;
00305 }
00306 else if (align.isBottom())
00307 {
00308 offset.top = contentSize.height - viewSize.height;
00309 }
00310 else
00311 {
00312 offset.top = (contentSize.height - viewSize.height) / 2;
00313 }
00314 }
00315
00316 if (offset != contentPoint)
00317 {
00318 if (nullptr != mVScroll) mVScroll->setScrollPosition(offset.top);
00319 if (nullptr != mHScroll) mHScroll->setScrollPosition(offset.left);
00320 setContentPosition(offset);
00321 }
00322 }
00323
00324 }