Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/GNEColorDialog.cpp
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2006-2025 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
myColorbox = new FXColorSelector(getContentFrame(), this, FXColorDialog::ID_COLORSELECTOR, LAYOUT_FILL_X | LAYOUT_FILL_Y);
47
// set color
48
myColorbox->setRGBA(MFXUtils::getFXColor(color));
49
// hide buttons
50
myColorbox->acceptButton()->disable();
51
myColorbox->acceptButton()->hide();
52
myColorbox->cancelButton()->disable();
53
myColorbox->cancelButton()->hide();
54
// open dialog
55
openDialog();
56
}
57
58
59
GNEColorDialog::~GNEColorDialog() {
60
myColorbox = (FXColorSelector*) - 1L;
61
}
62
63
64
void
65
GNEColorDialog::runInternalTest(const InternalTestStep::DialogArgument* dialogArgument) {
66
if (GNEAttributeCarrier::canParse<RGBColor>(dialogArgument->getCustomAction())) {
67
// parse color
68
const auto color = GNEAttributeCarrier::parse<RGBColor>(dialogArgument->getCustomAction());
69
// set color in colorbox
70
myColorbox->setRGBA(MFXUtils::getFXColor(color));
71
} else {
72
WRITE_ERROR("Cannot parse color " + dialogArgument->getCustomAction() + " in internal test");
73
}
74
}
75
76
77
RGBColor
78
GNEColorDialog::getColor() const {
79
return MFXUtils::getRGBColor(myColorbox->getRGBA());
80
}
81
82
83
long
84
GNEColorDialog::onCmdReset(FXObject*, FXSelector, void*) {
85
// restore original color
86
myColorbox->setRGBA(MFXUtils::getFXColor(myOriginalColor));
87
return 1;
88
}
89
90
91
long
92
GNEColorDialog::onChgColor(FXObject*, FXSelector, void* ptr) {
93
if (target) {
94
return target->tryHandle(this, FXSEL(SEL_CHANGED, message), ptr);
95
} else {
96
return 0;
97
}
98
}
99
100
101
long
102
GNEColorDialog::onCmdColor(FXObject*, FXSelector, void* ptr) {
103
if (target) {
104
return target->tryHandle(this, FXSEL(SEL_COMMAND, message), ptr);
105
} else {
106
return 0;
107
}
108
}
109
110