selective clearing
This commit is contained in:
parent
483131062f
commit
9bb36c990d
7 changed files with 98 additions and 30 deletions
|
|
@ -17,7 +17,6 @@ License along with this library; if not, write to the Free Software
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
module Crafter.Graphics:Window_impl;
|
||||
import :Window;
|
||||
import :Transform;
|
||||
|
|
@ -25,7 +24,7 @@ import std;
|
|||
|
||||
using namespace Crafter;
|
||||
|
||||
Window::Window(std::uint_fast32_t width, std::uint_fast32_t height) : width(width), height(height) {
|
||||
Window::Window(std::int_fast32_t width, std::int_fast32_t height) : width(width), height(height) {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -97,4 +96,32 @@ void Window::LogTiming() {
|
|||
duration_cast<std::chrono::milliseconds>(max)) << std::endl;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
bool Overlaps(const ScaleData& rect1, const ScaleData& rect2) {
|
||||
return !(rect1.x + rect1.width <= rect2.x || rect2.x + rect2.width <= rect1.x || rect1.y + rect1.height <= rect2.y || rect2.y + rect2.height <= rect1.y);
|
||||
}
|
||||
|
||||
ScaleData MergeRects(const ScaleData& rect1, const ScaleData& rect2) {
|
||||
ScaleData merged;
|
||||
merged.x = std::min(rect1.x, rect2.x);
|
||||
merged.y = std::min(rect1.y, rect2.y);
|
||||
merged.width = std::max(rect1.x + rect1.width, rect2.x + rect2.width) - merged.x;
|
||||
merged.height = std::max(rect1.y + rect1.height, rect2.y + rect2.height) - merged.y;
|
||||
return merged;
|
||||
}
|
||||
|
||||
void Window::AddDirtyRect(ScaleData rect) {
|
||||
bool merged = false;
|
||||
for (auto& existingRect : dirtyRects) {
|
||||
if (Overlaps(existingRect, rect)) {
|
||||
existingRect = MergeRects(existingRect, rect);
|
||||
merged = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!merged) {
|
||||
dirtyRects.push_back(rect);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue