-
Notifications
You must be signed in to change notification settings - Fork 2
/
menu.cpp
133 lines (102 loc) · 4.54 KB
/
menu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "menu.hpp"
#include "planet.hpp"
#include "tongue.hpp"
#include "syslog.hpp"
#include "graphlet/primitive.hpp"
using namespace WarGrey::SCADA;
using namespace Windows::Foundation;
using namespace Windows::UI;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Microsoft::Graphics::Canvas::Brushes;
/*************************************************************************************************/
static IPlanet* the_planet_for_multiple_selected_targets = nullptr;
static IGraphlet* the_specific_target = nullptr;
// Stupid Microsoft for its broken template specialization
static void menu_set_foreground(MenuFlyout^ master, unsigned int idx, Brush^ brush) {
if (ui_thread_accessed()) {
if (idx < master->Items->Size) {
MenuFlyoutItem^ item = dynamic_cast<MenuFlyoutItem^>(master->Items->GetAt(idx));
if (item->Command->CanExecute(nullptr)) {
item->Foreground = brush;
}
}
} else {
ui_thread_run_async([=]() { menu_set_foreground_color(master, idx, brush); });
}
}
/*************************************************************************************************/
IGraphlet* WarGrey::SCADA::menu_get_next_target_graphlet(IGraphlet* start) {
IGraphlet* target = nullptr;
if (start == nullptr) {
if (the_planet_for_multiple_selected_targets != nullptr) {
target = the_planet_for_multiple_selected_targets->find_next_selected_graphlet(start);
} else {
target = the_specific_target;
}
} else if (the_planet_for_multiple_selected_targets != nullptr) {
target = the_planet_for_multiple_selected_targets->find_next_selected_graphlet(start);
}
return target;
}
/*************************************************************************************************/
void WarGrey::SCADA::menu_push_command(MenuFlyout^ menu_background, Platform::String^ label, ICommand^ exe) {
auto item = ref new MenuFlyoutItem();
item->Command = exe;
item->Name = label;
item->Text = item->Name;
menu_background->Items->Append(item);
}
void WarGrey::SCADA::group_menu_push_command(MenuFlyout^ menu_background, Platform::String^ group, Platform::String^ label, ICommand^ exe) {
auto item = ref new MenuFlyoutItem();
item->Command = exe;
item->Name = group + ": " + label;
item->Text = item->Name;
menu_background->Items->Append(item);
}
void WarGrey::SCADA::menu_push_command(MenuFlyout^ menu_background, ICommand^ exe, Platform::String^ label, Platform::String^ tongue) {
auto item = ref new MenuFlyoutItem();
item->Command = exe;
item->Name = label;
item->Text = speak(label, ((tongue == nullptr) ? "menu" : tongue));
menu_background->Items->Append(item);
}
void WarGrey::SCADA::group_menu_push_command(MenuFlyout^ menu_background, ICommand^ exe
, Platform::String^ group, Platform::String^ label, Platform::String^ maybe_tongue) {
auto item = ref new MenuFlyoutItem();
Platform::String^ tongue = ((maybe_tongue == nullptr) ? "menu" : maybe_tongue);
item->Command = exe;
item->Name = group + ": " + label;
item->Text = speak(group, tongue) + ": " + speak(label, tongue);
menu_background->Items->Append(item);
}
void WarGrey::SCADA::menu_popup(MenuFlyout^ m, IGraphlet* g, float local_x, float local_y, float xoff, float yoff) {
IPlanet* p = g->master();
if (p != nullptr) {
Point pt = p->local_to_global_point(g, local_x, local_y, xoff, yoff);
the_planet_for_multiple_selected_targets = nullptr;
the_specific_target = g;
m->ShowAt(p->master()->display()->canvas, p->master()->local_to_global_point(p, pt.X, pt.Y));
}
}
void WarGrey::SCADA::menu_popup(MenuFlyout^ m, IPlanet* p, float x, float y, float xoff, float yoff) {
if (p != nullptr) {
the_planet_for_multiple_selected_targets = p;
the_specific_target = nullptr;
m->ShowAt(p->master()->display()->canvas, p->master()->local_to_global_point(p, x, y, xoff, yoff));
}
}
void WarGrey::SCADA::group_menu_popup(MenuFlyout^ m, IPlanet* p, float x, float y, float xoff, float yoff) {
if (p != nullptr) {
m->ShowAt(p->master()->display()->canvas, p->master()->local_to_global_point(p, x, y, xoff, yoff));
}
}
/*************************************************************************************************/
void WarGrey::SCADA::menu_set_foreground_color(MenuFlyout^ master, unsigned int idx, CanvasSolidColorBrush^ brush) {
menu_set_foreground(master, idx, ref new SolidColorBrush(brush->Color));
}
void WarGrey::SCADA::menu_set_foreground_color(MenuFlyout^ master, unsigned int idx, Brush^ brush) {
menu_set_foreground(master, idx, brush);
}