Add ResourcesListBox as a generic version of PalettesListBox

This commit is contained in:
David Capello 2014-06-15 23:05:14 -03:00
parent c639b4dba3
commit 76ec93ea80
14 changed files with 499 additions and 147 deletions

View File

@ -137,9 +137,10 @@ add_library(app-lib
modules/gui.cpp
modules/palettes.cpp
objects_container_impl.cpp
palettes_loader.cpp
project.cpp
recent_files.cpp
res/palettes_loader_delegate.cpp
res/resources_loader.cpp
resource_finder.cpp
settings/ui_settings_impl.cpp
shell.cpp
@ -184,10 +185,11 @@ add_library(app-lib
ui/main_window.cpp
ui/mini_editor.cpp
ui/notifications.cpp
ui/palette_listbox.cpp
ui/palettes_listbox.cpp
ui/palette_popup.cpp
ui/palette_view.cpp
ui/popup_window_pin.cpp
ui/resources_listbox.cpp
ui/skin/button_icon_impl.cpp
ui/skin/skin_part.cpp
ui/skin/skin_property.cpp

View File

@ -0,0 +1,48 @@
/* Aseprite
* Copyright (C) 2014 David Capello
*
* 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 of the License, 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; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef APP_RES_PALETTE_RESOURCE_H_INCLUDED
#define APP_RES_PALETTE_RESOURCE_H_INCLUDED
#pragma once
#include "app/res/resource.h"
namespace raster {
class Palette;
}
namespace app {
class PaletteResource : public Resource {
public:
PaletteResource(raster::Palette* palette, const std::string& name)
: m_palette(palette)
, m_name(name) {
}
virtual ~PaletteResource() { }
virtual raster::Palette* palette() { return m_palette; }
virtual const std::string& name() const OVERRIDE { return m_name; }
private:
raster::Palette* m_palette;
std::string m_name;
};
} // namespace app
#endif

View File

@ -0,0 +1,59 @@
/* Aseprite
* Copyright (C) 2014 David Capello
*
* 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 of the License, 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; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/res/palettes_loader_delegate.h"
#include "app/file_system.h"
#include "app/res/palette_resource.h"
#include "app/resource_finder.h"
#include "base/bind.h"
#include "base/fs.h"
#include "base/path.h"
#include "base/scoped_value.h"
#include "raster/palette.h"
namespace app {
std::string PalettesLoaderDelegate::resourcesLocation() const
{
std::string path;
ResourceFinder rf;
rf.includeDataDir("palettes");
while (rf.next()) {
if (base::is_directory(rf.filename())) {
path = rf.filename();
break;
}
}
return base::fix_path_separators(path);
}
Resource* PalettesLoaderDelegate::loadResource(const std::string& filename)
{
raster::Palette* palette = raster::Palette::load(filename.c_str());
if (!palette)
return NULL;
return new PaletteResource(palette, base::get_file_title(filename));
}
} // namespace app

View File

@ -0,0 +1,37 @@
/* Aseprite
* Copyright (C) 2014 David Capello
*
* 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 of the License, 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; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef APP_RES_PALETTES_LOADER_DELEGATE_H_INCLUDED
#define APP_RES_PALETTES_LOADER_DELEGATE_H_INCLUDED
#pragma once
#include "app/res/resources_loader_delegate.h"
#include "base/compiler_specific.h"
namespace app {
class PalettesLoaderDelegate : public ResourcesLoaderDelegate {
public:
// ResourcesLoaderDelegate impl
virtual std::string resourcesLocation() const OVERRIDE;
virtual Resource* loadResource(const std::string& filename) OVERRIDE;
};
} // namespace app
#endif

33
src/app/res/resource.h Normal file
View File

@ -0,0 +1,33 @@
/* Aseprite
* Copyright (C) 2014 David Capello
*
* 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 of the License, 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; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef APP_RES_RESOURCE_H_INCLUDED
#define APP_RES_RESOURCE_H_INCLUDED
#pragma once
namespace app {
class Resource {
public:
virtual ~Resource() { }
virtual const std::string& name() const = 0;
};
} // namespace app
#endif

View File

@ -1,5 +1,5 @@
/* Aseprite
* Copyright (C) 2001-2014 David Capello
* Copyright (C) 2014 David Capello
*
* 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
@ -20,78 +20,63 @@
#include "config.h"
#endif
#include "app/palettes_loader.h"
#include "app/res/resources_loader.h"
#include "app/file_system.h"
#include "app/res/resources_loader_delegate.h"
#include "app/resource_finder.h"
#include "base/bind.h"
#include "base/fs.h"
#include "base/path.h"
#include "base/scoped_value.h"
#include "raster/palette.h"
namespace app {
PalettesLoader::PalettesLoader()
: m_done(false)
ResourcesLoader::ResourcesLoader(ResourcesLoaderDelegate* delegate)
: m_delegate(delegate)
, m_done(false)
, m_cancel(false)
, m_thread(Bind<void>(&PalettesLoader::threadLoadPalettes, this))
, m_thread(Bind<void>(&ResourcesLoader::threadLoadResources, this))
{
PRINTF("PalettesLoader::PalettesLoader()\n");
PRINTF("ResourcesLoader::ResourcesLoader()\n");
}
PalettesLoader::~PalettesLoader()
ResourcesLoader::~ResourcesLoader()
{
m_thread.join();
PRINTF("PalettesLoader::~PalettesLoader()\n");
PRINTF("ResourcesLoader::~ResourcesLoader()\n");
}
void PalettesLoader::cancel()
void ResourcesLoader::cancel()
{
m_cancel = true;
}
bool PalettesLoader::done()
bool ResourcesLoader::done()
{
return m_done;
}
bool PalettesLoader::next(base::UniquePtr<raster::Palette>& palette, std::string& name)
bool ResourcesLoader::next(base::UniquePtr<Resource>& resource)
{
Item item;
if (m_queue.try_pop(item)) {
palette.reset(item.palette);
name = item.name;
Resource* rawResource;
if (m_queue.try_pop(rawResource)) {
resource.reset(rawResource);
return true;
}
else
return false;
}
// static
std::string PalettesLoader::palettesLocation()
void ResourcesLoader::threadLoadResources()
{
std::string path;
ResourceFinder rf;
rf.includeDataDir("palettes");
while (rf.next()) {
if (base::is_directory(rf.filename())) {
path = rf.filename();
break;
}
}
return base::fix_path_separators(path);
}
void PalettesLoader::threadLoadPalettes()
{
PRINTF("threadLoadPalettes()\n");
PRINTF("threadLoadResources()\n");
base::ScopedValue<bool> scoped(m_done, false, true);
std::string path = palettesLocation();
PRINTF("Loading palettes from %s...\n", path.c_str());
std::string path = m_delegate->resourcesLocation();
PRINTF("Loading resources from %s...\n", path.c_str());
if (path.empty())
return;
@ -108,12 +93,9 @@ void PalettesLoader::threadLoadPalettes()
if (m_cancel)
break;
raster::Palette* palette =
raster::Palette::load((*it)->getFileName().c_str());
if (palette) {
m_queue.push(Item(palette, base::get_file_title((*it)->getFileName())));
}
Resource* resource = m_delegate->loadResource((*it)->getFileName());
if (resource)
m_queue.push(resource);
}
}

View File

@ -1,5 +1,5 @@
/* Aseprite
* Copyright (C) 2001-2014 David Capello
* Copyright (C) 2014 David Capello
*
* 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
@ -16,50 +16,36 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef APP_PALETTES_LOADER_H_INCLUDED
#define APP_PALETTES_LOADER_H_INCLUDED
#ifndef APP_RES_RESOURCES_LOADER_H_INCLUDED
#define APP_RES_RESOURCES_LOADER_H_INCLUDED
#pragma once
#include "base/concurrent_queue.h"
#include "base/thread.h"
#include "base/unique_ptr.h"
#include <string>
namespace raster {
class Palette;
}
namespace app {
class PalettesLoader {
class Resource;
class ResourcesLoaderDelegate;
class ResourcesLoader {
public:
PalettesLoader();
~PalettesLoader();
ResourcesLoader(ResourcesLoaderDelegate* delegate);
~ResourcesLoader();
void cancel();
bool done();
bool isDone() const { return m_done; }
bool next(base::UniquePtr<raster::Palette>& palette, std::string& name);
static std::string palettesLocation();
bool next(base::UniquePtr<Resource>& resource);
private:
void threadLoadPalettes();
void threadLoadResources();
struct Item {
raster::Palette* palette;
std::string name;
Item() : palette(NULL) {
}
Item(raster::Palette* palette, const std::string& name)
: palette(palette), name(name) {
}
};
typedef base::concurrent_queue<Item> Queue;
typedef base::concurrent_queue<Resource*> Queue;
ResourcesLoaderDelegate* m_delegate;
bool m_done;
bool m_cancel;
Queue m_queue;

View File

@ -0,0 +1,38 @@
/* Aseprite
* Copyright (C) 2014 David Capello
*
* 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 of the License, 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; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef APP_RES_RESOURCES_LOADER_DELEGATE_H_INCLUDED
#define APP_RES_RESOURCES_LOADER_DELEGATE_H_INCLUDED
#pragma once
#include <string>
namespace app {
class Resource;
class ResourcesLoaderDelegate {
public:
virtual ~ResourcesLoaderDelegate() { }
virtual std::string resourcesLocation() const = 0;
virtual Resource* loadResource(const std::string& filename) = 0;
};
} // namespace app
#endif

View File

@ -26,8 +26,8 @@
#include "app/commands/commands.h"
#include "app/launcher.h"
#include "app/load_widget.h"
#include "app/palettes_loader.h"
#include "app/ui/palette_listbox.h"
#include "app/res/palettes_loader_delegate.h"
#include "app/ui/palettes_listbox.h"
#include "app/ui_context.h"
#include "base/bind.h"
#include "ui/box.h"
@ -91,7 +91,7 @@ void PalettePopup::onLoad()
void PalettePopup::onOpenFolder()
{
launcher::open_folder(PalettesLoader::palettesLocation());
launcher::open_folder(PalettesLoaderDelegate().resourcesLocation());
}
} // namespace app

View File

@ -20,7 +20,7 @@
#define APP_UI_PALETTE_POPUP_H_INCLUDED
#pragma once
#include "app/ui/palette_listbox.h"
#include "app/ui/palettes_listbox.h"
#include "base/compiler_specific.h"
#include "ui/popup_window.h"
@ -45,7 +45,7 @@ namespace app {
private:
ui::View* m_view;
ui::Button* m_load;
PaletteListBox m_paletteListBox;
PalettesListBox m_paletteListBox;
};
} // namespace app

View File

@ -0,0 +1,94 @@
/* Aseprite
* Copyright (C) 2014 David Capello
*
* 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 of the License, 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; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/ui/palettes_listbox.h"
#include "app/modules/palettes.h"
#include "app/res/palette_resource.h"
#include "app/res/palettes_loader_delegate.h"
#include "app/ui/skin/skin_theme.h"
#include "base/bind.h"
#include "raster/palette.h"
#include "ui/graphics.h"
#include "ui/listitem.h"
#include "ui/message.h"
#include "ui/paint_event.h"
#include "ui/preferred_size_event.h"
#include "ui/view.h"
namespace app {
using namespace ui;
PalettesListBox::PalettesListBox()
: ResourcesListBox(new ResourcesLoader(new PalettesLoaderDelegate))
{
}
raster::Palette* PalettesListBox::selectedPalette()
{
Resource* resource = selectedResource();
if (!resource)
return NULL;
return static_cast<PaletteResource*>(resource)->palette();
}
void PalettesListBox::onResourceChange(Resource* resource)
{
ResourcesListBox::onResourceChange(resource);
raster::Palette* palette = static_cast<PaletteResource*>(resource)->palette();
PalChange(palette);
}
void PalettesListBox::onPaintResource(Graphics* g, const gfx::Rect& bounds, Resource* resource)
{
raster::Palette* palette = static_cast<PaletteResource*>(resource)->palette();
gfx::Rect box(
bounds.x, bounds.y+bounds.h-6*jguiscale(),
4*jguiscale(), 4*jguiscale());
for (int i=0; i<palette->size(); ++i) {
raster::color_t c = palette->getEntry(i);
g->fillRect(ui::rgba(
raster::rgba_getr(c),
raster::rgba_getg(c),
raster::rgba_getb(c)), box);
box.x += box.w;
}
// g->drawString(getText(), fgcolor, ui::ColorNone, false,
// gfx::Point(
// bounds.x + jguiscale()*2,
// bounds.y + bounds.h/2 - g->measureString(getText()).h/2));
}
void PalettesListBox::onResourcePreferredSize(Resource* resource, gfx::Size& size)
{
size = gfx::Size(0, (2+16+2)*jguiscale());
}
} // namespace app

View File

@ -1,5 +1,5 @@
/* Aseprite
* Copyright (C) 2001-2014 David Capello
* Copyright (C) 2014 David Capello
*
* 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
@ -16,38 +16,30 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef APP_UI_PALETTE_LISTBOX_H_INCLUDED
#define APP_UI_PALETTE_LISTBOX_H_INCLUDED
#ifndef APP_UI_PALETTES_LISTBOX_H_INCLUDED
#define APP_UI_PALETTES_LISTBOX_H_INCLUDED
#pragma once
#include "app/palettes_loader.h"
#include "base/compiler_specific.h"
#include "base/unique_ptr.h"
#include "ui/listbox.h"
#include "ui/timer.h"
#include "app/ui/resources_listbox.h"
namespace raster {
class Palette;
}
namespace app {
class PaletteListBox : public ui::ListBox {
class PalettesListBox : public ResourcesListBox {
public:
PaletteListBox();
PalettesListBox();
raster::Palette* selectedPalette();
Signal1<void, raster::Palette*> PalChange;
protected:
bool onProcessMessage(ui::Message* msg) OVERRIDE;
void onChangeSelectedItem() OVERRIDE;
void onTick();
void stop();
private:
base::UniquePtr<PalettesLoader> m_palettesLoader;
ui::Timer m_palettesTimer;
class LoadingItem;
LoadingItem* m_loadingItem;
virtual void onResourceChange(Resource* resource) OVERRIDE;
virtual void onPaintResource(ui::Graphics* g, const gfx::Rect& bounds, Resource* resource) OVERRIDE;
virtual void onResourcePreferredSize(Resource* resource, gfx::Size& size) OVERRIDE;
};
} // namespace app

View File

@ -1,5 +1,5 @@
/* Aseprite
* Copyright (C) 2001-2014 David Capello
* Copyright (C) 2014 David Capello
*
* 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
@ -20,13 +20,12 @@
#include "config.h"
#endif
#include "app/ui/palette_listbox.h"
#include "app/ui/resources_listbox.h"
#include "app/modules/palettes.h"
#include "app/palettes_loader.h"
#include "app/res/resource.h"
#include "app/res/resources_loader.h"
#include "app/ui/skin/skin_theme.h"
#include "base/bind.h"
#include "raster/palette.h"
#include "ui/graphics.h"
#include "ui/listitem.h"
#include "ui/message.h"
@ -39,14 +38,14 @@ namespace app {
using namespace ui;
using namespace skin;
class PaletteListItem : public ListItem {
class ResourceListItem : public ListItem {
public:
PaletteListItem(raster::Palette* palette, const std::string& name)
: ListItem(name), m_palette(palette) {
ResourceListItem(Resource* resource)
: ListItem(resource->name()), m_resource(resource) {
}
raster::Palette* palette() const {
return m_palette;
Resource* resource() const {
return m_resource;
}
protected:
@ -77,20 +76,19 @@ protected:
g->fillRect(bgcolor, bounds);
gfx::Rect box(
bounds.x, bounds.y+bounds.h-6*jguiscale(),
4*jguiscale(), 4*jguiscale());
static_cast<ResourcesListBox*>(getParent())->
paintResource(g, bounds, m_resource);
// for (int i=0; i<m_palette->size(); ++i) {
// raster::color_t c = m_resource->getEntry(i);
for (int i=0; i<m_palette->size(); ++i) {
raster::color_t c = m_palette->getEntry(i);
// g->fillRect(ui::rgba(
// raster::rgba_getr(c),
// raster::rgba_getg(c),
// raster::rgba_getb(c)), box);
g->fillRect(ui::rgba(
raster::rgba_getr(c),
raster::rgba_getg(c),
raster::rgba_getb(c)), box);
box.x += box.w;
}
// box.x += box.w;
// }
g->drawString(getText(), fgcolor, ui::ColorNone, false,
gfx::Point(
@ -100,14 +98,15 @@ protected:
void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE {
ev.setPreferredSize(
gfx::Size(0, (2+16+2)*jguiscale()));
static_cast<ResourcesListBox*>(getParent())->
preferredResourceSize(m_resource));
}
private:
base::UniquePtr<raster::Palette> m_palette;
base::UniquePtr<Resource> m_resource;
};
class PaletteListBox::LoadingItem : public ListItem {
class ResourcesListBox::LoadingItem : public ListItem {
public:
LoadingItem()
: ListItem("Loading")
@ -131,30 +130,40 @@ private:
int m_state;
};
PaletteListBox::PaletteListBox()
: m_palettesTimer(100)
ResourcesListBox::ResourcesListBox(ResourcesLoader* resourcesLoader)
: m_resourcesLoader(resourcesLoader)
, m_resourcesTimer(100)
, m_loadingItem(NULL)
{
m_palettesTimer.Tick.connect(Bind<void>(&PaletteListBox::onTick, this));
m_resourcesTimer.Tick.connect(Bind<void>(&ResourcesListBox::onTick, this));
}
raster::Palette* PaletteListBox::selectedPalette()
Resource* ResourcesListBox::selectedResource()
{
if (PaletteListItem* item = dynamic_cast<PaletteListItem*>(getSelectedChild()))
return item->palette();
if (ResourceListItem* listItem = dynamic_cast<ResourceListItem*>(getSelectedChild()))
return listItem->resource();
else
return NULL;
}
bool PaletteListBox::onProcessMessage(ui::Message* msg)
void ResourcesListBox::paintResource(Graphics* g, const gfx::Rect& bounds, Resource* resource)
{
onPaintResource(g, bounds, resource);
}
gfx::Size ResourcesListBox::preferredResourceSize(Resource* resource)
{
gfx::Size pref(0, 0);
onResourcePreferredSize(resource, pref);
return pref;
}
bool ResourcesListBox::onProcessMessage(ui::Message* msg)
{
switch (msg->type()) {
case kOpenMessage: {
if (m_palettesLoader == NULL) {
m_palettesLoader.reset(new PalettesLoader());
m_palettesTimer.start();
}
m_resourcesTimer.start();
break;
}
@ -162,16 +171,26 @@ bool PaletteListBox::onProcessMessage(ui::Message* msg)
return ListBox::onProcessMessage(msg);
}
void PaletteListBox::onChangeSelectedItem()
void ResourcesListBox::onChangeSelectedItem()
{
raster::Palette* palette = selectedPalette();
if (palette)
PalChange(palette);
Resource* resource = selectedResource();
if (resource)
onResourceChange(resource);
}
void PaletteListBox::onTick()
void ResourcesListBox::onResourceChange(Resource* resource)
{
if (m_palettesLoader == NULL) {
// Do nothing
}
void ResourcesListBox::onPaintResource(Graphics* g, const gfx::Rect& bounds, Resource* resource)
{
// Do nothing
}
void ResourcesListBox::onTick()
{
if (m_resourcesLoader == NULL) {
stop();
return;
}
@ -182,11 +201,11 @@ void PaletteListBox::onTick()
}
m_loadingItem->makeProgress();
base::UniquePtr<raster::Palette> palette;
base::UniquePtr<Resource> resource;
std::string name;
if (!m_palettesLoader->next(palette, name)) {
if (m_palettesLoader->isDone()) {
if (!m_resourcesLoader->next(resource)) {
if (m_resourcesLoader->isDone()) {
stop();
PRINTF("Done\n");
@ -194,19 +213,19 @@ void PaletteListBox::onTick()
return;
}
base::UniquePtr<PaletteListItem> item(new PaletteListItem(palette, name));
insertChild(getItemsCount()-1, item);
base::UniquePtr<ResourceListItem> listItem(new ResourceListItem(resource));
insertChild(getItemsCount()-1, listItem);
layout();
View* view = View::getView(this);
if (view)
view->updateView();
palette.release();
item.release();
resource.release();
listItem.release();
}
void PaletteListBox::stop()
void ResourcesListBox::stop()
{
if (m_loadingItem) {
removeChild(m_loadingItem);
@ -216,7 +235,7 @@ void PaletteListBox::stop()
invalidate();
}
m_palettesTimer.stop();
m_resourcesTimer.stop();
}
} // namespace app

View File

@ -0,0 +1,62 @@
/* Aseprite
* Copyright (C) 2014 David Capello
*
* 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 of the License, 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; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef APP_UI_RESOURCES_LISTBOX_H_INCLUDED
#define APP_UI_RESOURCES_LISTBOX_H_INCLUDED
#pragma once
#include "app/res/resources_loader.h"
#include "base/compiler_specific.h"
#include "base/unique_ptr.h"
#include "ui/listbox.h"
#include "ui/timer.h"
namespace app {
class ResourcesListBox : public ui::ListBox {
public:
ResourcesListBox(ResourcesLoader* resourcesLoader);
Resource* selectedResource();
void paintResource(ui::Graphics* g, const gfx::Rect& bounds, Resource* resource);
gfx::Size preferredResourceSize(Resource* resource);
protected:
virtual bool onProcessMessage(ui::Message* msg) OVERRIDE;
virtual void onChangeSelectedItem() OVERRIDE;
virtual void onResourceChange(Resource* resource) = 0;
// abstract
virtual void onPaintResource(ui::Graphics* g, const gfx::Rect& bounds, Resource* resource) = 0;
virtual void onResourcePreferredSize(Resource* resource, gfx::Size& size) = 0;
private:
void onTick();
void stop();
ResourcesLoader* m_resourcesLoader;
ui::Timer m_resourcesTimer;
class LoadingItem;
LoadingItem* m_loadingItem;
};
} // namespace app
#endif