[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src/editor object_selector.cxx,1.2,1.3 su
From: |
grumbel |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src/editor object_selector.cxx,1.2,1.3 surface_selector.cxx,1.1,1.2 surface_selector.hxx,1.1,1.2 thumb_cache.cxx,1.5,1.6 thumb_cache.hxx,1.1,1.2 |
Date: |
23 Jun 2002 12:47:52 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src/editor
In directory dark:/tmp/cvs-serv10595/editor
Modified Files:
object_selector.cxx surface_selector.cxx surface_selector.hxx
thumb_cache.cxx thumb_cache.hxx
Log Message:
fixed resize bug of thumbnails
Index: object_selector.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/editor/object_selector.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- object_selector.cxx 22 Jun 2002 14:29:18 -0000 1.2
+++ object_selector.cxx 23 Jun 2002 12:47:50 -0000 1.3
@@ -555,16 +555,8 @@
++j;
sur_obj.name = *i;
sur_obj.datafile = resource_file;
- sur_obj.sur = ThumbCache::load (*i, resource_file);
-
- if (sur_obj.sur == 0)
- {
- sur_obj.sur = CL_Surface (sur_obj.name.c_str (), res);
- sur_obj.sur = Blitter::scale_surface (sur_obj.sur, 50, 50);
- ThumbCache::cache (sur_obj.sur, sur_obj.name, resource_file);
+ sur_obj.thumbnail = ThumbCache::load (*i, resource_file);
- std::cout << "Loading: " << sur_obj.name << endl;
- }
sur_list.push_back(sur_obj);
if (!datafile_loaded && (j % 25) == 0)
Index: surface_selector.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/editor/surface_selector.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- surface_selector.cxx 12 Jun 2002 19:11:31 -0000 1.1
+++ surface_selector.cxx 23 Jun 2002 12:47:50 -0000 1.2
@@ -98,14 +98,14 @@
// Draw all surfaces
for(vector<surface_obj>::iterator i = sur_list->begin(); i !=
sur_list->end(); i++)
{
- if (i->sur.get_width() <= 50 && i->sur.get_height() <= 50)
+ if (i->thumbnail.get_width() <= 50 && i->thumbnail.get_height() <= 50)
{
- i->sur.put_screen(x + 25 - (i->sur.get_width() / 2),
- y + 25 - (i->sur.get_height() / 2));
+ i->thumbnail.put_screen(x + 25 - (i->thumbnail.get_width() / 2),
+ y + 25 - (i->thumbnail.get_height() / 2));
}
else
{
- i->sur.put_screen(x, y);
+ i->thumbnail.put_screen(x, y);
}
if (i == c_obj)
Index: surface_selector.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/editor/surface_selector.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- surface_selector.hxx 12 Jun 2002 19:11:31 -0000 1.1
+++ surface_selector.hxx 23 Jun 2002 12:47:50 -0000 1.2
@@ -26,13 +26,16 @@
///
struct surface_obj
{
- ///
- CL_Surface sur;
- ///
+ /** Thumbnail of the surface */
+ CL_Surface thumbnail;
+
+ /** The real surface */
CL_Surface large_sur;
- ///
+
+ /** Resource ID */
std::string name;
- ///
+
+ /** Data File */
std::string datafile;
/** The time the small tumbnail was selected, when the mouse is
Index: thumb_cache.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/editor/thumb_cache.cxx,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- thumb_cache.cxx 23 Jun 2002 11:08:30 -0000 1.5
+++ thumb_cache.cxx 23 Jun 2002 12:47:50 -0000 1.6
@@ -32,7 +32,7 @@
using namespace Pingus;
-const unsigned int thumbcache_version = 2;
+const unsigned int thumbcache_version = 3;
/*
~/.pingus/cache/
@@ -42,11 +42,22 @@
uint32: width
uint32: height
uint32: mtime of parent image
- data: ...
+ data: (RGBA8888)...
*/
CL_Surface
+ThumbCache::uncached_load (const std::string & res_ident, const std::string &
datafile)
+{
+ CL_Surface sur = PingusResource::load_surface (res_ident, datafile);
+
+ std::cout << "ThumbCache: Loading: " << res_ident << " (" << datafile << ")"
<< std::endl;
+
+ // Add object to cache
+ return ThumbCache::cache (sur, res_ident, datafile);
+}
+
+CL_Surface
ThumbCache::load (const std::string & res_ident, const std::string & datafile)
{
std::string filename = res_ident + "-" + datafile;
@@ -70,7 +81,7 @@
if (version != thumbcache_version)
{
std::cout << "Thumbnail: version mismatch" << std::endl;
- return CL_Surface ();
+ return uncached_load (res_ident, datafile);
}
unsigned int width = in.read_uint32 ();
@@ -81,7 +92,7 @@
if (timestamp != PingusResource::get_mtime (res_ident, datafile))
{
std::cout << "Thumbnail: file needs update" << std::endl;
- return CL_Surface ();
+ return uncached_load (res_ident, datafile);
}
CL_Canvas* canvas = new CL_Canvas (width, height);
@@ -96,7 +107,7 @@
if (pingus_debug_flags & PINGUS_DEBUG_EDITOR)
std::cerr << "ThumbCache: " << filename << ": read error:
wanted " << buffer_size << " got " << read_size << std::endl;
delete canvas;
- return CL_Surface ();
+ return uncached_load (res_ident, datafile);
}
canvas->unlock ();
return CL_Surface (canvas, true);
@@ -104,21 +115,22 @@
catch (CL_Error& err)
{
std::cout << "ThumbCache: Read error: " << filename << " | " <<
err.message <<std::endl;
- return CL_Surface ();
+ return uncached_load (res_ident, datafile);
}
}
- // FIXME: This should return the correct surface
- return CL_Surface ();
+ return uncached_load (res_ident, datafile);
}
-void
+CL_Surface
ThumbCache::cache (const CL_Surface& sur, const std::string & res_ident, const
std::string & datafile)
{
- if (sur.get_provider ()->get_height () * sur.get_provider ()->get_width () <
50 * 50)
+ if (sur.get_provider ()->get_height () < 50
+ && sur.get_provider ()->get_width () < 50)
{
+ // If the image is smaller than the thumbnail, there is no need to cache
it
std::cout << "ThumbCache: image too small for cache: " << res_ident <<
std::endl;
- return;
+ return sur;
}
std::string filename = res_ident + "-" + datafile;
@@ -142,6 +154,7 @@
unsigned int width = Math::min((unsigned int)50, sur.get_width ());
unsigned int height = Math::min((unsigned int)50, sur.get_height ());
+ // Caller is responsible to delete the canvas
CL_Canvas* canvas = Blitter::scale_surface_to_canvas (sur, width,
height);
canvas->lock ();
void* buffer = canvas->get_data();
@@ -161,11 +174,18 @@
out.write (buffer, buffer_size);
canvas->unlock ();
- delete canvas;
+ // Canvas will get deleted on the end of the lifetime of this surface
+ return CL_Surface (canvas, true);
}
catch (CL_Error& err)
{
std::cout << "ThumbCache: Couldn't open file for writing: " << filename
<< std::endl;
+
+ // If writing the surface fails, we return the surface without
+ // writing it to the cache
+ unsigned int width = Math::min((unsigned int)50, sur.get_width ());
+ unsigned int height = Math::min((unsigned int)50, sur.get_height ());
+ return Blitter::scale_surface (sur, width, height);
}
}
Index: thumb_cache.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/editor/thumb_cache.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- thumb_cache.hxx 12 Jun 2002 19:11:31 -0000 1.1
+++ thumb_cache.hxx 23 Jun 2002 12:47:50 -0000 1.2
@@ -29,14 +29,17 @@
private:
public:
+ /** Load a surface from its source, instead of from the cache */
+ static CL_Surface uncached_load (const std::string & res_ident, const
std::string & datafile);
+
/** Load a thumbnail of a surface out of the cache. The thumbnail has
the size 50x50, if the thumbnail is not available, the surface
is loaded and added to the cache. */
static CL_Surface load (const std::string & res_ident, const std::string &
datafile);
/** Add a surface as thumbnail to the cache, the surface will be
- resized to a 50x50 size */
- static void cache (const CL_Surface&, const std::string & res_ident,
const std::string & datafile);
+ resized to a 50x50 size, the return value is the resized surface */
+ static CL_Surface cache (const CL_Surface&, const std::string & res_ident,
const std::string & datafile);
};
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src/editor object_selector.cxx,1.2,1.3 surface_selector.cxx,1.1,1.2 surface_selector.hxx,1.1,1.2 thumb_cache.cxx,1.5,1.6 thumb_cache.hxx,1.1,1.2,
grumbel <=