Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

pgtooltiphelp.cpp

Go to the documentation of this file.
00001 /*
00002    ParaGUI - crossplatform widgetset
00003    Copyright (C) 2000,2001,2002  Alexander Pipelka
00004  
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009  
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014  
00015    You should have received a copy of the GNU Library General Public
00016    License along with this library; if not, write to the Free
00017    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  
00019    Alexander Pipelka
00020    pipelka@teleweb.at
00021  
00022    Last Update:      $Author: mbickel $
00023    Update Date:      $Date: 2007-04-13 16:16:04 $
00024    Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/src/widgets/pgtooltiphelp.cpp,v $
00025    CVS/RCS Revision: $Revision: 1.2 $
00026    Status:           $State: Exp $
00027  */
00028 
00029 #include <cstring>
00030 
00031 #include "pgapplication.h"
00032 #include "pgeventsupplier.h"
00033 #include "pgwidget.h"
00034 #include "pglineedit.h"
00035 #include "pgtooltiphelp.h"
00036 
00037 
00038 
00039 PG_LineEdit* PG_ToolTipHelp::toolTipLabel = NULL;
00040 PG_ToolTipHelp::Ticker* PG_ToolTipHelp::ticker = NULL;
00041 
00042 
00043 PG_ToolTipHelp :: PG_ToolTipHelp( PG_Widget* parent, const std::string& text, int delay, const std::string &style )
00044                 : parentWidget(parent), lastTick(0), status(off), labelStyle(style), my_delay(delay) {
00045         if ( !parent )
00046                 return;
00047 
00048         parent->sigMouseEnter.connect( SigC::slot( *this, &PG_ToolTipHelp::onParentEnter ), parent );
00049         parent->sigMouseLeave.connect( SigC::slot( *this, &PG_ToolTipHelp::onParentLeave ), parent );
00050         parent->sigMouseMotion.connect( SigC::slot( *this, &PG_ToolTipHelp::onMouseMotion ));
00051         PG_Application::GetApp()->sigAppIdle.connect( SigC::slot( *this, &PG_ToolTipHelp::onIdle ));
00052         PG_Application::GetApp()->EnableAppIdleCalls();
00053 
00054         parent->sigDelete.connect( SigC::slot( *this, &PG_ToolTipHelp::onParentDelete ));
00055 
00056         SetText( text );
00057 }
00058 
00059 
00060 void PG_ToolTipHelp :: SetText( const std::string& text ) {
00061         my_text = text;
00062 }
00063 
00064 bool PG_ToolTipHelp :: onIdle(  ) {
00065         if ( !ticker )
00066                 return false;
00067 
00068         if ( status != counting )
00069                 return false;
00070 
00071         if ( status == counting && !parentWidget->IsMouseInside() ) {
00072                 status = off;
00073                 return false;
00074         }
00075 
00076         if ( ticker->getTicker() > lastTick + 10 ) {
00077                 if ( status < shown ) {
00078                         int x, y;
00079                         PG_Application::GetEventSupplier()->GetMouseState( x,y );
00080                         ShowHelp( PG_Point(x+5,y+10) );
00081                         status = shown;
00082                 }
00083                 return true;
00084         }
00085         return false;
00086 }
00087 
00088 
00089 bool PG_ToolTipHelp :: onParentEnter( void* dummy ) {
00090         if ( !ticker )
00091                 ticker = new Ticker(100);
00092 
00093         status = counting;
00094 
00095         lastTick = ticker->getTicker();
00096         return true;
00097 }
00098 
00099 bool PG_ToolTipHelp :: onParentLeave( void* dummy ) {
00100         // if the ToolTipLabel is beneath the mouse cursor, we'll receive a onParentLeave notification that we'll ignore
00101         if ( toolTipLabel && toolTipLabel->IsMouseInside() )
00102                 return false;
00103 
00104         HideHelp();
00105         status = off;
00106         return false;
00107 }
00108 
00109 
00110 bool PG_ToolTipHelp :: onParentDelete( const PG_MessageObject* object ) {
00111         if ( status != off)
00112                 HideHelp();
00113 
00114         delete this;
00115         return true;
00116 }
00117 
00118 bool PG_ToolTipHelp :: onMouseMotion( const SDL_MouseMotionEvent *motion ) {
00119         if ( ticker )
00120                 lastTick = ticker->getTicker();
00121 
00122         status = counting;
00123 
00124         HideHelp();
00125         return true;
00126 }
00127 
00128 
00129 void PG_ToolTipHelp :: ShowHelp( const PG_Point& pos ) {
00130         PG_Point mousePos = pos;
00131 
00132         /*
00133         if ( ! parentWidget->IsInside( mousePos ) ) 
00134            mousePos = PG_Point( parentWidget->x + parentWidget->Width() / 2, parentWidget->y + parentWidget->Height() / 2 );
00135         */
00136 
00137         if ( toolTipLabel )
00138                 delete toolTipLabel;
00139 
00140         toolTipLabel = new PG_LineEdit( NULL, PG_Rect( mousePos.x, mousePos.y, 0, 0 ), labelStyle );
00141         toolTipLabel->SetText( my_text );
00142         toolTipLabel->SetEditable( false );
00143 
00144         Uint16 w;
00145         Uint16 h;
00146         toolTipLabel->GetTextSize( w, h );
00147 
00148         PG_Rect r = *toolTipLabel;
00149         r.w = w + 6;
00150         r.h = h + 4;
00151         if ( r.x + r.w > PG_Application::GetScreen()->w )
00152                 r.x = PG_Application::GetScreen()->w - r.w;
00153 
00154         if ( r.y + r.h > PG_Application::GetScreen()->h )
00155                 r.y = PG_Application::GetScreen()->h - r.h;
00156 
00157         toolTipLabel->MoveWidget( r, false );
00158         toolTipLabel->Show();
00159         toolTipLabel->sigMouseMotion.connect( SigC::slot( *this, &PG_ToolTipHelp::onMouseMotion ));
00160 }
00161 
00162 void PG_ToolTipHelp :: HideHelp( ) {
00163         if ( toolTipLabel ) {
00164                 delete toolTipLabel;
00165                 toolTipLabel = NULL;
00166         }
00167 }
00168 

Generated on Tue Jun 24 01:27:49 2008 for Advanced Strategic Command by  doxygen 1.4.2