Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEColorDialog.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2006-2026 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/****************************************************************************/
18// Custom GNEColorDialog used in Netedit that supports internal tests
19/****************************************************************************/
20
23
24#include "GNEColorDialog.h"
25
26// ===========================================================================
27// FOX callback mapping
28// ===========================================================================
29
30FXDEFMAP(GNEColorDialog) GNEColorDialogMap[] = {
31 FXMAPFUNC(SEL_CHANGED, FXColorDialog::ID_COLORSELECTOR, GNEColorDialog::onChgColor),
32 FXMAPFUNC(SEL_COMMAND, FXColorDialog::ID_COLORSELECTOR, GNEColorDialog::onCmdColor),
33};
34
35// Object implementation
36FXIMPLEMENT(GNEColorDialog, GNEDialog, GNEColorDialogMap, ARRAYNUMBER(GNEColorDialogMap))
37
38// ===========================================================================
39// method definitions
40// ===========================================================================
41
43 GNEDialog(applicationWindow, TL("Edit color"), GUIIcon::COLORWHEEL, DialogType::COLOR,
44 Buttons::ACCEPT_CANCEL_RESET, OpenType::MODAL, ResizeMode::STATIC, 600, 300),
45 myOriginalColor(color) {
46 // build dialog
47 builder(color);
48}
49
50
52 const RGBColor color):
53 GNEDialog(applicationWindow, parentDialog, TL("Edit color"), GUIIcon::COLORWHEEL, DialogType::COLOR,
54 Buttons::ACCEPT_CANCEL_RESET, OpenType::MODAL, ResizeMode::STATIC, 600, 300),
55 myOriginalColor(color) {
56 // build dialog
57 builder(color);
58}
59
60
62 myColorbox = (FXColorSelector*) - 1L;
63}
64
65
66void
69 // parse color
70 const auto color = GNEAttributeCarrier::parse<RGBColor>(dialogArgument->getCustomAction());
71 // set color in colorbox
72 myColorbox->setRGBA(MFXUtils::getFXColor(color));
73 } else {
74 WRITE_ERROR("Cannot parse color " + dialogArgument->getCustomAction() + " in internal test");
75 }
76}
77
78
81 return MFXUtils::getRGBColor(myColorbox->getRGBA());
82}
83
84
85long
86GNEColorDialog::onCmdReset(FXObject*, FXSelector, void*) {
87 // restore original color
89 return 1;
90}
91
92
93long
94GNEColorDialog::onChgColor(FXObject*, FXSelector, void* ptr) {
95 if (target) {
96 return target->tryHandle(this, FXSEL(SEL_CHANGED, message), ptr);
97 } else {
98 return 0;
99 }
100}
101
102
103long
104GNEColorDialog::onCmdColor(FXObject*, FXSelector, void* ptr) {
105 if (target) {
106 return target->tryHandle(this, FXSEL(SEL_COMMAND, message), ptr);
107 } else {
108 return 0;
109 }
110}
111
112
113void
115 myColorbox = new FXColorSelector(getContentFrame(), this, FXColorDialog::ID_COLORSELECTOR, LAYOUT_FILL_X | LAYOUT_FILL_Y);
116 // set color
117 myColorbox->setRGBA(MFXUtils::getFXColor(color));
118 // hide buttons
119 myColorbox->acceptButton()->disable();
120 myColorbox->acceptButton()->hide();
121 myColorbox->cancelButton()->disable();
122 myColorbox->cancelButton()->hide();
123 // open dialog
124 openDialog();
125}
DialogType
Definition DialogType.h:30
FXDEFMAP(GNEColorDialog) GNEColorDialogMap[]
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ COLORWHEEL
Definition GUIIcons.h:189
#define WRITE_ERROR(msg)
Definition MsgHandler.h:295
#define TL(string)
Definition MsgHandler.h:304
static T parse(const std::string &string)
parses a value of type T from string (used for basic types: int, double, bool, etc....
static bool canParse(const std::string &string)
true if a value of type T can be parsed from string
RGBColor getColor() const
Get the color.
GNEColorDialog(GNEApplicationWindow *applicationWindow, const RGBColor color)
Constructor.
long onCmdReset(FXObject *, FXSelector, void *)
called when reset button is pressed
virtual ~GNEColorDialog()
Destructor.
long onChgColor(FXObject *, FXSelector, void *)
Called when color is changed.
long onCmdColor(FXObject *, FXSelector, void *)
Called when color is selected.
void builder(const RGBColor color)
builder
void runInternalTest(const InternalTestStep::DialogArgument *dialogArgument)
run internal test
const RGBColor myOriginalColor
Original color to restore pressing reset button.
FXColorSelector * myColorbox
Default constructor.
FXVerticalFrame * getContentFrame() const
get content frame
void openDialog(FXWindow *focusableElement=nullptr)
open dialog
OpenType
Open dialog type.
Definition GNEDialog.h:58
GNEDialog(GNEApplicationWindow *applicationWindow, const std::string &name, GUIIcon titleIcon, DialogType type, Buttons buttons, OpenType openType, ResizeMode resizeMode)
basic constructor
Definition GNEDialog.cpp:60
dialog arguments, used for certain modal dialogs that can not be edited using tab
const std::string & getCustomAction() const
get custom action
static FXColor getFXColor(const RGBColor &col)
converts FXColor to RGBColor
Definition MFXUtils.cpp:146
static RGBColor getRGBColor(FXColor col)
converts FXColor to RGBColor
Definition MFXUtils.cpp:140