Skip to content

Commit

Permalink
Disable use of CTT for color picker.
Browse files Browse the repository at this point in the history
- Address issue #27.
- Temporarily disable cache to texture. Broken with Allegro 5.2.
  • Loading branch information
billyquith committed Aug 2, 2016
1 parent cca52e2 commit 82994b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion source/gwork/source/Controls/HSVColorPicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ GWK_CONTROL_CONSTRUCTOR(HSVColorPicker)
{
SetMouseInputEnabled(true);
SetSize(256, 64);
EnableCacheToTexture();
// EnableCacheToTexture(); // TODO - fix texture caching.

m_lerpBox = new Gwk::Controls::ColorLerpBox(this);
m_lerpBox->onSelectionChanged.Add(this, &HSVColorPicker::ColorBoxChanged);
Expand Down
23 changes: 14 additions & 9 deletions source/platform/renderers/Allegro5/Allegro5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AllegroCTT : public ICacheToTexture
{
public:

AllegroCTT() : m_oSWindowldTarget(nullptr) {}
AllegroCTT() : m_oldTarget(nullptr) {}
~AllegroCTT() {}

void Initialize() {}
Expand Down Expand Up @@ -53,7 +53,7 @@ class AllegroCTT : public ICacheToTexture
typedef std::map< CacheHandle, CacheEntry > CacheMap;
CacheMap m_cache;

ALLEGRO_BITMAP *m_oSWindowldTarget;
ALLEGRO_BITMAP *m_oldTarget;
};

void AllegroCTT::ShutDown()
Expand All @@ -68,6 +68,7 @@ void AllegroCTT::CreateControlCacheTexture(CacheHandle control, const Point& siz
// If we haven't seen this control before, create a new entry.
if (m_cache.find(control) == m_cache.end())
{
al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);
CacheEntry newEntry = { al_create_bitmap(size.x, size.y) };
m_cache.insert(std::pair<CacheHandle,CacheEntry>(control, newEntry));
}
Expand All @@ -80,18 +81,22 @@ void AllegroCTT::SetupCacheTexture(CacheHandle control)
if (it != m_cache.end())
{
// Prepare for rendering.
assert(m_oSWindowldTarget==nullptr);
m_oSWindowldTarget = al_get_target_bitmap();
al_set_target_bitmap((*it).second.m_bitmap);
al_clear_to_color(al_map_rgb_f(1.f,1.f,1.f));
assert(m_oldTarget==nullptr);
m_oldTarget = al_get_target_bitmap();

auto albmp = it->second.m_bitmap;
assert(albmp != nullptr);
al_set_target_bitmap(albmp);

al_clear_to_color(al_map_rgb_f(1.f, 1.f, 1.f));
}
}

void AllegroCTT::FinishCacheTexture(CacheHandle control)
{
// Prepare for rendering.
al_set_target_bitmap(m_oSWindowldTarget);
m_oSWindowldTarget = nullptr;
al_set_target_bitmap(m_oldTarget);
m_oldTarget = nullptr;
}

void AllegroCTT::DrawCachedControlTexture(CacheHandle control)
Expand All @@ -100,7 +105,7 @@ void AllegroCTT::DrawCachedControlTexture(CacheHandle control)
assert(it != m_cache.end());
if (it != m_cache.end())
{
ALLEGRO_BITMAP *bmp = (*it).second.m_bitmap;
ALLEGRO_BITMAP *bmp = it->second.m_bitmap;
const Gwk::Point &pos = m_renderer->GetRenderOffset();
al_draw_bitmap(bmp, pos.x, pos.y, 0);
}
Expand Down

0 comments on commit 82994b3

Please sign in to comment.