-
Notifications
You must be signed in to change notification settings - Fork 2
/
gui_fms_option.cpp
110 lines (100 loc) · 4.27 KB
/
gui_fms_option.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
#include <string>
#include <stdio.h>
#include <map>
#include <cstdlib>
#include <cstring>
#include <stdint.h>
#include "include/SDK/XPLMDisplay.h"
#include "include/SDK/XPLMUtilities.h"
#include "include/SDK/XPLMDataAccess.h"
#include "include/SDK/XPLMMenus.h"
#include "include/SDK/XPLMGraphics.h"
#include "include/SDK/XPWidgets.h"
#include "include/SDK/XPStandardWidgets.h"
#include "include/SDK/XPLMDefs.h"
#include "include/gui_fms_option.h"
#include "include/out.h"
#include "include/config.h"
#include "include/fms.h"
static XPWidgetID widget;
static XPWidgetID window;
static XPWidgetID Text_fl;
static XPWidgetID Text_gs;
static XPWidgetID Text_takeoff;
static XPWidgetID button_apply;
static config_t* a_config_ref;
static fms_t* a_fms_ref;
gui_fms_option_t::gui_fms_option_t(config_t* config_ref,fms_t* fms_ref)
{
a_config_ref = config_ref;
a_fms_ref = fms_ref;
}
// handle the creation of the option window
void gui_fms_option_t::enable(void) {
if (XPIsWidgetVisible(widget)) XPHideWidget(widget);
else {
create(300, 600, 300, 350);
XPShowWidget(widget);
}
}
// handle the destruction of the option window
void gui_fms_option_t::disable(void) {
}
// build the FMS Options window
void gui_fms_option_t::create(int x, int y, int w, int h){
int x2 = x + w;
int y2 = y - h;
int Item =0;
// retrieve default FL and GS
char buffer_fl[512],buffer_gs[512],buffer_takeoff[512];
map<string,string> config=a_config_ref->get_config_fms();
sprintf(buffer_fl, "%i",::atoi(config["cruise_fl"].c_str()));
sprintf(buffer_gs, "%i",::atoi(config["cruise_gs"].c_str()));
sprintf(buffer_takeoff, "%s",config["scheduled_takeoff"].c_str());
// build the option window
widget = XPCreateWidget(x, y, x2, y2,1,"FMS Options",1,NULL,xpWidgetClass_MainWindow);
XPSetWidgetProperty(widget, xpProperty_MainWindowHasCloseBoxes, 1);
window = XPCreateWidget(x+30, y-30, x2-30, y2+30,1, "",0,widget,xpWidgetClass_SubWindow);
XPSetWidgetProperty(window, xpProperty_SubWindowType, xpSubWindowStyle_SubWindow);
// build the labels and the text box widgets
XPCreateWidget(x+60, y-(70 + (Item*30)), x+115, y-(92 + (Item*30)),1,"Requested Flight Level (FL)",0,widget,xpWidgetClass_Caption);
Item++;
Text_fl = XPCreateWidget(x+120, y-(70 + (Item*30)), x+210, y-(92 + (Item*30)),1, buffer_fl, 0, widget,xpWidgetClass_TextField);
Item++;
XPCreateWidget(x+60, y-(70 + (Item*30)), x+115, y-(92 + (Item*30)),1,"Requested Ground Speed (kts)",0,widget,xpWidgetClass_Caption);
Item++;
Text_gs = XPCreateWidget(x+120, y-(70 + (Item*30)), x+210, y-(92 + (Item*30)),1, buffer_gs, 0, widget,xpWidgetClass_TextField);
Item++;
XPCreateWidget(x+60, y-(70 + (Item*30)), x+115, y-(92 + (Item*30)),1,"Expected Take-off Zulu Time (HH:MM)",0,widget,xpWidgetClass_Caption);
Item++;
Text_takeoff = XPCreateWidget(x+120, y-(70 + (Item*30)), x+210, y-(92 + (Item*30)),1, buffer_takeoff, 0, widget,xpWidgetClass_TextField);
// build the buttons
Item++;
button_apply = XPCreateWidget(x+120, y-(70 + (Item*30)), x+210, y-(92 + (Item*30)),1, "Apply Data", 0, widget,xpWidgetClass_Button);
XPSetWidgetProperty(button_apply, xpProperty_ButtonType, xpPushButton);
// Add the callback
XPAddWidgetCallback(widget, click);
}
// handle events from the FMS options panel
int gui_fms_option_t::click(XPWidgetMessage inMessage,XPWidgetID inWidget,intptr_t inParam1,intptr_t inParam2) {
if (inMessage == xpMessage_CloseButtonPushed){
if(XPIsWidgetVisible(widget)) XPHideWidget(widget);
return 1;
}
if (inMessage == xpMsg_PushButtonPressed){
if (inParam1 == (intptr_t)button_apply){
char buffer_fl[512],buffer_gs[512],buffer_takeoff[512];
XPGetWidgetDescriptor(Text_fl, buffer_fl, 512);
XPGetWidgetDescriptor(Text_gs, buffer_gs, 512);
XPGetWidgetDescriptor(Text_takeoff, buffer_takeoff, 512);
string fl_s = string(buffer_fl);
string gs_s = string(buffer_gs);
string takeoff_s = string(buffer_takeoff);
a_config_ref->set_fms_config(fl_s,gs_s,takeoff_s);
a_fms_ref->a_fp_ref->a_status = 99; // force refresh
XPHideWidget(widget);
return 1;
}
}
return 0;
}