2015-07-08 08:39:24 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ui.hpp"
|
2017-08-03 19:06:59 +01:00
|
|
|
#include "sine_table.hpp"
|
2015-07-08 08:39:24 -07:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
2017-08-27 21:03:17 +01:00
|
|
|
// CGA palette
|
|
|
|
Color term_colors[16] = {
|
2017-08-17 12:56:47 +01:00
|
|
|
Color::black(),
|
2017-08-27 21:03:17 +01:00
|
|
|
Color::dark_blue(),
|
|
|
|
Color::dark_green(),
|
|
|
|
Color::dark_cyan(),
|
|
|
|
Color::dark_red(),
|
|
|
|
Color::dark_magenta(),
|
|
|
|
Color::dark_yellow(),
|
|
|
|
Color::light_grey(),
|
|
|
|
Color::dark_grey(),
|
2017-08-17 12:56:47 +01:00
|
|
|
Color::blue(),
|
2017-08-27 21:03:17 +01:00
|
|
|
Color::green(),
|
2017-08-17 12:56:47 +01:00
|
|
|
Color::cyan(),
|
2017-08-27 21:03:17 +01:00
|
|
|
Color::red(),
|
|
|
|
Color::magenta(),
|
|
|
|
Color::yellow(),
|
2017-08-17 12:56:47 +01:00
|
|
|
Color::white()
|
|
|
|
};
|
|
|
|
|
2015-07-08 08:39:24 -07:00
|
|
|
bool Rect::contains(const Point p) const {
|
2016-11-28 10:39:10 -08:00
|
|
|
return (p.x() >= left()) && (p.y() >= top()) &&
|
|
|
|
(p.x() < right()) && (p.y() < bottom());
|
2015-07-08 08:39:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Rect Rect::intersect(const Rect& o) const {
|
|
|
|
const auto x1 = std::max(left(), o.left());
|
|
|
|
const auto x2 = std::min(right(), o.right());
|
|
|
|
const auto y1 = std::max(top(), o.top());
|
|
|
|
const auto y2 = std::min(bottom(), o.bottom());
|
|
|
|
if( (x2 >= x1) && (y2 > y1) ) {
|
2016-01-23 17:02:16 -08:00
|
|
|
return { x1, y1, x2 - x1, y2 - y1 };
|
2015-07-08 08:39:24 -07:00
|
|
|
} else {
|
|
|
|
return { };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-07 22:19:30 -07:00
|
|
|
// TODO: This violates the principle of least surprise!
|
|
|
|
// This does a union, but that might not be obvious from "+=" syntax.
|
2015-07-08 08:39:24 -07:00
|
|
|
Rect& Rect::operator+=(const Rect& p) {
|
|
|
|
if( is_empty() ) {
|
|
|
|
*this = p;
|
|
|
|
}
|
|
|
|
if( !p.is_empty() ) {
|
|
|
|
const auto x1 = std::min(left(), p.left());
|
|
|
|
const auto y1 = std::min(top(), p.top());
|
2016-11-28 11:25:27 -08:00
|
|
|
_pos = { x1, y1 };
|
2015-07-08 08:39:24 -07:00
|
|
|
const auto x2 = std::max(right(), p.right());
|
|
|
|
const auto y2 = std::max(bottom(), p.bottom());
|
2016-11-28 11:25:27 -08:00
|
|
|
_size = { x2 - x1, y2 - y1 };
|
2015-07-08 08:39:24 -07:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-09-07 22:18:11 -07:00
|
|
|
Rect& Rect::operator+=(const Point& p) {
|
2016-11-28 11:25:27 -08:00
|
|
|
_pos += p;
|
2016-09-07 22:18:11 -07:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-11-28 10:39:10 -08:00
|
|
|
Rect& Rect::operator-=(const Point& p) {
|
2016-11-28 11:25:27 -08:00
|
|
|
_pos -= p;
|
2016-11-28 10:39:10 -08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2017-08-03 19:06:59 +01:00
|
|
|
Point polar_to_point(float angle, uint32_t distance) {
|
2020-07-01 13:16:48 -05:00
|
|
|
//polar to compass with y negated for screen drawing
|
|
|
|
return Point(sin_f32(DEG_TO_RAD(-angle) + pi) * distance,
|
|
|
|
sin_f32(DEG_TO_RAD(-angle) - (pi / 2)) * distance);
|
2017-08-03 19:06:59 +01:00
|
|
|
}
|
|
|
|
|
2015-07-08 08:39:24 -07:00
|
|
|
} /* namespace ui */
|