mirror of https://github.com/stella-emu/stella.git
Cleaned up the Rect class, which is something I've been meaning to do
for a long time. Changed to unsigned int everywhere, and removed functions that I will never use (the class originally came from ScummVM). git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2923 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
05c007cbae
commit
815e0b2d33
|
@ -115,7 +115,7 @@ bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode,
|
||||||
{
|
{
|
||||||
int w, h;
|
int w, h;
|
||||||
SDL_GetWindowSize(myWindow, &w, &h);
|
SDL_GetWindowSize(myWindow, &w, &h);
|
||||||
if(w != mode.screen.w || h != mode.screen.h)
|
if((uInt32)w != mode.screen.w || (uInt32)h != mode.screen.h)
|
||||||
{
|
{
|
||||||
SDL_DestroyWindow(myWindow);
|
SDL_DestroyWindow(myWindow);
|
||||||
myWindow = NULL;
|
myWindow = NULL;
|
||||||
|
|
|
@ -168,8 +168,8 @@ void Debugger::initialize()
|
||||||
{
|
{
|
||||||
// Get the dialog size
|
// Get the dialog size
|
||||||
const GUI::Size& size = myOSystem->settings().getSize("dbg.res");
|
const GUI::Size& size = myOSystem->settings().getSize("dbg.res");
|
||||||
myWidth = BSPF_max(size.w, 0);
|
myWidth = BSPF_max(size.w, 0u);
|
||||||
myHeight = BSPF_max(size.h, 0);
|
myHeight = BSPF_max(size.h, 0u);
|
||||||
myWidth = BSPF_max(myWidth, (uInt32)DebuggerDialog::kSmallFontMinW);
|
myWidth = BSPF_max(myWidth, (uInt32)DebuggerDialog::kSmallFontMinW);
|
||||||
myHeight = BSPF_max(myHeight, (uInt32)DebuggerDialog::kSmallFontMinH);
|
myHeight = BSPF_max(myHeight, (uInt32)DebuggerDialog::kSmallFontMinH);
|
||||||
myOSystem->settings().setValue("dbg.res", GUI::Size(myWidth, myHeight));
|
myOSystem->settings().setValue("dbg.res", GUI::Size(myWidth, myHeight));
|
||||||
|
|
|
@ -110,8 +110,8 @@ void ContextMenu::recalc(const GUI::Rect& image)
|
||||||
{
|
{
|
||||||
// Now is the time to adjust the height
|
// Now is the time to adjust the height
|
||||||
// If it's higher than the screen, we need to scroll through
|
// If it's higher than the screen, we need to scroll through
|
||||||
int maxentries = BSPF_min(18, (image.height() - 4) / _rowHeight);
|
uInt32 maxentries = BSPF_min(18u, (image.height() - 4) / _rowHeight);
|
||||||
if((int)_entries.size() > maxentries)
|
if(_entries.size() > maxentries)
|
||||||
{
|
{
|
||||||
// We show two less than the max, so we have room for two scroll buttons
|
// We show two less than the max, so we have room for two scroll buttons
|
||||||
_numEntries = maxentries - 2;
|
_numEntries = maxentries - 2;
|
||||||
|
|
|
@ -113,9 +113,6 @@ void DialogContainer::draw(bool full)
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void DialogContainer::addDialog(Dialog* d)
|
void DialogContainer::addDialog(Dialog* d)
|
||||||
{
|
{
|
||||||
const GUI::Size& screen = myOSystem->frameBuffer().screenSize();
|
|
||||||
assert(d->getWidth() <= screen.w && d->getHeight() <= screen.h);
|
|
||||||
|
|
||||||
myDialogStack.push(d);
|
myDialogStack.push(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
104
src/gui/Rect.hxx
104
src/gui/Rect.hxx
|
@ -60,19 +60,19 @@ struct Point
|
||||||
|
|
||||||
struct Size
|
struct Size
|
||||||
{
|
{
|
||||||
int w; //!< The width part of the size
|
uInt32 w; //!< The width part of the size
|
||||||
int h; //!< The height part of the size
|
uInt32 h; //!< The height part of the size
|
||||||
|
|
||||||
Size() : w(0), h(0) {};
|
Size() : w(0), h(0) {};
|
||||||
Size(const Size & s) : w(s.w), h(s.h) {};
|
Size(const Size & s) : w(s.w), h(s.h) {};
|
||||||
explicit Size(int w1, int h1) : w(w1), h(h1) {};
|
explicit Size(uInt32 w1, uInt32 h1) : w(w1), h(h1) {};
|
||||||
Size(const string& s) {
|
Size(const string& s) {
|
||||||
char c = '\0';
|
char c = '\0';
|
||||||
w = h = -1;
|
w = h = 0;
|
||||||
istringstream buf(s);
|
istringstream buf(s);
|
||||||
buf >> w >> c >> h;
|
buf >> w >> c >> h;
|
||||||
if(c != 'x')
|
if(c != 'x')
|
||||||
w = h = -1;
|
w = h = 0;
|
||||||
}
|
}
|
||||||
Size & operator=(const Size & s) { w = s.w; h = s.h; return *this; };
|
Size & operator=(const Size & s) { w = s.w; h = s.h; return *this; };
|
||||||
bool operator==(const Size & s) const { return w == s.w && h == s.h; };
|
bool operator==(const Size & s) const { return w == s.w && h == s.h; };
|
||||||
|
@ -103,110 +103,42 @@ struct Size
|
||||||
*/
|
*/
|
||||||
struct Rect
|
struct Rect
|
||||||
{
|
{
|
||||||
int top, left; //!< The point at the top left of the rectangle (part of the rect).
|
uInt32 top, left; //!< The point at the top left of the rectangle (part of the rect).
|
||||||
int bottom, right; //!< The point at the bottom right of the rectangle (not part of the rect).
|
uInt32 bottom, right; //!< The point at the bottom right of the rectangle (not part of the rect).
|
||||||
|
|
||||||
Rect() : top(0), left(0), bottom(0), right(0) {}
|
Rect() : top(0), left(0), bottom(0), right(0) {}
|
||||||
Rect(int w, int h) : top(0), left(0), bottom(h), right(w) {}
|
Rect(uInt32 w, uInt32 h) : top(0), left(0), bottom(h), right(w) {}
|
||||||
Rect(const Point& p, int w, int h) : top(p.y), left(p.x), bottom(h), right(w) {}
|
Rect(const Point& p, uInt32 w, uInt32 h) : top(p.y), left(p.x), bottom(h), right(w) {}
|
||||||
Rect(int x1, int y1, int x2, int y2) : top(y1), left(x1), bottom(y2), right(x2)
|
Rect(uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2) : top(y1), left(x1), bottom(y2), right(x2)
|
||||||
{
|
{
|
||||||
assert(isValidRect());
|
assert(isValidRect());
|
||||||
}
|
}
|
||||||
|
|
||||||
int x() const { return left; }
|
uInt32 x() const { return left; }
|
||||||
int y() const { return top; }
|
uInt32 y() const { return top; }
|
||||||
Point point() const { return Point(x(), y()); }
|
Point point() const { return Point(x(), y()); }
|
||||||
|
|
||||||
int width() const { return right - left; }
|
uInt32 width() const { return right - left; }
|
||||||
int height() const { return bottom - top; }
|
uInt32 height() const { return bottom - top; }
|
||||||
Size size() const { return Size(width(), height()); }
|
Size size() const { return Size(width(), height()); }
|
||||||
|
|
||||||
void setWidth(int aWidth) { right = left + aWidth; }
|
void setWidth(uInt32 aWidth) { right = left + aWidth; }
|
||||||
void setHeight(int aHeight) { bottom = top + aHeight; }
|
void setHeight(uInt32 aHeight) { bottom = top + aHeight; }
|
||||||
void setSize(const Size& size) { setWidth(size.w); setHeight(size.h); }
|
void setSize(const Size& size) { setWidth(size.w); setHeight(size.h); }
|
||||||
|
|
||||||
void setBounds(int x1, int y1, int x2, int y2) {
|
void setBounds(uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2) {
|
||||||
top = y1;
|
top = y1;
|
||||||
left = x1;
|
left = x1;
|
||||||
bottom = y2;
|
bottom = y2;
|
||||||
right = x2;
|
right = x2;
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
@param x the horizontal position to check
|
|
||||||
@param y the vertical position to check
|
|
||||||
|
|
||||||
@return true if the given position is inside this rectangle, false otherwise
|
|
||||||
*/
|
|
||||||
bool contains(int x, int y) const {
|
|
||||||
return (left <= x) && (x < right) && (top <= y) && (y < bottom);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
@param p the point to check
|
|
||||||
|
|
||||||
@return true if the given point is inside this rectangle, false otherwise
|
|
||||||
*/
|
|
||||||
bool contains(const Point & p) const { return contains(p.x, p.y); }
|
|
||||||
|
|
||||||
/*
|
|
||||||
@param r the rectangle to check
|
|
||||||
|
|
||||||
@return true if the given rectangle is inside the rectangle, false otherwise
|
|
||||||
*/
|
|
||||||
bool intersects(const Rect & r) const {
|
|
||||||
return (left < r.right) && (r.left < right) && (top < r.bottom) && (r.top < bottom);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
@param r the rectangle to extend by
|
|
||||||
*/
|
|
||||||
void extend(const Rect & r) {
|
|
||||||
left = BSPF_min(left, r.left);
|
|
||||||
right = BSPF_max(right, r.right);
|
|
||||||
top = BSPF_min(top, r.top);
|
|
||||||
bottom = BSPF_max(bottom, r.bottom);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Extend this rectangle in all four directions by the given number of pixels
|
|
||||||
|
|
||||||
@param offset the size to grow by
|
|
||||||
*/
|
|
||||||
void grow(int offset) {
|
|
||||||
top -= offset;
|
|
||||||
left -= offset;
|
|
||||||
bottom += offset;
|
|
||||||
right += offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
void clip(const Rect & r) {
|
|
||||||
assert(isValidRect());
|
assert(isValidRect());
|
||||||
assert(r.isValidRect());
|
|
||||||
|
|
||||||
if (top < r.top) top = r.top;
|
|
||||||
else if (top > r.bottom) top = r.bottom;
|
|
||||||
|
|
||||||
if (left < r.left) left = r.left;
|
|
||||||
else if (left > r.right) left = r.right;
|
|
||||||
|
|
||||||
if (bottom > r.bottom) bottom = r.bottom;
|
|
||||||
else if (bottom < r.top) bottom = r.top;
|
|
||||||
|
|
||||||
if (right > r.right) right = r.right;
|
|
||||||
else if (right < r.left) right = r.left;
|
|
||||||
}
|
|
||||||
|
|
||||||
void clip(int maxw, int maxh) {
|
|
||||||
clip(Rect(0, 0, maxw, maxh));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isValidRect() const {
|
bool isValidRect() const {
|
||||||
return (left <= right && top <= bottom);
|
return (left <= right && top <= bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
void moveTo(int x, int y) {
|
void moveTo(uInt32 x, uInt32 y) {
|
||||||
bottom += y - top;
|
bottom += y - top;
|
||||||
right += x - left;
|
right += x - left;
|
||||||
top = y;
|
top = y;
|
||||||
|
|
|
@ -298,10 +298,10 @@ void UIDialog::loadConfig()
|
||||||
{
|
{
|
||||||
// Launcher size
|
// Launcher size
|
||||||
const GUI::Size& ls = instance().settings().getSize("launcherres");
|
const GUI::Size& ls = instance().settings().getSize("launcherres");
|
||||||
int w = ls.w, h = ls.h;
|
uInt32 w = ls.w, h = ls.h;
|
||||||
|
|
||||||
w = BSPF_max(w, (int)FrameBuffer::kFBMinW);
|
w = BSPF_max(w, (uInt32)FrameBuffer::kFBMinW);
|
||||||
h = BSPF_max(h, (int)FrameBuffer::kFBMinH);
|
h = BSPF_max(h, (uInt32)FrameBuffer::kFBMinH);
|
||||||
w = BSPF_min(w, instance().frameBuffer().desktopSize().w);
|
w = BSPF_min(w, instance().frameBuffer().desktopSize().w);
|
||||||
h = BSPF_min(h, instance().frameBuffer().desktopSize().h);
|
h = BSPF_min(h, instance().frameBuffer().desktopSize().h);
|
||||||
|
|
||||||
|
@ -326,10 +326,10 @@ void UIDialog::loadConfig()
|
||||||
// Debugger size
|
// Debugger size
|
||||||
const GUI::Size& ds = instance().settings().getSize("dbg.res");
|
const GUI::Size& ds = instance().settings().getSize("dbg.res");
|
||||||
w = ds.w, h = ds.h;
|
w = ds.w, h = ds.h;
|
||||||
w = BSPF_max(w, (int)DebuggerDialog::kSmallFontMinW);
|
w = BSPF_max(w, (uInt32)DebuggerDialog::kSmallFontMinW);
|
||||||
h = BSPF_max(h, (int)DebuggerDialog::kSmallFontMinH);
|
h = BSPF_max(h, (uInt32)DebuggerDialog::kSmallFontMinH);
|
||||||
w = BSPF_min(w, (int)ds.w);
|
w = BSPF_min(w, ds.w);
|
||||||
h = BSPF_min(h, (int)ds.h);
|
h = BSPF_min(h, ds.h);
|
||||||
|
|
||||||
myDebuggerWidthSlider->setValue(w);
|
myDebuggerWidthSlider->setValue(w);
|
||||||
myDebuggerWidthLabel->setValue(w);
|
myDebuggerWidthLabel->setValue(w);
|
||||||
|
@ -399,8 +399,8 @@ void UIDialog::setDefaults()
|
||||||
{
|
{
|
||||||
case 0: // Launcher options
|
case 0: // Launcher options
|
||||||
{
|
{
|
||||||
int w = BSPF_min(instance().frameBuffer().desktopSize().w, (int)FrameBuffer::kFBMinW);
|
uInt32 w = BSPF_min(instance().frameBuffer().desktopSize().w, (uInt32)FrameBuffer::kFBMinW);
|
||||||
int h = BSPF_min(instance().frameBuffer().desktopSize().h, (int)FrameBuffer::kFBMinH);
|
uInt32 h = BSPF_min(instance().frameBuffer().desktopSize().h, (uInt32)FrameBuffer::kFBMinH);
|
||||||
myLauncherWidthSlider->setValue(w);
|
myLauncherWidthSlider->setValue(w);
|
||||||
myLauncherWidthLabel->setValue(w);
|
myLauncherWidthLabel->setValue(w);
|
||||||
myLauncherHeightSlider->setValue(h);
|
myLauncherHeightSlider->setValue(h);
|
||||||
|
@ -414,8 +414,8 @@ void UIDialog::setDefaults()
|
||||||
case 1: // Debugger options
|
case 1: // Debugger options
|
||||||
{
|
{
|
||||||
#ifdef DEBUGGER_SUPPORT
|
#ifdef DEBUGGER_SUPPORT
|
||||||
int w = BSPF_min(instance().frameBuffer().desktopSize().w, (int)DebuggerDialog::kMediumFontMinW);
|
uInt32 w = BSPF_min(instance().frameBuffer().desktopSize().w, (uInt32)DebuggerDialog::kMediumFontMinW);
|
||||||
int h = BSPF_min(instance().frameBuffer().desktopSize().h, (int)DebuggerDialog::kMediumFontMinH);
|
uInt32 h = BSPF_min(instance().frameBuffer().desktopSize().h, (uInt32)DebuggerDialog::kMediumFontMinH);
|
||||||
myDebuggerWidthSlider->setValue(w);
|
myDebuggerWidthSlider->setValue(w);
|
||||||
myDebuggerWidthLabel->setValue(w);
|
myDebuggerWidthLabel->setValue(w);
|
||||||
myDebuggerHeightSlider->setValue(h);
|
myDebuggerHeightSlider->setValue(h);
|
||||||
|
|
Loading…
Reference in New Issue