Minor refactor to pass draw regions in display::expose()

This commit is contained in:
Tommy 2022-07-29 06:18:09 +12:00
parent 4ece911e07
commit b8d4f49858
4 changed files with 54 additions and 35 deletions

View file

@ -1458,15 +1458,26 @@ void display::draw_label(const theme::label& label)
}
}
void display::draw_all_panels()
bool display::draw_all_panels(const rect& region)
{
bool drew = false;
const rect game_canvas = video::game_canvas();
for(const auto& panel : theme_.panels()) {
draw_panel(panel);
if(region.overlaps(panel.location(game_canvas))) {
draw_panel(panel);
drew = true;
}
}
for(const auto& label : theme_.labels()) {
draw_label(label);
if(region.overlaps(label.location(game_canvas))) {
draw_label(label);
drew = true;
}
}
return drew;
}
void display::draw_text_in_hex(const map_location& loc,
@ -2574,28 +2585,30 @@ void display::render()
bool display::expose(const SDL_Rect& region)
{
// Note: clipping region is set by draw_manager,
// and will be contained by <region>.
if(prevent_draw_) {
DBG_DP << "draw prevented";
return false;
}
rect clipped_region = draw::get_clip().intersect(region);
// Blit from the pre-rendered front buffer.
front_.set_src(region);
draw::blit(front_, region);
front_.clear_src();
if(clipped_region.overlaps(map_outside_area())) {
front_.set_src(clipped_region);
draw::blit(front_, clipped_region);
front_.clear_src();
}
// Render halos.
// TODO: draw_manager - halo render region not rely on clip?
halo_man_.render();
halo_man_.render(clipped_region);
// These all check for clip region overlap before drawing
draw_all_panels();
draw_reports();
draw_minimap();
draw_buttons();
// Render UI elements.
draw_all_panels(clipped_region);
draw_reports(clipped_region);
if(clipped_region.overlaps(minimap_area())) {
draw_minimap();
}
//draw_buttons();
// TODO: draw_manager - hmm... buttons redraw over tooltips, because they are TLDs
font::draw_floating_labels();
@ -2607,7 +2620,9 @@ bool display::expose(const SDL_Rect& region)
DBG_DP << "display::expose " << region;
return true; // TODO: draw_manager - maybe don't flip yeah?
// The display covers the entire screen.
// We will always be drawing something.
return true;
}
rect display::screen_location()
@ -3141,17 +3156,18 @@ void display::draw_report(const std::string& report_name, bool tooltip_test)
}
}
// TODO: draw_manager - pass in bounds in stead of using clip region
// TODO: draw_manager - return whether anything was drawn
void display::draw_reports()
bool display::draw_reports(const rect& region)
{
bool drew = false;
for(const auto& it : reports_) {
const std::string& name = it.first;
const rect& loc = reportLocations_[name];
if(loc.overlaps(draw::get_clip())) {
if(loc.overlaps(region)) {
draw_report(name);
drew = true;
}
}
return drew;
}
void display::invalidate_all()

View file

@ -413,8 +413,9 @@ public:
*/
void draw_report(const std::string& report_name, bool test_run = false);
/** Draw all reports. This will respect the clipping region, if set. */
void draw_reports();
/** Draw all reports in the given region.
* Returns true if something was drawn, false otherwise. */
bool draw_reports(const rect& region);
void draw_minimap_units();
@ -1086,8 +1087,10 @@ protected:
/** Clears the drawing buffer. */
void drawing_buffer_clear();
/** redraw all panels associated with the map display */
void draw_all_panels();
/** Redraws all panels intersecting the given region.
* Returns true if something was drawn, false otherwise. */
bool draw_all_panels(const rect& region);
private:
void draw_panel(const theme::panel& panel);
void draw_label(const theme::label& label);

View file

@ -146,7 +146,9 @@ class halo_impl
void remove(int handle);
void update();
void render();
/** Render all halos overlapping the given region */
void render(const rect&);
}; //end halo_impl
@ -404,17 +406,14 @@ void halo_impl::update()
}
}
void halo_impl::render()
void halo_impl::render(const rect& region)
{
if(haloes.empty()) {
return;
}
// TODO: draw_manager - pass in rect in stead of assuming clip makes sense
rect clip = draw::get_clip();
for(auto& [id, effect] : haloes) {
if(clip.overlaps(effect.get_draw_location())) {
if(region.overlaps(effect.get_draw_location())) {
DBG_HL << "drawing intersected halo " << id;
effect.render();
}
@ -456,9 +455,9 @@ void manager::update()
impl_->update();
}
void manager::render()
void manager::render(const rect& r)
{
impl_->render();
impl_->render(r);
}
// end halo::manager implementation

View file

@ -16,6 +16,7 @@
#pragma once
class display;
struct rect;
#include "map/location.hpp"
@ -62,8 +63,8 @@ public:
* regions now requiring redraw. */
void update();
/** Render halos. */
void render();
/** Render halos in region. */
void render(const rect& r);
private:
std::shared_ptr<halo_impl> impl_;