# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

blend_wnd.cpp

Go to the documentation of this file.
00001 
00007 /* Copyright, 2001 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX D.T.C. SYSTEM.
00010  * NEVRAX D.T.C. SYSTEM is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX D.T.C. SYSTEM is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX D.T.C. SYSTEM; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #include "std_afx.h"
00027 #include "blend_wnd.h"
00028 #include <nel/misc/common.h>
00029 #include <nel/3d/animation_playlist.h>
00030 
00031 using namespace NL3D;
00032 using namespace NLMISC;
00033 
00034 #define COLOR_BLEND_ENABLE (RGB(192, 43, 223))
00035 #define COLOR_BLEND_DISABLE (RGB(140, 113, 142))
00036 #define SEGMENT_COUNT 10
00037 
00038 // ***************************************************************************
00039 
00040 CBlendWnd::CBlendWnd()
00041 {
00042 }
00043 
00044 // ***************************************************************************
00045 
00046 void CBlendWnd::MakePoint (const RECT& src, POINT& dst, float x, float y)
00047 {
00048         float widthClient=(float)src.right-(float)src.left;
00049         float heightClient=(float)src.bottom-(float)src.top;
00050         dst.x=src.left+(int)(widthClient*x);
00051         dst.y=src.top+(int)(heightClient*y);
00052 }
00053 
00054 // ***************************************************************************
00055 
00056 void CBlendWnd::MakeRect (const RECT& src, RECT& dst, float x, float y, float width, float height)
00057 {
00058         float widthClient=(float)src.right-(float)src.left;
00059         float heightClient=(float)src.bottom-(float)src.top;
00060         dst.left=src.left+(int)(widthClient*x);
00061         dst.top=src.top+(int)(heightClient*y);
00062         dst.right=src.left+(int)(widthClient*(x+width));
00063         dst.bottom=src.top+(int)(heightClient*(y+height));
00064 }
00065 
00066 // ***************************************************************************
00067 
00068 void CBlendWnd::OnPaint (const RECT& client, CDC* pDc, float StartBlend, float EndBlend, float StartBlendTime, float EndBlendTime, 
00069         float Smoothness, float StartTime, float EndTime, bool enabled)
00070 {
00071         // Get the good color
00072         COLORREF color=(enabled?COLOR_BLEND_ENABLE:COLOR_BLEND_DISABLE);
00073 
00074         // *** Paint the left rect
00075 
00076         // Offset start
00077         float offsetLeft=(StartBlendTime-StartTime)/(EndTime-StartTime);
00078         clamp (offsetLeft, 0, 1);
00079 
00080         // Fill the background
00081         pDc->FillSolidRect(&client, GetSysColor (COLOR_SCROLLBAR));
00082 
00083         // Make a rect for left
00084         RECT left;
00085         MakeRect (client, left, 0.f, 1.f-StartBlend, offsetLeft, StartBlend);
00086         pDc->FillSolidRect(&left, color);
00087 
00088         // *** Paint the right rect
00089 
00090         // Offset start
00091         float offsetRight=(EndBlendTime-StartTime)/(EndTime-StartTime);
00092         clamp (offsetRight, 0, 1);
00093 
00094         // Make a rect for left
00095         RECT right;
00096         MakeRect (client, right, offsetRight, 1.f-EndBlend, 1.f-offsetRight, EndBlend);
00097         pDc->FillSolidRect(&right, color);
00098 
00099         // *** Paint the inter zone
00100 
00101         // Set pen and brush color
00102     CPen myPen (PS_NULL, 0, color);
00103     CBrush myBrush (color);
00104         CPen* oldPen=NULL;
00105         CBrush* oldBrush=NULL;
00106 
00107     // Then initialize it
00108         oldPen=pDc->SelectObject (&myPen);
00109         oldBrush=pDc->SelectObject (&myBrush);
00110 
00111         for (uint i=0; i<SEGMENT_COUNT; i++)
00112         {       
00113                 // Offset of the polygon
00114                 float firstOffset=offsetLeft+(float)i*(offsetRight-offsetLeft)/(float)SEGMENT_COUNT;
00115                 float nextOffset=offsetLeft+(float)(i+1)*(offsetRight-offsetLeft)/(float)SEGMENT_COUNT;
00116 
00117                 // Get time
00118                 float firstTime=StartBlendTime+(float)i*(EndBlendTime-StartBlendTime)/(float)SEGMENT_COUNT;
00119                 float nextTime=StartBlendTime+(float)(i+1)*(EndBlendTime-StartBlendTime)/(float)SEGMENT_COUNT;
00120 
00121                 // Get the values
00122                 float firstValue=CAnimationPlaylist::getWeightValue (StartBlendTime, EndBlendTime, firstTime, StartBlend, EndBlend, Smoothness);
00123                 float nextValue=CAnimationPlaylist::getWeightValue (StartBlendTime, EndBlendTime, nextTime, StartBlend, EndBlend, Smoothness);
00124 
00125                 // Setup polygon points
00126                 POINT polygon[4];
00127                 MakePoint (client, polygon[0], firstOffset, 1.f);
00128                 MakePoint (client, polygon[1], firstOffset, 1.f-firstValue);
00129                 MakePoint (client, polygon[2], nextOffset, 1.f-nextValue);
00130                 MakePoint (client, polygon[3], nextOffset, 1.f);
00131 
00132                 // Draw the polygon
00133                 pDc->Polygon (polygon, 4);
00134         }
00135 
00136         // Draw limit line
00137     CPen myBlackPen (PS_SOLID, 1, RGB(0,0,0));
00138         pDc->SelectObject (&myBlackPen);
00139 
00140         POINT p0;
00141         POINT p1;
00142         //MakePoint (client, p0, offsetLeft, 1.f-StartBlend);
00143         MakePoint (client, p0, offsetLeft, 0.f);
00144         MakePoint (client, p1, offsetLeft, 1.f);
00145         pDc->MoveTo (p0);
00146         pDc->LineTo (p1);
00147         //MakePoint (client, p0, offsetRight, 1.f-EndBlend);
00148         MakePoint (client, p0, offsetRight, 0.f);
00149         MakePoint (client, p1, offsetRight, 1.f);
00150         pDc->MoveTo (p0);
00151         pDc->LineTo (p1);
00152 
00153         // Make frame
00154         pDc->MoveTo (client.left, client.top);
00155         pDc->LineTo (client.right, client.top);
00156         pDc->LineTo (client.right, client.bottom);
00157         pDc->LineTo (client.left, client.bottom);
00158         pDc->LineTo (client.left, client.top);
00159 
00160     // Then reselect old object
00161         pDc->SelectObject (oldPen);
00162         pDc->SelectObject (oldBrush);
00163 }
00164 
00165 // ***************************************************************************