@@ -332,12 +332,14 @@ struct BaseGraphWindow : Window {
332
332
static_assert (GRAPH_MAX_DATASETS >= (int )NUM_CARGO && GRAPH_MAX_DATASETS >= (int )MAX_COMPANIES);
333
333
assert (this ->num_vert_lines > 0 );
334
334
335
+ bool rtl = _current_text_dir == TD_RTL;
336
+
335
337
/* Rect r will be adjusted to contain just the graph, with labels being
336
338
* placed outside the area. */
337
339
r.top += ScaleGUITrad (5 ) + GetCharacterHeight (FS_SMALL) / 2 ;
338
340
r.bottom -= (this ->draw_dates ? 2 : 1 ) * GetCharacterHeight (FS_SMALL) + ScaleGUITrad (4 );
339
- r.left += ScaleGUITrad (9 );
340
- r.right -= ScaleGUITrad (5 );
341
+ r.left += ScaleGUITrad (rtl ? 5 : 9 );
342
+ r.right -= ScaleGUITrad (rtl ? 9 : 5 );
341
343
342
344
/* Initial number of horizontal lines. */
343
345
int num_hori_lines = 160 / ScaleGUITrad (MIN_GRID_PIXEL_SIZE);
@@ -349,14 +351,22 @@ struct BaseGraphWindow : Window {
349
351
350
352
int label_width = GetYLabelWidth (interval, num_hori_lines);
351
353
352
- r.left += label_width;
354
+ if (rtl) {
355
+ r.right -= label_width;
356
+ } else {
357
+ r.left += label_width;
358
+ }
353
359
354
360
int x_sep = (r.right - r.left ) / this ->num_vert_lines ;
355
361
int y_sep = (r.bottom - r.top ) / num_hori_lines;
356
362
357
363
/* Redetermine right and bottom edge of graph to fit with the integer
358
364
* separation values. */
359
- r.right = r.left + x_sep * this ->num_vert_lines ;
365
+ if (rtl) {
366
+ r.left = r.right - x_sep * this ->num_vert_lines ;
367
+ } else {
368
+ r.right = r.left + x_sep * this ->num_vert_lines ;
369
+ }
360
370
r.bottom = r.top + y_sep * num_hori_lines;
361
371
362
372
OverflowSafeInt64 interval_size = interval.highest + abs (interval.lowest );
@@ -369,7 +379,12 @@ struct BaseGraphWindow : Window {
369
379
/* Draw the vertical grid lines. */
370
380
371
381
/* Don't draw the first line, as that's where the axis will be. */
372
- x = r.left + x_sep;
382
+ if (rtl) {
383
+ x_sep = -x_sep;
384
+ x = r.right + x_sep;
385
+ } else {
386
+ x = r.left + x_sep;
387
+ }
373
388
374
389
int grid_colour = GRAPH_GRID_COLOUR;
375
390
for (int i = 1 ; i < this ->num_vert_lines + 1 ; i++) {
@@ -385,7 +400,11 @@ struct BaseGraphWindow : Window {
385
400
y = r.bottom ;
386
401
387
402
for (int i = 0 ; i < (num_hori_lines + 1 ); i++) {
388
- GfxFillRect (r.left - ScaleGUITrad (3 ), y, r.left - 1 , y, GRAPH_AXIS_LINE_COLOUR);
403
+ if (rtl) {
404
+ GfxFillRect (r.right + 1 , y, r.right + ScaleGUITrad (3 ), y, GRAPH_AXIS_LINE_COLOUR);
405
+ } else {
406
+ GfxFillRect (r.left - ScaleGUITrad (3 ), y, r.left - 1 , y, GRAPH_AXIS_LINE_COLOUR);
407
+ }
389
408
GfxFillRect (r.left , y, r.right , y, GRAPH_GRID_COLOUR);
390
409
y -= y_sep;
391
410
}
@@ -409,24 +428,36 @@ struct BaseGraphWindow : Window {
409
428
y = r.top - GetCharacterHeight (FS_SMALL) / 2 ;
410
429
411
430
for (int i = 0 ; i < (num_hori_lines + 1 ); i++) {
412
- DrawString (r.left - label_width - ScaleGUITrad (4 ), r.left - ScaleGUITrad (4 ), y,
413
- GetString (STR_GRAPH_Y_LABEL, this ->format_str_y_axis , y_label),
414
- GRAPH_AXIS_LABEL_COLOUR, SA_RIGHT);
431
+ if (rtl) {
432
+ DrawString (r.right + ScaleGUITrad (4 ), r.right + label_width + ScaleGUITrad (4 ), y,
433
+ GetString (STR_GRAPH_Y_LABEL, this ->format_str_y_axis , y_label),
434
+ GRAPH_AXIS_LABEL_COLOUR, SA_RIGHT | SA_FORCE);
435
+ } else {
436
+ DrawString (r.left - label_width - ScaleGUITrad (4 ), r.left - ScaleGUITrad (4 ), y,
437
+ GetString (STR_GRAPH_Y_LABEL, this ->format_str_y_axis , y_label),
438
+ GRAPH_AXIS_LABEL_COLOUR, SA_RIGHT | SA_FORCE);
439
+ }
415
440
416
441
y_label -= y_label_separation;
417
442
y += y_sep;
418
443
}
419
444
420
445
/* Draw x-axis labels and markings for graphs based on financial quarters and years. */
421
446
if (this ->draw_dates ) {
422
- x = r.left ;
447
+ x = rtl ? r. right : r.left ;
423
448
y = r.bottom + ScaleGUITrad (2 );
424
449
TimerGameEconomy::Month month = this ->month ;
425
450
TimerGameEconomy::Year year = this ->year ;
426
451
for (int i = 0 ; i < this ->num_on_x_axis ; i++) {
427
- DrawStringMultiLine (x, x + x_sep, y, this ->height ,
428
- GetString (month == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH, STR_MONTH_ABBREV_JAN + month, year),
429
- GRAPH_AXIS_LABEL_COLOUR, SA_LEFT);
452
+ if (rtl) {
453
+ DrawStringMultiLine (x + x_sep, x, y, this ->height ,
454
+ GetString (month == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH, STR_MONTH_ABBREV_JAN + month, year),
455
+ GRAPH_AXIS_LABEL_COLOUR, SA_LEFT);
456
+ } else {
457
+ DrawStringMultiLine (x, x + x_sep, y, this ->height ,
458
+ GetString (month == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH, STR_MONTH_ABBREV_JAN + month, year),
459
+ GRAPH_AXIS_LABEL_COLOUR, SA_LEFT);
460
+ }
430
461
431
462
month += this ->month_increment ;
432
463
if (month >= 12 ) {
@@ -440,7 +471,7 @@ struct BaseGraphWindow : Window {
440
471
}
441
472
} else {
442
473
/* Draw x-axis labels for graphs not based on quarterly performance (cargo payment rates, and all graphs when using wallclock units). */
443
- x = r.left ;
474
+ x = rtl ? r. right : r.left ;
444
475
y = r.bottom + ScaleGUITrad (2 );
445
476
446
477
int16_t iterator;
@@ -454,7 +485,11 @@ struct BaseGraphWindow : Window {
454
485
}
455
486
456
487
for (int i = 0 ; i < this ->num_on_x_axis ; i++) {
457
- DrawString (x + 1 , x + x_sep - 1 , y, GetString (STR_GRAPH_Y_LABEL_NUMBER, label), GRAPH_AXIS_LABEL_COLOUR, SA_HOR_CENTER);
488
+ if (rtl) {
489
+ DrawString (x + x_sep + 1 , x - 1 , y, GetString (STR_GRAPH_Y_LABEL_NUMBER, label), GRAPH_AXIS_LABEL_COLOUR, SA_HOR_CENTER);
490
+ } else {
491
+ DrawString (x + 1 , x + x_sep - 1 , y, GetString (STR_GRAPH_Y_LABEL_NUMBER, label), GRAPH_AXIS_LABEL_COLOUR, SA_HOR_CENTER);
492
+ }
458
493
459
494
label += iterator;
460
495
x += x_sep;
@@ -471,7 +506,11 @@ struct BaseGraphWindow : Window {
471
506
if (HasBit (this ->excluded_range , dataset.range_bit )) continue ;
472
507
473
508
/* Centre the dot between the grid lines. */
474
- x = r.left + (x_sep / 2 );
509
+ if (rtl) {
510
+ x = r.right + (x_sep / 2 );
511
+ } else {
512
+ x = r.left + (x_sep / 2 );
513
+ }
475
514
476
515
uint prev_x = INVALID_DATAPOINT_POS;
477
516
uint prev_y = INVALID_DATAPOINT_POS;
0 commit comments