[Wgui-cvs] wgui/wgui_ex/src wgex_knob.cpp,1.2,1.3
Status: Beta
Brought to you by:
greenwire
|
From: Rob W. <gre...@us...> - 2004-04-23 19:38:56
|
Update of /cvsroot/wgui/wgui/wgui_ex/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20009/wgui_ex/src Modified Files: wgex_knob.cpp Log Message: wGui_ex clean up and minor stuff Index: wgex_knob.cpp =================================================================== RCS file: /cvsroot/wgui/wgui/wgui_ex/src/wgex_knob.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** wgex_knob.cpp 12 Nov 2003 18:35:21 -0000 1.2 --- wgex_knob.cpp 23 Apr 2004 19:38:47 -0000 1.3 *************** *** 1,9 **** // wgex_knob.cpp // - // // CKnob & CAnimKnob class implementations // // ! // No Copyright (nc) 2003 kRAkEn/gORe // kra...@li... // --- 1,10 ---- // wgex_knob.cpp // // CKnob & CAnimKnob class implementations // // ! // Copyright (c) 2004 Rob Wiskow ! // ro...@bo... ! // Copyright (c) 2003 kRAkEn/gORe // kra...@li... // *************** *** 33,48 **** //________________________________________________________________ ! CKnob::CKnob(const CRect& WindowRect, CWindow* pParent ) ! : CControl( WindowRect, pParent ), ! m_CircleUpColor(120, 220, 20), ! m_CircleLoColor(120, 220, 20), ! m_HandleUpColor(0,0,0), ! m_HandleLoColor(255,255,250) { ! m_fRadius = (float)(WindowRect.Right() - WindowRect.Left()) / 2.0f; ! m_iInsetPixels = 2; ! m_fRangeAngle = 1.f; ! SetStartAngle( (float)( 5.f * 3.141592f / 4.f ) ); ! SetRangeAngle( (float)( -3.f * 3.141592f / 2.f ) ); CMessageServer::Instance().RegisterMessageClient(this, CMessage::MOUSE_MOVE); --- 34,44 ---- //________________________________________________________________ ! CKnob::CKnob(const CRect& WindowRect, CWindow* pParent ) : ! CWindow(WindowRect, pParent), m_CircleUpColor(120, 220, 20), m_CircleLoColor(120, 220, 20), m_HandleUpColor(0, 0, 0), ! m_HandleLoColor(255, 255, 250), m_dRangeAngle(1.0) { ! m_dRadius = stdex::safe_static_cast<double>(WindowRect.Width()) / 2.0; ! m_dStartAngle = 3.92699; // 5 * pi / 4 ! m_dRangeAngle = -4.71239; // -3 * pi / 2 CMessageServer::Instance().RegisterMessageClient(this, CMessage::MOUSE_MOVE); *************** *** 59,78 **** void CKnob::Draw(void) const { ! CAdvancedPainter Painter( m_pSDLSurface ); ! ! int midx = m_WindowRect.Left() + m_WindowRect.Width() / 2; ! int midy = m_WindowRect.Top() + m_WindowRect.Height() / 2; ! // p.Rect( s.Left(), s.Top(), s.Right(), s.Bottom(), m_BGColor ); ! const CRGBColor* CircleColor = &m_CircleLoColor; ! const CRGBColor* HandleColor = &m_HandleLoColor; ! if( m_iMouseButton != CMouseMessage::NONE ) { ! CircleColor = &m_CircleUpColor; ! HandleColor = &m_HandleUpColor; } ! Painter.DrawAACircleAlpha( midx, midy, m_fRadius - m_iInsetPixels, *CircleColor, 255 ); ! Painter.DrawAACircleAlpha( midx, midy, m_fRadius - m_iInsetPixels - 1, *CircleColor, 255 ); int x, y; --- 55,71 ---- void CKnob::Draw(void) const { ! CAdvancedPainter Painter(m_pSDLSurface); ! CPoint Center = m_WindowRect.Center(); ! CRGBColor CircleColor = m_CircleLoColor; ! CRGBColor HandleColor = m_HandleLoColor; ! if(m_iMouseButton != CMouseMessage::NONE) { ! CircleColor = m_CircleUpColor; ! HandleColor = m_HandleUpColor; } ! Painter.DrawAACircleAlpha(Center.XPos(), Center.YPos(), m_dRadius - 2, CircleColor, 255); ! Painter.DrawAACircleAlpha(Center.XPos(), Center.YPos(), m_dRadius - 3, CircleColor, 255); int x, y; *************** *** 80,90 **** x += m_WindowRect.Left(); y += m_WindowRect.Top(); - - // p.AALine( midx, midy, x, y, *HandleColor ); - // p.AALine( midx, midy, x+2, y-2, *HandleColor ); - // p.AALine( midx, midy, x-2, y+2, *HandleColor ); - Painter.DrawFilledCircleAlpha( x, y, 2, *HandleColor, 255 ); - Painter.DrawFilledCircleAlpha( midx, midy, 3, *CircleColor, 255 ); } --- 73,79 ---- x += m_WindowRect.Left(); y += m_WindowRect.Top(); + Painter.DrawFilledCircleAlpha(x, y, 2, HandleColor, 255); + Painter.DrawFilledCircleAlpha(Center.XPos(), Center.YPos(), 3, CircleColor, 255); } *************** *** 95,134 **** bool bResult = false; ! if (! CWindow::OnMouseButtonDown(Point, Button) && m_bVisible && (m_WindowRect.HitTest(Point) == CRect::RELPOS_INSIDE) ! && CApplication::Instance()->GetMouseFocus() == 0 ) { m_iMouseButton = Button; ! ! switch( m_iMouseButton ) { case CMouseMessage::LEFT: ! { ! CApplication::Instance()->SetMouseVisibility( 0 ); ! CApplication::Instance()->SetMouseFocus( this ); ! StartDrawProc(); ! bResult = true; ! break; ! } ! ! case CMouseMessage::MIDDLE: // random ! { ! break; ! } ! case CMouseMessage::RIGHT: ! { ! CApplication::Instance()->SetMouseVisibility( 0 ); ! CApplication::Instance()->SetMouseFocus( this ); StartDrawProc(); bResult = true; break; - } } ! ! } return bResult; } //________________________________________________________________ bool CKnob::OnMouseButtonUp(CPoint Point, unsigned int Button) --- 84,108 ---- bool bResult = false; ! if (!CWindow::OnMouseButtonDown(Point, Button) && m_bVisible && (m_WindowRect.HitTest(Point) == CRect::RELPOS_INSIDE) ! && CApplication::Instance()->GetMouseFocus() == 0) { m_iMouseButton = Button; ! switch(m_iMouseButton) { case CMouseMessage::LEFT: ! // do the same thing for left and right mouse clicks case CMouseMessage::RIGHT: ! CApplication::Instance()->SetMouseVisibility(0); ! CApplication::Instance()->SetMouseFocus(this); StartDrawProc(); bResult = true; break; } ! } return bResult; } + //________________________________________________________________ bool CKnob::OnMouseButtonUp(CPoint Point, unsigned int Button) *************** *** 136,151 **** bool bResult = false; ! if (! CWindow::OnMouseButtonUp(Point, Button) && m_bVisible /* && (m_WindowRect.HitTest(Point) == CRect::RELPOS_INSIDE) */ ! && (m_iMouseButton == Button) && CApplication::Instance()->GetMouseFocus() == this ) { ! switch( m_iMouseButton ) { case CMouseMessage::LEFT: ! // case CMouseMessage::MIDDLE: case CMouseMessage::RIGHT: { ! CApplication::Instance()->SetMousePosition( m_WindowRect.Center() ); ! CApplication::Instance()->SetMouseVisibility( 1 ); ! CApplication::Instance()->SetMouseFocus( 0 ); StartDrawProc(); --- 110,125 ---- bool bResult = false; ! if (!CWindow::OnMouseButtonUp(Point, Button) && m_bVisible ! && (m_iMouseButton == Button) && CApplication::Instance()->GetMouseFocus() == this) { ! switch(m_iMouseButton) { case CMouseMessage::LEFT: ! // do the same thing for left and right mouse clicks case CMouseMessage::RIGHT: { ! CApplication::Instance()->SetMousePosition(m_WindowRect.Center()); ! CApplication::Instance()->SetMouseVisibility(1); ! CApplication::Instance()->SetMouseFocus(0); StartDrawProc(); *************** *** 165,176 **** //________________________________________________________________ ! bool CKnob::HandleMessage( CMessage* pMessage ) { bool bHandled = false; ! switch( pMessage->MessageType() ) { - //-------------------------------------------------------------------------- case CMessage::MOUSE_MOVE: - //-------------------------------------------------------------------------- { CMouseMessage* pMouseMessage = dynamic_cast<CMouseMessage*>(pMessage); --- 139,148 ---- //________________________________________________________________ ! bool CKnob::HandleMessage(CMessage* pMessage) { bool bHandled = false; ! switch(pMessage->MessageType()) { case CMessage::MOUSE_MOVE: { CMouseMessage* pMouseMessage = dynamic_cast<CMouseMessage*>(pMessage); *************** *** 178,193 **** { // calculate value ! double dx = pMouseMessage->Relative.XPos() * m_fSmooth; ! double dy = pMouseMessage->Relative.YPos() * m_fSmooth; ! m_fValue += dx / (float)50*0.4f - dy / (float)50*0.3f ; ! if( m_fValue < 0.0f ) m_fValue = 0.0f; ! if( m_fValue > 1.0f ) m_fValue = 1.0f; CMessageServer::Instance().QueueMessage( ! new TFloatMessage(CMessage::CTRL_VALUECHANGE, m_pParentWindow, this, m_fValue) ); ! ! StartDrawProc(); bHandled = true; } --- 150,168 ---- { // calculate value ! m_dValue += pMouseMessage->Relative.XPos() * 0.005 - pMouseMessage->Relative.YPos() * 0.005; ! if(m_dValue < 0.0) ! { ! m_dValue = 0.0; ! } ! else if(m_dValue > 1.0) ! { ! m_dValue = 1.0; ! } CMessageServer::Instance().QueueMessage( ! new TDoubleMessage(CMessage::CTRL_VALUECHANGE, m_pParentWindow, this, m_dValue)); + StartDrawProc(); bHandled = true; } *************** *** 195,202 **** break; } - - //-------------------------------------------------------------------------- default : - //-------------------------------------------------------------------------- bHandled = CWindow::HandleMessage(pMessage); break; --- 170,174 ---- *************** *** 210,226 **** - - //________________________________________________________________ ! CAnimKnob::CAnimKnob( const CRect& WindowRect, CWindow* pParent, const std::string& sPictureFile, int iSubpix, bool bVertical ) : CKnob(WindowRect, pParent), ! m_hBitmap( CBitmapFileResourceHandle(sPictureFile) ), m_iNumSubpix(iSubpix), m_bVerticalImages(bVertical) { if( m_bVerticalImages ) m_iHeightOneImage = m_hBitmap.Bitmap()->h / m_iNumSubpix; else m_iHeightOneImage = m_hBitmap.Bitmap()->w / m_iNumSubpix; } --- 182,200 ---- //________________________________________________________________ ! CAnimKnob::CAnimKnob(const CRect& WindowRect, CWindow* pParent, const std::string& sPictureFile, int iSubpix, bool bVertical) : CKnob(WindowRect, pParent), ! m_hBitmap(CBitmapFileResourceHandle(sPictureFile)), m_iNumSubpix(iSubpix), m_bVerticalImages(bVertical) { if( m_bVerticalImages ) + { m_iHeightOneImage = m_hBitmap.Bitmap()->h / m_iNumSubpix; + } else + { m_iHeightOneImage = m_hBitmap.Bitmap()->w / m_iNumSubpix; + } } *************** *** 236,247 **** { CWindow::Draw(); - - int iPixelIndex = (int)( m_fValue * (float)( m_iNumSubpix - 1) ) * m_iHeightOneImage; CRect PictureRect = GetClientRect(); PictureRect.Grow(-1); SDL_Rect SourceRect = PictureRect.SDLRect(); ! if( m_bVerticalImages ) { SourceRect.x = 0; --- 210,220 ---- { CWindow::Draw(); + int iPixelIndex = stdex::safe_static_cast<int>(m_dValue * stdex::safe_static_cast<double>(m_iNumSubpix - 1) * m_iHeightOneImage); CRect PictureRect = GetClientRect(); PictureRect.Grow(-1); SDL_Rect SourceRect = PictureRect.SDLRect(); ! if(m_bVerticalImages) { SourceRect.x = 0; *************** *** 255,259 **** SDL_Rect DestRect = PictureRect.SDLRect(); ! SDL_BlitSurface( m_hBitmap.Bitmap(), &SourceRect, m_pSDLSurface, &DestRect ); } --- 228,232 ---- SDL_Rect DestRect = PictureRect.SDLRect(); ! SDL_BlitSurface(m_hBitmap.Bitmap(), &SourceRect, m_pSDLSurface, &DestRect); } |