Back to index

nux  3.0.0
AnimatedTextureArea.cpp
Go to the documentation of this file.
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 "NuxGraphics/ImageSurface.h"
00025 #include "AnimatedTextureArea.h"
00026 
00027 namespace nux
00028 {
00029 
00030   AnimatedTextureArea::AnimatedTextureArea(NUX_FILE_LINE_DECL)
00031     :   View(NUX_FILE_LINE_PARAM)
00032     ,   m_UserTexture(0)
00033   {
00034     SetMinMaxSize(32, 32);
00035 
00036     mouse_down.connect(sigc::mem_fun(this, &AnimatedTextureArea::RecvMouseDown));
00037     mouse_drag.connect(sigc::mem_fun(this, &AnimatedTextureArea::RecvMouseDrag));
00038 
00039     m_TimerFunctor = new TimerFunctor();
00040     m_TimerFunctor->time_expires.connect(sigc::mem_fun(this, &AnimatedTextureArea::TimerNextFrame));
00041   }
00042 
00043   AnimatedTextureArea::~AnimatedTextureArea()
00044   {
00045     GetTimer().RemoveTimerHandler(m_TimerHandler);
00046     m_TimerHandler = 0;
00047     delete m_TimerFunctor;
00048     m_TimerFunctor = 0;
00049   }
00050 
00051   void AnimatedTextureArea::Draw(GraphicsEngine &graphics_engine, bool force_draw)
00052   {
00053     if (m_UserTexture)
00054     {
00055       GetPainter().PaintBackground(graphics_engine, GetGeometry());
00056       graphics_engine.GetRenderStates().SetBlend(true, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00057       nux::Geometry base = GetGeometry();
00058       nux::TexCoordXForm texxform;
00059       graphics_engine.QRP_1Tex(base.x, base.y, base.width, base.height, m_UserTexture->GetDeviceTexture(), texxform, nux::color::White);
00060 
00061       graphics_engine.GetRenderStates().SetBlend(false);
00062     }
00063   }
00064   void AnimatedTextureArea::DrawContent(GraphicsEngine &graphics_engine, bool force_draw)
00065   {
00066 
00067   }
00068 
00069   void AnimatedTextureArea::PostDraw(GraphicsEngine &graphics_engine, bool force_draw)
00070   {
00071 
00072   }
00073 
00074   void AnimatedTextureArea::SetTexture(TextureFrameAnimation *t)
00075   {
00076     m_UserTexture = t;
00077 
00078     if (m_UserTexture)
00079     {
00080       ObjectPtr< CachedTextureFrameAnimation > Texture = GetGraphicsDisplay()->GetGraphicsEngine()->CacheResource(m_UserTexture);
00081       ObjectPtr<IOpenGLAnimatedTexture> AnimatedTexture = Texture->m_Texture; //Texture->m_Texture.CastRef<IOpenGLAnimatedTexture>();
00082       ObjectPtr<IOpenGLBaseTexture> Texture2D = Texture->m_Texture; //Texture->m_Texture.CastRef<IOpenGLAnimatedTexture>();
00083 
00084       AnimatedTexture->SetFiltering(GL_LINEAR, GL_LINEAR);
00085       AnimatedTexture->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
00086     }
00087 
00088     QueueDraw();
00089   }
00090 
00091   void AnimatedTextureArea::RecvMouseDown(int x, int y, long button_flags, long key_flags)
00092   {
00093     sigMouseDown.emit(x, y);
00094   }
00095 
00096   void AnimatedTextureArea::RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
00097   {
00098     sigMouseDrag.emit(x, y);
00099   }
00100 
00101   void AnimatedTextureArea::StartAnimation()
00102   {
00103     if (m_TimerHandler.IsValid())
00104     {
00105       GetTimer().RemoveTimerHandler(m_TimerHandler);
00106       m_TimerHandler = 0;
00107     }
00108 
00109     m_TimerHandler = GetTimer().AddTimerHandler(41, m_TimerFunctor, 0);
00110     QueueDraw();
00111   }
00112 
00113   void AnimatedTextureArea::StopAnimation()
00114   {
00115     if (m_TimerHandler.IsValid())
00116     {
00117       GetTimer().RemoveTimerHandler(m_TimerHandler);
00118       m_TimerHandler = 0;
00119     }
00120   }
00121 
00122   void AnimatedTextureArea::TimerNextFrame(void *v)
00123   {
00124     if (m_UserTexture)
00125     {
00126       ObjectPtr< CachedTextureFrameAnimation > Texture = GetGraphicsDisplay()->GetGraphicsEngine()->CacheResource(m_UserTexture);
00127       ObjectPtr<IOpenGLAnimatedTexture> AnimatedTexture = Texture->m_Texture; //Texture->m_Texture.CastRef<IOpenGLAnimatedTexture>();
00128       ObjectPtr<IOpenGLBaseTexture> Texture2D = Texture->m_Texture; //Texture->m_Texture.CastRef<IOpenGLAnimatedTexture>();
00129 
00130       AnimatedTexture->PresentNextFrame();
00131       m_TimerHandler = GetTimer().AddTimerHandler(41, m_TimerFunctor, 0);
00132     }
00133 
00134     QueueDraw();
00135   }
00136 
00137 }