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

            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       591223 : FXIMPLEMENT(MFXLabelTooltip, FXButton, MFXLabelTooltipMap, ARRAYNUMBER(MFXLabelTooltipMap))
      34              : 
      35              : 
      36         7551 : MFXLabelTooltip::MFXLabelTooltip(FXComposite* p, MFXStaticToolTip* staticToolTip, const FXString& text, FXIcon* ic, FXuint opts,
      37         7551 :                                  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         7551 :     myStaticToolTip(staticToolTip) {
      40              :     // to avoid select button, just disable it (we can improve this in the future)
      41         7551 :     disable();
      42         7551 : }
      43              : 
      44              : 
      45        15076 : MFXLabelTooltip::~MFXLabelTooltip() {}
      46              : 
      47              : 
      48              : long
      49         7442 : MFXLabelTooltip::onPaint(FXObject*, FXSelector, void* ptr) {
      50              :     FXEvent* ev = (FXEvent*)ptr;
      51         7442 :     FXDCWindow dc(this, ev);
      52              :     FXint tw = 0, th = 0, iw = 0, ih = 0, tx, ty, ix, iy;
      53         7442 :     dc.setForeground(backColor);
      54         7442 :     dc.fillRectangle(0, 0, width, height);
      55         7442 :     if (!label.empty()) {
      56         7442 :         tw = labelWidth(label);
      57         7442 :         th = labelHeight(label);
      58              :     }
      59         7442 :     if (icon) {
      60              :         iw = icon->getWidth();
      61              :         ih = icon->getHeight();
      62              :     }
      63         7442 :     just_x(tx, ix, tw, iw);
      64         7442 :     just_y(ty, iy, th, ih);
      65         7442 :     if (icon) {
      66            0 :         dc.drawIcon(icon, ix, iy);
      67              :     }
      68         7442 :     if (!label.empty()) {
      69         7442 :         dc.setFont(font);
      70         7442 :         dc.setForeground(textColor);
      71         7442 :         drawLabel(dc, label, hotoff, tx, ty, tw, th);
      72              :     }
      73         7442 :     drawFrame(dc, 0, 0, width, height);
      74         7442 :     return 1;
      75         7442 : }
      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 2.0-1