GUIGLObjectToolTip.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // The tooltip class for displaying information about gl-objects
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 
00020 
00021 // ===========================================================================
00022 // included modules
00023 // ===========================================================================
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029 
00030 #include <iostream>
00031 #include <string>
00032 #include "GUIGlObjectStorage.h"
00033 #include "GUIGlObject.h"
00034 #include "GUIGLObjectToolTip.h"
00035 
00036 #ifdef CHECK_MEMORY_LEAKS
00037 #include <foreign/nvwa/debug_new.h>
00038 #endif // CHECK_MEMORY_LEAKS
00039 
00040 
00041 // ===========================================================================
00042 // FOX callback mapping
00043 // ===========================================================================
00044 FXDEFMAP(GUIGLObjectToolTip) GUIGLObjectToolTipMap[]={
00045     FXMAPFUNC(SEL_PAINT, 0, GUIGLObjectToolTip::onPaint),
00046 };
00047 
00048 FXIMPLEMENT(GUIGLObjectToolTip,FXToolTip,GUIGLObjectToolTipMap,ARRAYNUMBER(GUIGLObjectToolTipMap))
00049 
00050 
00051 // ===========================================================================
00052 // method definitions
00053 // ===========================================================================
00054 GUIGLObjectToolTip::GUIGLObjectToolTip(FXWindow *a)
00055         : FXToolTip(a->getApp(), /*TOOLTIP_NORMAL*/TOOLTIP_PERMANENT, 0, 0, 200, 200),
00056         myFont(a->getApp()->getNormalFont()),
00057         myObject(0) {
00058     setBackColor((255)|(204<<8)|(0<<16));
00059     myTextHeight = myFont->getFontHeight();
00060     create();
00061     hide();
00062 }
00063 
00064 
00065 GUIGLObjectToolTip::~GUIGLObjectToolTip() {}
00066 
00067 void
00068 GUIGLObjectToolTip::setObjectTip(GUIGlObject *object,
00069                                  FXint x, FXint y) {
00070     // check whether the object has changed
00071     bool objectChanged = (myObject!=object);
00072     // save current object
00073     myObject = object;
00074     if (object==0) {
00075         // hide the tool tip if there is no object below
00076         hide();
00077         return;
00078     }
00079     // if the object has changed
00080     if (objectChanged) {
00081         // get the new name and width
00082         myObjectName = object->getFullName();
00083         label = myObjectName.c_str();
00084         myWidth = myFont->getTextWidth(myObjectName.c_str(), (FXuint) myObjectName.length())+6;
00085     }
00086     myHeight = myTextHeight+6;
00087     position(x+15, y-20, 1, 1);
00088     position(x+15, y-20, myWidth, myHeight);
00089     if (!shown()) {
00090         show();
00091     } else {
00092         if (objectChanged) {
00093             recalc();
00094         }
00095         update();
00096     }
00097     myLastXPos = x;
00098     myLastYPos = y;
00099 }
00100 
00101 
00102 long
00103 GUIGLObjectToolTip::onPaint(FXObject*,FXSelector,void*) {
00104     if (myObject==0) {
00105         return 1;
00106     }
00107     // Start drawing
00108     FXDCWindow dc(this);
00109     dc.setForeground(backColor);
00110     dc.fillRectangle(1, 1,
00111                      myFont->getTextWidth(myObjectName.c_str(), (FXuint) myObjectName.length())+4, myTextHeight+4);
00112     dc.setFont(myFont);
00113     dc.setForeground(0);
00114     dc.drawText(3, myTextHeight,
00115                 myObjectName.c_str(), (FXuint) myObject->getFullName().length());
00116     dc.drawRectangle(0, 0, myFont->getTextWidth(myObjectName.c_str(), (FXuint) myObjectName.length())+5, myTextHeight+5);
00117     return 1;
00118 }
00119 
00120 
00121 FXint
00122 GUIGLObjectToolTip::getDefaultWidth() {
00123     return myWidth;
00124 }
00125 
00126 
00127 FXint
00128 GUIGLObjectToolTip::getDefaultHeight() {
00129     return myHeight;
00130 }
00131 
00132 
00133 long
00134 GUIGLObjectToolTip::onTipShow(FXObject*,FXSelector,void*) {
00135     return 1;
00136 }
00137 
00138 
00139 long
00140 GUIGLObjectToolTip::onTipHide(FXObject*,FXSelector,void*) {
00141     return 1;
00142 }
00143 
00144 
00145 
00146 /****************************************************************************/
00147 

Generated on Wed May 5 00:06:30 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6