nux-1.14.0
TextureArea.cpp
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #include "Nux.h"
00024 #include "TextureArea.h"
00025 #include "NuxImage/ImageSurface.h"
00026 
00027 namespace nux
00028 {
00029   NUX_IMPLEMENT_OBJECT_TYPE (TextureArea);
00030 
00031   TextureArea::TextureArea (NUX_FILE_LINE_DECL)
00032     :   View (NUX_FILE_LINE_PARAM)
00033   {
00034     //SetMinMaxSize(50, 50);
00035 
00036     mouse_down.connect (sigc::mem_fun (this, &TextureArea::RecvMouseDown));
00037     mouse_up.connect (sigc::mem_fun (this, &TextureArea::RecvMouseUp));
00038     
00039     mouse_enter.connect (sigc::mem_fun (this, &TextureArea::RecvMouseEnter));
00040     mouse_leave.connect (sigc::mem_fun (this, &TextureArea::RecvMouseLeave));
00041     mouse_click.connect (sigc::mem_fun (this, &TextureArea::RecvMouseClick));
00042 
00043     mouse_drag.connect (sigc::mem_fun (this, &TextureArea::RecvMouseDrag));
00044 
00045     m_PaintLayer = new ColorLayer (Color (0xFFFF40FF));
00046     _2d_rotate.Identity ();
00047   }
00048 
00049   TextureArea::~TextureArea()
00050   {
00051     NUX_SAFE_DELETE (m_PaintLayer);
00052     // m_UserTexture is delete by the user
00053   }
00054 
00055   void TextureArea::Draw (GraphicsEngine &GfxContext, bool force_draw)
00056   {
00057     // Ability to rotate the widget around its center
00058     GfxContext.PushModelViewMatrix(Matrix4::TRANSLATE(-GetBaseX() - GetBaseWidth() / 2, -GetBaseY() - GetBaseHeight() / 2, 0));
00059     GfxContext.PushModelViewMatrix(Get2DRotation());
00060     GfxContext.PushModelViewMatrix(Matrix4::TRANSLATE(GetBaseX() + GetBaseWidth() / 2, GetBaseY() + GetBaseHeight() / 2, 0));
00061 
00062     // The TextureArea should not render the accumulated background. That is left to the caller.
00063     // GetPainter().PaintBackground (GfxContext, GetGeometry() );
00064 
00065     if (m_PaintLayer)
00066     {
00067       m_PaintLayer->SetGeometry(GetGeometry());
00068       GetPainter().RenderSinglePaintLayer(GfxContext, GetGeometry(), m_PaintLayer);
00069     }
00070 
00071     GfxContext.PopModelViewMatrix();
00072     GfxContext.PopModelViewMatrix();
00073     GfxContext.PopModelViewMatrix();
00074   }
00075 
00076   void TextureArea::DrawContent(GraphicsEngine &GfxContext, bool force_draw)
00077   {
00078 
00079   }
00080 
00081   void TextureArea::PostDraw(GraphicsEngine &GfxContext, bool force_draw)
00082   {
00083 
00084   }
00085 
00086   void TextureArea::SetTexture(BaseTexture *texture)
00087   {
00088     NUX_RETURN_IF_NULL(texture);
00089     NUX_SAFE_DELETE(m_PaintLayer);
00090 
00091     TexCoordXForm texxform;
00092     texxform.SetTexCoordType(TexCoordXForm::OFFSET_COORD);
00093     texxform.SetWrap(TEXWRAP_REPEAT, TEXWRAP_REPEAT);
00094     m_PaintLayer = new TextureLayer(texture->GetDeviceTexture(), texxform, color::White);
00095 
00096     QueueDraw();
00097   }
00098 
00099   void TextureArea::SetPaintLayer (AbstractPaintLayer *layer)
00100   {
00101     NUX_SAFE_DELETE (m_PaintLayer);
00102     m_PaintLayer = layer->Clone();
00103 
00104     QueueDraw();
00105   }
00106 
00107 // void TextureArea::SetTexture(const TCHAR* TextureFilename)
00108 // {
00109 //     // Who should delete the texture? This class or the user?
00110 //     m_UserTexture = CreateTextureFromFile(TextureFilename);
00111 //     QueueDraw();
00112 // }
00113 
00114   void TextureArea::RecvMouseDown (int x, int y, long button_flags, long key_flags)
00115   {
00116     sigMouseDown.emit (x, y);
00117     QueueDraw ();
00118   }
00119 
00120   void TextureArea::RecvMouseClick (int x, int y, long button_flags, long key_flags)
00121   {
00122 
00123   }
00124 
00125   void TextureArea::RecvMouseUp (int x, int y, long button_flags, long key_flags)
00126   {
00127     QueueDraw ();
00128   }
00129 
00130   void TextureArea::RecvMouseEnter (int x, int y, long button_flags, long key_flags)
00131   {
00132 
00133   }
00134 
00135   void TextureArea::RecvMouseLeave (int x, int y, long button_flags, long key_flags)
00136   {
00137 
00138   }
00139 
00140   void TextureArea::RecvMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
00141   {
00142     sigMouseDrag.emit (x, y);
00143   }
00144 
00145   void TextureArea::Set2DRotation (float angle)
00146   {
00147     _2d_rotate.Rotate_z (angle);
00148     QueueDraw ();
00149   }
00150 
00151   Matrix4 TextureArea::Get2DRotation () const
00152   {
00153     return _2d_rotate;
00154   }
00155 }
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends