Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/GNEColorDialog.cpp
193874 views
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
/****************************************************************************/
14
/// @file GNEColorDialog.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Aug 2025
17
///
18
// Custom GNEColorDialog used in Netedit that supports internal tests
19
/****************************************************************************/
20
21
#include <netedit/elements/GNEAttributeCarrier.h>
22
#include <netedit/GNEApplicationWindow.h>
23
24
#include "GNEColorDialog.h"
25
26
// ===========================================================================
27
// FOX callback mapping
28
// ===========================================================================
29
30
FXDEFMAP(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
36
FXIMPLEMENT(GNEColorDialog, GNEDialog, GNEColorDialogMap, ARRAYNUMBER(GNEColorDialogMap))
37
38
// ===========================================================================
39
// method definitions
40
// ===========================================================================
41
42
GNEColorDialog::GNEColorDialog(GNEApplicationWindow* applicationWindow, const RGBColor color):
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
51
GNEColorDialog::GNEColorDialog(GNEApplicationWindow* applicationWindow, GNEDialog* parentDialog,
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
61
GNEColorDialog::~GNEColorDialog() {
62
myColorbox = (FXColorSelector*) - 1L;
63
}
64
65
66
void
67
GNEColorDialog::runInternalTest(const InternalTestStep::DialogArgument* dialogArgument) {
68
if (GNEAttributeCarrier::canParse<RGBColor>(dialogArgument->getCustomAction())) {
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
79
RGBColor
80
GNEColorDialog::getColor() const {
81
return MFXUtils::getRGBColor(myColorbox->getRGBA());
82
}
83
84
85
long
86
GNEColorDialog::onCmdReset(FXObject*, FXSelector, void*) {
87
// restore original color
88
myColorbox->setRGBA(MFXUtils::getFXColor(myOriginalColor));
89
return 1;
90
}
91
92
93
long
94
GNEColorDialog::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
103
long
104
GNEColorDialog::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
113
void
114
GNEColorDialog::builder(const RGBColor color) {
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
}
126
127