/*
 * Copyright (C) 2015 The gtkmm 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <gtkmm/widget.h>
_DEFS(gtkmm,gtk)
_PINCLUDE(gtkmm/private/widget_p.h)

#include <gdkmm/glcontext.h>

namespace Gtk
{

/** A widget used for drawing with OpenGL.
 * @newin{3,18}
 * @ingroup Widgets
 */
class GLArea : public Widget
{
  _CLASS_GTKOBJECT(GLArea,GtkGLArea,GTK_GL_AREA,Gtk::Widget,GtkWidget)
public:

  _CTOR_DEFAULT

  _WRAP_METHOD(Glib::RefPtr<Gdk::GLContext> get_context(), gtk_gl_area_get_context, refreturn, newin "3,18")
  _WRAP_METHOD(Glib::RefPtr<const Gdk::GLContext> get_context() const, gtk_gl_area_get_context, refreturn, constversion, newin "3,18")
  _WRAP_METHOD(void make_current(), gtk_gl_area_make_current, newin "3,18")
  _WRAP_METHOD(void queue_render(), gtk_gl_area_queue_render, newin "3,18")
  _WRAP_METHOD(void attach_buffers(), gtk_gl_area_attach_buffers, newin "3,18")
  /** Check if any error is currently set on this <i>area</i>.
   *
   * The error may be obtained by using throw_if_error() and
   * set using set_error().
   *
   * @newin{3,18}
   *
   * @return true if an error is currently set.
   */
  bool has_error() const;

  _IGNORE(gtk_gl_area_get_error)
  /** Will throw the correct Glib::Error subclass if
   * any is currently set on this <i>area</i>.
   *
   * @newin{3,18}
   *
   * @throw Throws any currently set error (e.g. Gdk::GLError).
   */
  void throw_if_error() const;

#m4 _CONVERSION(`const Glib::Error&', `const GError*', __FR2P)
  /** Sets an error on the <i>area</i> which will be shown
   * instead of GL rendering.
   *
   * This is useful in the signal_create_context() handler
   * if GL context creation fails.
   *
   * @newin{3,18}
   *
   * @param error The error to set on the <i>area</i>.
   */
  _WRAP_METHOD(void set_error(const Glib::Error& error), gtk_gl_area_set_error)
  /** Clears any previous set error on this <i>area</i> made with set_error().
   *
   * @newin{3,18}
   */
  void unset_error();
  _WRAP_METHOD(bool get_has_alpha() const, gtk_gl_area_get_has_alpha, newin "3,18")
  _WRAP_METHOD(void set_has_alpha(bool has_alpha = true), gtk_gl_area_set_has_alpha, newin "3,18")
  _WRAP_METHOD(bool get_has_depth_buffer() const, gtk_gl_area_get_has_depth_buffer, newin "3,18")
  _WRAP_METHOD(void set_has_depth_buffer(bool has_depth_buffer = true), gtk_gl_area_set_has_depth_buffer, newin "3,18")
  _WRAP_METHOD(bool get_has_stencil_buffer() const, gtk_gl_area_get_has_stencil_buffer, newin "3,18")
  _WRAP_METHOD(void set_has_stencil_buffer(bool has_stencil_buffer = true), gtk_gl_area_set_has_stencil_buffer, newin "3,18")
  _WRAP_METHOD(bool get_auto_render() const, gtk_gl_area_get_auto_render, newin "3,18")
  _WRAP_METHOD(void set_auto_render(bool auto_render = true), gtk_gl_area_set_auto_render, newin "3,18")
  _WRAP_METHOD(void get_required_version(int& major, int& minor) const, gtk_gl_area_get_required_version, newin "3,18")
  _WRAP_METHOD(void set_required_version(int major, int minor), gtk_gl_area_set_required_version, newin "3,18")

  _WRAP_PROPERTY("auto-render", bool, newin "3,18")
  _WRAP_PROPERTY("context", Glib::RefPtr<Gdk::GLContext>, newin "3,18")
  _WRAP_PROPERTY("has-alpha", bool, newin "3,18")
  _WRAP_PROPERTY("has-depth-buffer", bool, newin "3,18")
  _WRAP_PROPERTY("has-stencil-buffer", bool, newin "3,18")

#m4 _CONVERSION(`Glib::RefPtr<Gdk::GLContext>', `GdkGLContext*', Glib::unwrap($3))
  _WRAP_SIGNAL(Glib::RefPtr<Gdk::GLContext> create_context(), "create_context", newin "3,18")
#m4 _CONVERSION(`GdkGLContext*', `const Glib::RefPtr<Gdk::GLContext>&', Glib::wrap($3, true))
  _WRAP_SIGNAL(bool render(const Glib::RefPtr<Gdk::GLContext>& context), render, newin "3,18")
  _WRAP_SIGNAL(void resize(int width, int height), "resize", newin "3,18")

};

} //namespace Gtk
