LCOV - code coverage report
Current view: top level - src/utils/gui/cursors - GUICursorSubSys.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 89.7 % 29 26
Test Date: 2024-11-20 15:55:46 Functions: 80.0 % 5 4

            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    GUICursorSubSys.cpp
      15              : /// @author  Pablo Alvarez Lopez
      16              : /// @date    Nov 2018
      17              : ///
      18              : // Helper for cursors loading and usage
      19              : /****************************************************************************/
      20              : #include <config.h>
      21              : 
      22              : #include <utils/common/UtilExceptions.h>
      23              : 
      24              : #include "GUICursors.h"
      25              : #include "GUICursorSubSys.h"
      26              : 
      27              : #include "Delete_cursor.cpp"
      28              : #include "Select_cursor.cpp"
      29              : #include "SelectLane_cursor.cpp"
      30              : #include "Inspect_cursor.cpp"
      31              : #include "InspectLane_cursor.cpp"
      32              : #include "MoveElement_cursor.cpp"
      33              : 
      34              : // ===========================================================================
      35              : // static member variable definitions
      36              : // ===========================================================================
      37              : 
      38              : GUICursorSubSys* GUICursorSubSys::myInstance = nullptr;
      39              : 
      40              : // ===========================================================================
      41              : // member definitions
      42              : // ===========================================================================
      43              : 
      44         7535 : GUICursorSubSys::GUICursorSubSys(FXApp* a) {
      45              :     // default cursors (already created)
      46         7535 :     myCursors[GUICursor::DEFAULT] = a->getDefaultCursor(DEF_ARROW_CURSOR);
      47         7535 :     myCursors[GUICursor::MOVEVIEW] = a->getDefaultCursor(DEF_MOVE_CURSOR);
      48              : 
      49              :     // custom cursors (must be created)
      50         7535 :     myCursors[GUICursor::DELETE_CURSOR] = new FXGIFCursor(a, Delete_cursor, 1, 2);
      51         7535 :     myCursors[GUICursor::SELECT] = new FXGIFCursor(a, Select_cursor, 1, 1);
      52         7535 :     myCursors[GUICursor::SELECT_LANE] = new FXGIFCursor(a, SelectLane_cursor, 1, 1);
      53         7535 :     myCursors[GUICursor::INSPECT] = new FXGIFCursor(a, Inspect_cursor, 1, 2);
      54         7535 :     myCursors[GUICursor::INSPECT_LANE] = new FXGIFCursor(a, InspectLane_cursor, 1, 2);
      55         7535 :     myCursors[GUICursor::MOVEELEMENT] = new FXGIFCursor(a, MoveElement_cursor, 1, 2);
      56              : 
      57              :     // ... and create them
      58        67815 :     for (const auto& cursor : myCursors) {
      59        60280 :         if (cursor.second != nullptr) {
      60        60280 :             cursor.second->create();
      61              :         }
      62              :     }
      63              : 
      64         7535 : }
      65              : 
      66              : 
      67         7523 : GUICursorSubSys::~GUICursorSubSys() {
      68              :     // delete all cursors
      69        67707 :     for (const auto& cursor : myCursors) {
      70        60184 :         if (cursor.first != GUICursor::DEFAULT && cursor.first != GUICursor::MOVEVIEW) {
      71        45138 :             delete cursor.second;
      72              :         }
      73              :     }
      74         7523 : }
      75              : 
      76              : 
      77              : void
      78         7535 : GUICursorSubSys::initCursors(FXApp* a) {
      79         7535 :     if (myInstance == nullptr) {
      80         7535 :         myInstance = new GUICursorSubSys(a);
      81              :     } else {
      82            0 :         throw ProcessError("GUICursorSubSys already init");
      83              :     }
      84         7535 : }
      85              : 
      86              : 
      87              : FXCursor*
      88            0 : GUICursorSubSys::getCursor(GUICursor which) {
      89            0 :     return myInstance->myCursors[which];
      90              : }
      91              : 
      92              : 
      93              : void
      94         7523 : GUICursorSubSys::close() {
      95              :     // delete and reset instance
      96         7523 :     delete myInstance;
      97         7523 :     myInstance = nullptr;
      98         7523 : }
      99              : 
     100              : 
     101              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1