Skip to content

Commit 5f68ab6

Browse files
author
Olivier Butler
committed
monitor'sUI automaticaly found
1 parent 6a66300 commit 5f68ab6

File tree

5 files changed

+238
-87
lines changed

5 files changed

+238
-87
lines changed

src/bp.c

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,11 +1482,9 @@ bp_can_start(const char **reason) {
14821482
return (B_FALSE);
14831483
}
14841484

1485-
if (!ignore_doors_check && (!acf_doors_closed())) {
1486-
if (reason != NULL) {
1487-
*reason = _("Pushback not yet possible: Doors and hatches "
1485+
if (reason != NULL && !ignore_doors_check && (!acf_doors_closed())) {
1486+
*reason = _("Pushback not yet possible: Doors and hatches "
14881487
"not all closed.");
1489-
}
14901488
return (B_FALSE);
14911489
}
14921490

@@ -2456,26 +2454,28 @@ disco_win_draw(XPLMWindowID inWindowID, void *inRefcon) {
24562454
int w, h, mx, my;
24572455

24582456
UNUSED(inRefcon);
2459-
BPGetScreenSizeUIScaled(&w, &h, B_FALSE);
2457+
// BPGetScreenSizeUIScaled(&w, &h, B_FALSE);
2458+
h = monitor_def.h;
2459+
w = monitor_def.w;
24602460
XPLMGetMouseLocationGlobal(&mx, &my);
24612461

24622462
XPLMSetGraphicsState(0, 1, 0, 0, 1, 0, 0);
24632463
if (inWindowID == bp_ls.disco_win) {
2464-
bool_t is_lit = (mx >= w / 2 - 1.5 * disco_buttons[0].w &&
2465-
mx <= w / 2 - 0.5 * disco_buttons[0].w &&
2466-
my >= h - 1.5 * disco_buttons[0].h &&
2467-
my <= h - 0.5 * disco_buttons[0].h);
2468-
draw_icon(&disco_buttons[0], w / 2 - 1.5 * disco_buttons[0].w,
2469-
h - 1.5 * disco_buttons[0].h, 1.0,
2464+
bool_t is_lit = (mx >= monitor_def.x_origin + w / 2 - 1.5 * disco_buttons[0].w &&
2465+
mx <= monitor_def.x_origin + w / 2 - 0.5 * disco_buttons[0].w &&
2466+
my >= monitor_def.y_origin + h - 1.5 * disco_buttons[0].h &&
2467+
my <= monitor_def.y_origin + h - 0.5 * disco_buttons[0].h);
2468+
draw_icon(&disco_buttons[0], monitor_def.x_origin + w / 2 - 1.5 * disco_buttons[0].w,
2469+
monitor_def.y_origin + h - 1.5 * disco_buttons[0].h, 1.0,
24702470
B_FALSE, is_lit);
24712471
} else {
2472-
bool_t is_lit = (mx >= w / 2 + 0.5 * disco_buttons[1].w &&
2473-
mx <= w / 2 + 1.5 * disco_buttons[1].w &&
2474-
my >= h - 1.5 * disco_buttons[1].h &&
2475-
my <= h - 0.5 * disco_buttons[1].h);
2472+
bool_t is_lit = (mx >= monitor_def.x_origin + w / 2 + 0.5 * disco_buttons[1].w &&
2473+
mx <= monitor_def.x_origin + w / 2 + 1.5 * disco_buttons[1].w &&
2474+
my >= monitor_def.y_origin + h - 1.5 * disco_buttons[1].h &&
2475+
my <= monitor_def.y_origin + h - 0.5 * disco_buttons[1].h);
24762476
ASSERT(inWindowID == bp_ls.recon_win);
2477-
draw_icon(&disco_buttons[1], w / 2 + 0.5 * disco_buttons[1].w,
2478-
h - 1.5 * disco_buttons[1].h, 1.0,
2477+
draw_icon(&disco_buttons[1], monitor_def.x_origin + w / 2 + 0.5 * disco_buttons[1].w,
2478+
monitor_def.y_origin + h - 1.5 * disco_buttons[1].h, 1.0,
24792479
B_FALSE, is_lit);
24802480
}
24812481
}
@@ -2568,20 +2568,23 @@ disco_intf_show(void) {
25682568
};
25692569
int w, h;
25702570

2571-
BPGetScreenSizeUIScaled(&w, &h, B_TRUE);
2571+
initMonitorOrigin();
2572+
// BPGetScreenSizeUIScaled(&w, &h, B_TRUE);
2573+
h = monitor_def.h;
2574+
w = monitor_def.w;
25722575

2573-
disco_ops.left = w / 2 - 1.5 * disco_buttons[0].w;
2574-
disco_ops.right = w / 2 - 0.5 * disco_buttons[0].w;
2575-
disco_ops.top = h - 0.5 * disco_buttons[0].h;
2576-
disco_ops.bottom = h - 1.5 * disco_buttons[0].h;
2576+
disco_ops.left = monitor_def.x_origin + w / 2 - 1.5 * disco_buttons[0].w;
2577+
disco_ops.right = monitor_def.x_origin + w / 2 - 0.5 * disco_buttons[0].w;
2578+
disco_ops.top = monitor_def.y_origin + h - 0.5 * disco_buttons[0].h;
2579+
disco_ops.bottom = monitor_def.y_origin + h - 1.5 * disco_buttons[0].h;
25772580
bp_ls.disco_win = XPLMCreateWindowEx(&disco_ops);
25782581
ASSERT(bp_ls.disco_win != NULL);
25792582
XPLMBringWindowToFront(bp_ls.disco_win);
25802583

2581-
disco_ops.left = w / 2 + 0.5 * disco_buttons[1].w;
2582-
disco_ops.right = w / 2 + 1.5 * disco_buttons[1].w;
2583-
disco_ops.top = h - 0.5 * disco_buttons[1].h;
2584-
disco_ops.bottom = h - 1.5 * disco_buttons[1].h;
2584+
disco_ops.left = monitor_def.x_origin + w / 2 + 0.5 * disco_buttons[1].w;
2585+
disco_ops.right = monitor_def.x_origin + w / 2 + 1.5 * disco_buttons[1].w;
2586+
disco_ops.top = monitor_def.y_origin + h - 0.5 * disco_buttons[1].h;
2587+
disco_ops.bottom = monitor_def.y_origin + h - 1.5 * disco_buttons[1].h;
25852588
bp_ls.recon_win = XPLMCreateWindowEx(&disco_ops);
25862589
ASSERT(bp_ls.recon_win != NULL);
25872590
XPLMBringWindowToFront(bp_ls.recon_win);
@@ -2618,29 +2621,32 @@ main_win_click(XPLMWindowID inWindowID, int x, int y, XPLMMouseStatus inMouse,
26182621

26192622
static void
26202623
main_win_draw(XPLMWindowID inWindowID, void *inRefcon) {
2621-
int w, h, mx, my;
2624+
int h, mx, my;
26222625

26232626
UNUSED(inRefcon);
2624-
BPGetScreenSizeUIScaled(&w, &h, B_FALSE);
2627+
// BPGetScreenSizeUIScaled(&w, &h, B_FALSE);
2628+
h = monitor_def.h;
2629+
//w = monitor_def.w;
2630+
26252631
XPLMGetMouseLocationGlobal(&mx, &my);
26262632

26272633
XPLMSetGraphicsState(0, 1, 0, 0, 1, 0, 0);
26282634
if (inWindowID == bp_ls.planner_win) {
2629-
bool_t is_lit = (mx >= 0 &&
2630-
mx <= disco_buttons[2].w &&
2631-
my >= h/2 - disco_buttons[2].h &&
2632-
my <= h/2 );
2633-
draw_icon(&disco_buttons[2], 0,
2634-
h/2 - disco_buttons[2].h, 1.0,
2635+
bool_t is_lit = (mx >= monitor_def.x_origin &&
2636+
mx <= monitor_def.x_origin + disco_buttons[2].w &&
2637+
my >= monitor_def.y_origin + h/2 - disco_buttons[2].h &&
2638+
my <= monitor_def.y_origin + h/2 );
2639+
draw_icon(&disco_buttons[2], monitor_def.x_origin,
2640+
monitor_def.y_origin + h/2 - disco_buttons[2].h, 1.0,
26352641
B_FALSE, is_lit);
26362642
} else {
2637-
bool_t is_lit = (mx >= 0 &&
2638-
mx <= disco_buttons[3].w &&
2639-
my >= h/2 - 1.5 * disco_buttons[2].h - disco_buttons[3].h &&
2640-
my <= h/2 - 1.5 * disco_buttons[2].h);
2643+
bool_t is_lit = (mx >= monitor_def.x_origin &&
2644+
mx <= monitor_def.x_origin + disco_buttons[3].w &&
2645+
my >= monitor_def.y_origin + h/2 - 1.5 * disco_buttons[2].h - disco_buttons[3].h &&
2646+
my <= monitor_def.y_origin + h/2 - 1.5 * disco_buttons[2].h);
26412647
ASSERT(inWindowID == bp_ls.start_pb_win);
2642-
draw_icon(&disco_buttons[3], 0,
2643-
h/2 - 1.5 * disco_buttons[2].h - disco_buttons[3].h, 1.0,
2648+
draw_icon(&disco_buttons[3], monitor_def.x_origin,
2649+
monitor_def.y_origin + h/2 - 1.5 * disco_buttons[2].h - disco_buttons[3].h, 1.0,
26442650
B_FALSE, is_lit);
26452651
}
26462652
}
@@ -2658,15 +2664,20 @@ main_intf_show(void) {
26582664
.handleMouseWheelFunc = nil_win_wheel,
26592665
.refcon = NULL
26602666
};
2661-
int w, h;
2662-
initMonitorOrigin(0);
2663-
BPGetScreenSizeUIScaled(&w, &h, B_TRUE);
2667+
int h;
2668+
initMonitorOrigin();
2669+
//BPGetScreenSizeUIScaled(&w, &h, B_TRUE);
2670+
h = monitor_def.h;
2671+
//w = monitor_def.w;
2672+
2673+
2674+
logMsg("Orign x %d y %d",monitor_def.x_origin,monitor_def.y_origin );
26642675

26652676
if (bp_ls.planner_win == NULL) {
26662677
load_icon(&disco_buttons[2]);
26672678
disco_ops.left = monitor_def.x_origin ; // w / 2 - 1.5 * disco_buttons[0].w;
2668-
disco_ops.right = disco_buttons[2].w;
2669-
disco_ops.top = h/2 ; // - 0.5 * disco_buttons[0].h;
2679+
disco_ops.right = monitor_def.x_origin + disco_buttons[2].w;
2680+
disco_ops.top = monitor_def.y_origin + h/2 ; // - 0.5 * disco_buttons[0].h;
26702681
disco_ops.bottom = monitor_def.y_origin + h/2 - disco_buttons[2].h;
26712682
bp_ls.planner_win = XPLMCreateWindowEx(&disco_ops);
26722683
ASSERT(bp_ls.planner_win != NULL);
@@ -2676,8 +2687,8 @@ main_intf_show(void) {
26762687
if (bp_ls.start_pb_win == NULL) {
26772688
load_icon(&disco_buttons[3]);
26782689
disco_ops.left = monitor_def.x_origin ; //w / 2 + 0.5 * disco_buttons[1].w;
2679-
disco_ops.right = disco_buttons[3].w;
2680-
disco_ops.top = h/2 - 1.5 * disco_buttons[2].h;
2690+
disco_ops.right = monitor_def.x_origin + disco_buttons[3].w;
2691+
disco_ops.top = monitor_def.y_origin + h/2 - 1.5 * disco_buttons[2].h;
26812692
disco_ops.bottom = monitor_def.y_origin + disco_ops.top - disco_buttons[3].h;
26822693
bp_ls.start_pb_win = XPLMCreateWindowEx(&disco_ops);
26832694
ASSERT(bp_ls.start_pb_win != NULL);

src/bp_cam.c

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -376,18 +376,19 @@ move_camera(XPLMCommandRef cmd, XPLMCommandPhase phase, void *refcon) {
376376

377377
static void
378378
get_vp(vec4 vp) {
379-
int scr_w, scr_h;
379+
/// int scr_w, scr_h;
380380

381381
ASSERT(vp != NULL);
382382
/*
383383
* As fake_win is defined with 0,0 and sizes given by BPGetScreenSizeUIScaled
384384
* let's do the same here. it will fix planner drawing in Xp12
385385
*/
386-
BPGetScreenSizeUIScaled(&scr_w, &scr_h, B_FALSE);
387-
vp[0] = 0;
388-
vp[1] = 0;
389-
vp[2] = scr_w;
390-
vp[3] = scr_h;
386+
/// BPGetScreenSizeUIScaled(&scr_w, &scr_h, B_FALSE);
387+
vp[0] = monitor_def.x_origin;
388+
vp[1] = monitor_def.y_origin;
389+
vp[2] = monitor_def.w;
390+
vp[3] = monitor_def.h;
391+
391392
}
392393

393394
/*
@@ -847,8 +848,11 @@ fake_win_draw(XPLMWindowID inWindowID, void *inRefcon) {
847848
UNUSED(inWindowID);
848849
UNUSED(inRefcon);
849850

850-
BPGetScreenSizeUIScaled(&w, &h, B_FALSE);
851-
XPLMSetWindowGeometry(fake_win, 0, h, w, 0);
851+
//BPGetScreenSizeUIScaled(&w, &h, B_FALSE);
852+
h = monitor_def.h;
853+
w = monitor_def.w;
854+
855+
XPLMSetWindowGeometry(fake_win, monitor_def.x_origin, h, w, monitor_def.y_origin);
852856

853857
if (!XPLMIsWindowInFront(fake_win))
854858
XPLMBringWindowToFront(fake_win);
@@ -875,7 +879,7 @@ fake_win_draw(XPLMWindowID inWindowID, void *inRefcon) {
875879
if (btn->tex == 0)
876880
continue;
877881

878-
draw_icon(btn, w - btn->w * scale, h_off - btn->h * scale,
882+
draw_icon(btn, monitor_def.x_origin + w - btn->w * scale, monitor_def.y_origin + h_off - btn->h * scale,
879883
scale, i == button_hit, i == button_lit);
880884
}
881885

@@ -889,7 +893,9 @@ button_hit_check(int x, int y) {
889893
double scale;
890894
int w, h, h_buttons, h_off;
891895

892-
BPGetScreenSizeUIScaled(&w, &h, B_FALSE);
896+
// BPGetScreenSizeUIScaled(&w, &h, B_FALSE);
897+
h = monitor_def.h;
898+
w = monitor_def.w;
893899

894900
h_buttons = 0;
895901
for (int i = 0; buttons[i].filename != NULL; i++)
@@ -903,8 +909,8 @@ button_hit_check(int x, int y) {
903909
h_off = (h + (h_buttons * scale)) / 2;
904910
for (int i = 0; buttons[i].filename != NULL;
905911
i++, h_off -= buttons[i].h * scale) {
906-
if (x >= w - buttons[i].w * scale && x <= w &&
907-
y >= h_off - buttons[i].h * scale && y <= h_off &&
912+
if (x >= monitor_def.x_origin + w - buttons[i].w * scale && x <= monitor_def.x_origin + w &&
913+
y >= monitor_def.y_origin + h_off - buttons[i].h * scale && y <= monitor_def.y_origin + h_off &&
908914
buttons[i].vk != -1)
909915
return (i);
910916
}
@@ -1203,7 +1209,14 @@ bp_cam_start(void) {
12031209

12041210
push_reset_fov_values();
12051211
eye_track_debut();
1206-
BPGetScreenSizeUIScaled(&fake_win_ops.right, &fake_win_ops.top, B_TRUE);
1212+
// BPGetScreenSizeUIScaled(&fake_win_ops.right, &fake_win_ops.top, B_TRUE);
1213+
1214+
initMonitorOrigin();
1215+
fake_win_ops.left = monitor_def.x_origin;
1216+
fake_win_ops.right = monitor_def.x_origin + monitor_def.w;
1217+
fake_win_ops.bottom = monitor_def.y_origin;
1218+
fake_win_ops.top = monitor_def.y_origin + monitor_def.h;
1219+
12071220

12081221
circle_view_cmd = XPLMFindCommand("sim/view/circle");
12091222
ASSERT(circle_view_cmd != NULL);
@@ -1273,9 +1286,11 @@ bp_cam_start(void) {
12731286

12741287
updateAvailable = getPluginUpdateStatus();
12751288
if (updateAvailable != NULL) {
1276-
snprintf(bottom_msg, sizeof(bottom_msg), "New version of BetterPushBack available: %s (Use SkunkCrafts Updater to update)", updateAvailable);
1277-
init_bottom_msg(bottom_msg);
1289+
// snprintf(bottom_msg, sizeof(bottom_msg), "New version of BetterPushBack available: %s (Use SkunkCrafts Updater to update)", updateAvailable);
1290+
// init_bottom_msg(bottom_msg);
12781291
}
1292+
snprintf(bottom_msg, sizeof(bottom_msg), "New version of BetterPushBack available: xxxx (Use SkunkCrafts Updater to update)");
1293+
init_bottom_msg(bottom_msg);
12791294

12801295
return (B_TRUE);
12811296
}
@@ -1422,16 +1437,16 @@ draw_bottom_msg(int screen_x, int screen_y) {
14221437

14231438
glBindTexture(GL_TEXTURE_2D, bottom_msg.texture);
14241439
glBegin(GL_QUADS);
1425-
glTexCoord2f(0.0, 1.0);
1426-
glVertex2f((screen_x - bottom_msg.width) / 2 - MARGIN_SIZE, 0);
1427-
glTexCoord2f(0.0, 0.0);
1428-
glVertex2f((screen_x - bottom_msg.width) / 2 - MARGIN_SIZE,
1429-
bottom_msg.height + 2 * MARGIN_SIZE);
1430-
glTexCoord2f(1.0, 0.0);
1431-
glVertex2f((screen_x + bottom_msg.width) / 2 + MARGIN_SIZE,
1432-
bottom_msg.height + 2 * MARGIN_SIZE);
1433-
glTexCoord2f(1.0, 1.0);
1434-
glVertex2f((screen_x + bottom_msg.width) / 2 + MARGIN_SIZE, 0);
1440+
glTexCoord2f(monitor_def.x_origin , monitor_def.y_origin + 1.0);
1441+
glVertex2f(monitor_def.x_origin + (screen_x - bottom_msg.width) / 2 - MARGIN_SIZE, monitor_def.y_origin );
1442+
glTexCoord2f(monitor_def.x_origin, monitor_def.y_origin);
1443+
glVertex2f(monitor_def.x_origin + (screen_x - bottom_msg.width) / 2 - MARGIN_SIZE,
1444+
monitor_def.y_origin + bottom_msg.height + 2 * MARGIN_SIZE);
1445+
glTexCoord2f( monitor_def.x_origin + 1, monitor_def.y_origin);
1446+
glVertex2f(monitor_def.x_origin + (screen_x + bottom_msg.width) / 2 + MARGIN_SIZE,
1447+
monitor_def.y_origin + bottom_msg.height + 2 * MARGIN_SIZE);
1448+
glTexCoord2f( monitor_def.x_origin + 1, monitor_def.y_origin + 1);
1449+
glVertex2f(monitor_def.x_origin + (screen_x + bottom_msg.width) / 2 + MARGIN_SIZE, monitor_def.y_origin);
14351450
glEnd();
14361451
}
14371452

src/cab_view.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,12 @@ cam_ctl(XPLMCameraPosition_t *pos, int losing_control, void *refcon)
199199
static void
200200
win_draw(XPLMWindowID inWindowID, void *inRefcon)
201201
{
202-
int w, h;
202+
// int w, h;
203203

204204
UNUSED(inWindowID);
205205
UNUSED(inRefcon);
206-
BPGetScreenSizeUIScaled(&w, &h, B_FALSE);
207-
XPLMSetWindowGeometry(win, 0, h, w, 0);
206+
// BPGetScreenSizeUIScaled(&w, &h, B_FALSE);
207+
XPLMSetWindowGeometry(win, monitor_def.x_origin, monitor_def.h, monitor_def.w, monitor_def.y_origin);
208208

209209
if (hintbar != NULL && microclock() - hintbar_start > HINTBAR_TIMEOUT) {
210210
XPDestroyWidget(hintbar, 1);
@@ -318,6 +318,7 @@ cab_view_start(void)
318318
XPLMControlCamera(xplm_ControlCameraUntilViewChanges, cam_ctl, NULL);
319319
started = B_TRUE;
320320

321+
initMonitorOrigin();
321322
if (win == NULL) {
322323
XPLMCreateWindow_t win_ops = {
323324
.structSize = sizeof (XPLMCreateWindow_t),
@@ -329,7 +330,11 @@ cab_view_start(void)
329330
.handleMouseWheelFunc = win_wheel,
330331
.refcon = NULL
331332
};
332-
BPGetScreenSizeUIScaled(&win_ops.right, &win_ops.top, B_TRUE);
333+
// BPGetScreenSizeUIScaled(&win_ops.right, &win_ops.top, B_TRUE);
334+
win_ops.left = monitor_def.x_origin;
335+
win_ops.right = monitor_def.x_origin + monitor_def.w;
336+
win_ops.bottom = monitor_def.y_origin;
337+
win_ops.top = monitor_def.y_origin + monitor_def.h;
333338
win = XPLMCreateWindowEx(&win_ops);
334339
}
335340
ASSERT(win != NULL);
@@ -342,14 +347,14 @@ cab_view_start(void)
342347
*/
343348
if (hintbar == NULL) {
344349
const char *str = _("Left mouse button to reorient view");
345-
int x, y;
350+
// int x, y;
346351
int w = XPLMMeasureString(xplmFont_Proportional,
347352
str, strlen(str));
348353
XPWidgetID caption;
349354

350-
BPGetScreenSizeUIScaled(&x, &y, B_TRUE);
351-
hintbar = create_widget_rel((x - w) / 2 - 10,
352-
HINTBAR_HEIGHT * 3, B_FALSE, w + 20,
355+
// BPGetScreenSizeUIScaled(&x, &y, B_TRUE);
356+
hintbar = create_widget_rel((monitor_def.w - w) / 2 - 10,
357+
HINTBAR_HEIGHT * 3, B_FALSE, w + 20,
353358
HINTBAR_HEIGHT, 0, "", 1, NULL, xpWidgetClass_MainWindow);
354359
XPSetWidgetProperty(hintbar, xpProperty_MainWindowType,
355360
xpMainWindowStyle_Translucent);

0 commit comments

Comments
 (0)