home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / include / k3d / k3dsdk / mesh_painter_gl.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-11-07  |  3.2 KB  |  110 lines

  1. #ifndef K3DSDK_MESH_PAINTER_GL_H
  2. #define K3DSDK_MESH_PAINTER_GL_H
  3.  
  4. // K-3D
  5. // Copyright (c) 1995-2007, Timothy M. Shead
  6. //
  7. // Contact: tshead@k-3d.com
  8. //
  9. // This program is free software; you can redistribute it and/or
  10. // modify it under the terms of the GNU General Public
  11. // License as published by the Free Software Foundation; either
  12. // version 2 of the License, or (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. // General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public
  20. // License along with this program; if not, write to the Free Software
  21. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  22.  
  23. /** \file
  24.     \author Tim Shead (tshead@k-3d.com)
  25. */
  26.  
  27. #include "data.h"
  28. #include "imesh_painter_gl.h"
  29. #include "k3d-i18n-config.h"
  30. #include "node.h"
  31. #include "utility_gl.h"
  32.  
  33. namespace k3d
  34. {
  35.  
  36. namespace gl
  37. {
  38.  
  39. /// Provides a boilerplate implementation of k3d::gl::imesh_painter
  40. class mesh_painter :
  41.     public node,
  42.     public imesh_painter
  43. {
  44.     typedef node base;
  45.  
  46. public:
  47.     mesh_painter(iplugin_factory& Factory, idocument& Document) :
  48.         base(Factory, Document),
  49.         m_enabled(init_owner(*this) + init_name("enabled") + init_label(_("Enabled")) + init_description(_("Enable / disable drawing for this painter.")) + init_value(true))
  50.     {
  51.         m_enabled.changed_signal().connect(make_async_redraw_slot());
  52.     }
  53.  
  54.     void paint_mesh(const mesh& Mesh, const painter_render_state& RenderState)
  55.     {
  56.         if(m_enabled.pipeline_value())
  57.             on_paint_mesh(Mesh, RenderState);
  58.     }
  59.  
  60.     void select_mesh(const mesh& Mesh, const painter_render_state& RenderState, const painter_selection_state& SelectionState)
  61.     {
  62.         if(m_enabled.pipeline_value())
  63.             on_select_mesh(Mesh, RenderState, SelectionState);
  64.     }
  65.  
  66.     void mesh_changed(const mesh& Mesh, ihint* Hint)
  67.     {
  68.         // Note - on_mesh_changed() is always called whether we're enabled or not to prevent caching of stale data
  69.         on_mesh_changed(Mesh, Hint);
  70.     }
  71.  
  72. protected:
  73.     /// Returns a slot that will schedule an asynchronous screen update when called
  74.     sigc::slot<void, ihint*> make_async_redraw_slot()
  75.     {
  76.         return sigc::mem_fun(*this, &mesh_painter::async_redraw);
  77.     }
  78.  
  79.     /// Schedules an asynchronous screen update
  80.     void async_redraw(ihint*)
  81.     {
  82.         redraw_all(document(), irender_viewport::ASYNCHRONOUS);
  83.     }
  84.  
  85.     /// Implement this in derived classes to draw mesh components
  86.     virtual void on_paint_mesh(const mesh& Mesh, const painter_render_state& RenderState)
  87.     {
  88.     }
  89.  
  90.     /// Implement this in derived classes to draw mesh components for selection
  91.     virtual void on_select_mesh(const mesh& Mesh, const painter_render_state& RenderState, const painter_selection_state& SelectionState)
  92.     {
  93.     }
  94.  
  95.     /// Implement this in derived classes to clear cached data when a mesh changes
  96.     virtual void on_mesh_changed(const mesh& Mesh, ihint* Hint)
  97.     {
  98.     }
  99.  
  100.     /// Used to enable/disable the painter
  101.     k3d_data(bool, data::immutable_name, data::change_signal, data::with_undo, data::local_storage, data::no_constraint, data::writable_property, data::with_serialization) m_enabled;
  102. };
  103.  
  104. } // namespace gl
  105.  
  106. } // namespace k3d
  107.  
  108. #endif // !K3DSDK_MESH_PAINTER_GL_H
  109.  
  110.