nux-1.16.0
|
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 "NuxImage/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->OnTimerExpired.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 long AnimatedTextureArea::ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) 00052 { 00053 return PostProcessEvent2 (ievent, TraverseInfo, ProcessEventInfo); 00054 } 00055 00056 void AnimatedTextureArea::Draw (GraphicsEngine &GfxContext, bool force_draw) 00057 { 00058 if (m_UserTexture) 00059 { 00060 GetPainter().PaintBackground (GfxContext, GetGeometry() ); 00061 GfxContext.GetRenderStates().SetBlend (true, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00062 nux::Geometry base = GetGeometry(); 00063 nux::TexCoordXForm texxform; 00064 GfxContext.QRP_1Tex (base.x, base.y, base.width, base.height, m_UserTexture->GetDeviceTexture(), texxform, nux::color::White); 00065 00066 GfxContext.GetRenderStates().SetBlend (false); 00067 } 00068 } 00069 void AnimatedTextureArea::DrawContent (GraphicsEngine &GfxContext, bool force_draw) 00070 { 00071 00072 } 00073 00074 void AnimatedTextureArea::PostDraw (GraphicsEngine &GfxContext, bool force_draw) 00075 { 00076 00077 } 00078 00079 void AnimatedTextureArea::SetTexture (TextureFrameAnimation *Texture) 00080 { 00081 m_UserTexture = Texture; 00082 00083 if (m_UserTexture) 00084 { 00085 ObjectPtr< CachedTextureFrameAnimation > Texture = GetGraphicsDisplay()->GetGraphicsEngine()->CacheResource (m_UserTexture); 00086 ObjectPtr<IOpenGLAnimatedTexture> AnimatedTexture = Texture->m_Texture; //Texture->m_Texture.CastRef<IOpenGLAnimatedTexture>(); 00087 ObjectPtr<IOpenGLBaseTexture> Texture2D = Texture->m_Texture; //Texture->m_Texture.CastRef<IOpenGLAnimatedTexture>(); 00088 00089 AnimatedTexture->SetFiltering (GL_LINEAR, GL_LINEAR); 00090 AnimatedTexture->SetWrap (GL_CLAMP, GL_CLAMP, GL_CLAMP); 00091 } 00092 00093 QueueDraw(); 00094 } 00095 00096 void AnimatedTextureArea::RecvMouseDown (int x, int y, long button_flags, long key_flags) 00097 { 00098 sigMouseDown.emit (x, y); 00099 } 00100 00101 void AnimatedTextureArea::RecvMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) 00102 { 00103 sigMouseDrag.emit (x, y); 00104 } 00105 00106 void AnimatedTextureArea::StartAnimation() 00107 { 00108 if (m_TimerHandler.IsValid() ) 00109 { 00110 GetTimer().RemoveTimerHandler (m_TimerHandler); 00111 m_TimerHandler = 0; 00112 } 00113 00114 m_TimerHandler = GetTimer().AddTimerHandler (41, m_TimerFunctor, 0); 00115 QueueDraw(); 00116 } 00117 00118 void AnimatedTextureArea::StopAnimation() 00119 { 00120 if (m_TimerHandler.IsValid() ) 00121 { 00122 GetTimer().RemoveTimerHandler (m_TimerHandler); 00123 m_TimerHandler = 0; 00124 } 00125 } 00126 00127 void AnimatedTextureArea::TimerNextFrame (void *v) 00128 { 00129 if (m_UserTexture) 00130 { 00131 ObjectPtr< CachedTextureFrameAnimation > Texture = GetGraphicsDisplay()->GetGraphicsEngine()->CacheResource (m_UserTexture); 00132 ObjectPtr<IOpenGLAnimatedTexture> AnimatedTexture = Texture->m_Texture; //Texture->m_Texture.CastRef<IOpenGLAnimatedTexture>(); 00133 ObjectPtr<IOpenGLBaseTexture> Texture2D = Texture->m_Texture; //Texture->m_Texture.CastRef<IOpenGLAnimatedTexture>(); 00134 00135 AnimatedTexture->PresentNextFrame(); 00136 m_TimerHandler = GetTimer().AddTimerHandler (41, m_TimerFunctor, 0); 00137 } 00138 00139 QueueDraw(); 00140 } 00141 00142 }