LCOV - code coverage report
Current view: top level - src/utils/foxtools - MFXLabelTooltip.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 25 35 71.4 %
Date: 2024-04-27 15:34:54 Functions: 5 9 55.6 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
       4             : // This program and the accompanying materials are made available under the
       5             : // terms of the Eclipse Public License 2.0 which is available at
       6             : // https://www.eclipse.org/legal/epl-2.0/
       7             : // This Source Code may also be made available under the following Secondary
       8             : // Licenses when the conditions for such availability set forth in the Eclipse
       9             : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10             : // or later which is available at
      11             : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12             : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13             : /****************************************************************************/
      14             : /// @file    MFXLabelTooltip.cpp
      15             : /// @author  Pablo Alvarez Lopez
      16             : /// @date    2022-08-10
      17             : ///
      18             : // Label similar to FXLabel but with the possibility of showing tooltips
      19             : /****************************************************************************/
      20             : #include <config.h>
      21             : 
      22             : #include "MFXLabelTooltip.h"
      23             : 
      24             : 
      25             : FXDEFMAP(MFXLabelTooltip) MFXLabelTooltipMap[] = {
      26             :     FXMAPFUNC(SEL_PAINT,    0,  MFXLabelTooltip::onPaint),
      27             :     FXMAPFUNC(SEL_ENTER,    0,  MFXLabelTooltip::onEnter),
      28             :     FXMAPFUNC(SEL_LEAVE,    0,  MFXLabelTooltip::onLeave),
      29             :     FXMAPFUNC(SEL_MOTION,   0,  MFXLabelTooltip::onMotion),
      30             : };
      31             : 
      32             : // Object implementation
      33      653477 : FXIMPLEMENT(MFXLabelTooltip, FXButton, MFXLabelTooltipMap, ARRAYNUMBER(MFXLabelTooltipMap))
      34             : 
      35             : 
      36        7254 : MFXLabelTooltip::MFXLabelTooltip(FXComposite* p, MFXStaticToolTip* staticToolTip, const FXString& text, FXIcon* ic, FXuint opts,
      37        7254 :                                  FXint x, FXint y, FXint w, FXint h, FXint pl, FXint pr, FXint pt, FXint pb) :
      38             :     FXButton(p, text, ic, nullptr, 0, opts, x, y, w, h, pl, pr, pt, pb),
      39        7254 :     myStaticToolTip(staticToolTip) {
      40             :     // to avoid select button, just disable it (we can improve this in the future)
      41        7254 :     disable();
      42        7254 : }
      43             : 
      44             : 
      45       14474 : MFXLabelTooltip::~MFXLabelTooltip() {}
      46             : 
      47             : 
      48             : long
      49        7181 : MFXLabelTooltip::onPaint(FXObject*, FXSelector, void* ptr) {
      50             :     FXEvent* ev = (FXEvent*)ptr;
      51        7181 :     FXDCWindow dc(this, ev);
      52             :     FXint tw = 0, th = 0, iw = 0, ih = 0, tx, ty, ix, iy;
      53        7181 :     dc.setForeground(backColor);
      54        7181 :     dc.fillRectangle(0, 0, width, height);
      55        7181 :     if (!label.empty()) {
      56        7181 :         tw = labelWidth(label);
      57        7181 :         th = labelHeight(label);
      58             :     }
      59        7181 :     if (icon) {
      60             :         iw = icon->getWidth();
      61             :         ih = icon->getHeight();
      62             :     }
      63        7181 :     just_x(tx, ix, tw, iw);
      64        7181 :     just_y(ty, iy, th, ih);
      65        7181 :     if (icon) {
      66           0 :         dc.drawIcon(icon, ix, iy);
      67             :     }
      68        7181 :     if (!label.empty()) {
      69        7181 :         dc.setFont(font);
      70        7181 :         dc.setForeground(textColor);
      71        7181 :         drawLabel(dc, label, hotoff, tx, ty, tw, th);
      72             :     }
      73        7181 :     drawFrame(dc, 0, 0, width, height);
      74        7181 :     return 1;
      75        7181 : }
      76             : 
      77             : 
      78             : long
      79           0 : MFXLabelTooltip::onEnter(FXObject* sender, FXSelector sel, void* ptr) {
      80             :     // show tip show
      81           0 :     myStaticToolTip->showStaticToolTip(getTipText());
      82           0 :     return FXButton::onEnter(sender, sel, ptr);
      83             : }
      84             : 
      85             : 
      86             : long
      87           0 : MFXLabelTooltip::onLeave(FXObject* sender, FXSelector sel, void* ptr) {
      88             :     // hide static toolTip
      89           0 :     myStaticToolTip->hideStaticToolTip();
      90           0 :     return FXButton::onLeave(sender, sel, ptr);
      91             : }
      92             : 
      93             : 
      94             : long
      95           0 : MFXLabelTooltip::onMotion(FXObject* sender, FXSelector sel, void* ptr) {
      96             :     // update static tooltip
      97           0 :     myStaticToolTip->onUpdate(sender, sel, ptr);
      98           0 :     return FXButton::onMotion(sender, sel, ptr);
      99             : }
     100             : 
     101             : /****************************************************************************/

Generated by: LCOV version 1.14