/* Copyright (C) 2007 The cluttermm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <cluttermm/actor.h>
#include <cluttermm/types.h>
#include <clutter/clutter.h> // For CoglHandle

_DEFS(cluttermm,clutter)
_PINCLUDE(cluttermm/private/actor_p.h)


namespace Clutter
{

_WRAP_ENUM(TextureFlags, ClutterTextureFlags)
_WRAP_ENUM(TextureQuality, ClutterTextureQuality)

/** Exception class for Clutter::Texture errors.
 */
_WRAP_GERROR(TextureError, ClutterTextureError, CLUTTER_TEXTURE_ERROR)

class Texture : public Actor
{
  _CLASS_GOBJECT(Texture, ClutterTexture, CLUTTER_TEXTURE, Actor, ClutterActor)

protected:
  _CTOR_DEFAULT()
  // We do not wrap this constructor because it might throw an error. This
  // gets difficult to get right especially for disabled exceptions in glibmm,
  // and it is easy enough to create a texture and call set_from_file() on
  // it manually.  But we do wrap the create method at least. --danielk
  _IGNORE(clutter_texture_new_from_file)

  // TODO: Wrap clutter_texture_new_from_actor. This needs changes in clutter
  // since the _new function does a lot more than calling g_object_new().
  //_WRAP_CTOR(Texture(const Glib::RefPtr<Actor>& actor), clutter_texture_new_from_actor)

public:
#m4 _CONVERSION(`ClutterActor*',`Glib::RefPtr<Texture>',`Glib::wrap((ClutterTexture*)$3)')

  _WRAP_CREATE()
  static Glib::RefPtr<Texture> create_from_file(const std::string& filename);
  //_WRAP_CREATE(const Glib::RefPtr<Actor>& actor);

  _WRAP_METHOD(bool set_from_file(const std::string& filename), clutter_texture_set_from_file, errthrow)
  _WRAP_METHOD(bool set_from_rgb_data(const guchar* data, bool has_alpha, int width, int height, int rowstride, int bpp, TextureFlags flags), clutter_texture_set_from_rgb_data, errthrow)
  _WRAP_METHOD(bool set_from_yuv_data(const guchar* data, int width, int height, TextureFlags flags), clutter_texture_set_from_yuv_data, errthrow)
  _WRAP_METHOD(bool set_area_from_rgb_data(const guchar* data, bool has_alpha, int x, int y, int width, int height, int rowstride, int bpp, TextureFlags flags), clutter_texture_set_area_from_rgb_data, errthrow)
  _WRAP_METHOD(void get_base_size(int& width, int& height) const, clutter_texture_get_base_size)

  _WRAP_METHOD(CoglPixelFormat get_pixel_format() const, clutter_texture_get_pixel_format)

  _WRAP_METHOD(TextureQuality get_filter_quality() const, clutter_texture_get_filter_quality)
  _WRAP_METHOD(void set_filter_quality(TextureQuality filter_quality), clutter_texture_set_filter_quality)

  _WRAP_METHOD(int get_max_tile_waste() const, clutter_texture_get_max_tile_waste)
  _WRAP_METHOD(void set_max_tile_waste(int max_tile_waste), clutter_texture_set_max_tile_waste)

  // TODO: Is there a coglmm we could depend on for this?
  _WRAP_METHOD(CoglHandle get_cogl_texture() const, clutter_texture_get_cogl_texture)
  _WRAP_METHOD(void set_cogl_texture(CoglHandle handle), clutter_texture_set_cogl_texture)
  _WRAP_METHOD(CoglHandle get_cogl_material() const, clutter_texture_get_cogl_material)
  _WRAP_METHOD(void set_cogl_material(CoglHandle handle), clutter_texture_set_cogl_material)

  _WRAP_METHOD(bool get_sync_size() const, clutter_texture_get_sync_size)
  _WRAP_METHOD(void set_sync_size(bool sync_size=true), clutter_texture_set_sync_size)

#m4 _CONVERSION(`bool&',`gboolean*',`reinterpret_cast<gboolean*>(&$3)')
  _WRAP_METHOD(void get_repeat(bool& repeat_x, bool& repeat_y) const, clutter_texture_get_repeat)
  _WRAP_METHOD(void set_repeat(bool repeat_x=true, bool repeat_y=true), clutter_texture_set_repeat)

  _WRAP_METHOD(bool get_keep_aspect_ratio() const, clutter_texture_get_keep_aspect_ratio)
  _WRAP_METHOD(void set_keep_aspect_ratio(bool keep_aspect=true), clutter_texture_set_keep_aspect_ratio)

  _WRAP_METHOD(bool get_load_async() const, clutter_texture_get_load_async)
  _WRAP_METHOD(void set_load_async(bool load_async=true), clutter_texture_set_load_async)

  _WRAP_METHOD(bool get_load_data_async() const, clutter_texture_get_load_data_async)
  _WRAP_METHOD(void set_load_data_async(bool load_async=true), clutter_texture_set_load_data_async)

  // TODO: figure out what to do with this GError parameter
  //_WRAP_SIGNAL(void load_finished(GError* error), "load_finished")
  _WRAP_SIGNAL(void size_change(int width, int height), "size_change")
  _WRAP_SIGNAL(void pixbuf_change(), "pixbuf_change")

#m4 // TODO: What's with the C type?
  _WRAP_PROPERTY("cogl-texture", CoglHandle)
  _WRAP_PROPERTY("disable-slicing", bool)
  _WRAP_PROPERTY("filename", std::string)
  _WRAP_PROPERTY("filter-quality", TextureQuality)
  _WRAP_PROPERTY("keep-aspect-ratio", bool)
  _WRAP_PROPERTY("load-async", bool)
  _WRAP_PROPERTY("load-data-async", bool)
  _WRAP_PROPERTY("pixel-format", int)
  _WRAP_PROPERTY("repeat-x", bool)
  _WRAP_PROPERTY("repeat-y", bool)
  _WRAP_PROPERTY("sync-size", bool)
  _WRAP_PROPERTY("tile-waste", int)
};

} // namespace Clutter
