Skip to content

Commit d74981b

Browse files
committed
Merge pull request #471 from MageKing17/feature/escort-gauge-right-aligned-names
Add "Right-Align Ship Names:" option to HudGaugeEscort.
2 parents 87d07c9 + 6df0a70 commit d74981b

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

code/graphics/font.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ font *Current_font = NULL;
4343
* @param str string to crop. Modifies this string directly
4444
* @param max_str max characters allowed in str
4545
* @param max_width number of pixels to limit string to (less than or equal to).
46-
* @return Returns same pointer passed in for str.
46+
* @return Returns the width of the string as given by gr_get_string_size().
4747
*/
48-
char *gr_force_fit_string(char *str, int max_str, int max_width)
48+
int gr_force_fit_string(char *str, int max_str, int max_width)
4949
{
5050
int w;
5151

@@ -65,7 +65,7 @@ char *gr_force_fit_string(char *str, int max_str, int max_width)
6565
}
6666
}
6767

68-
return str;
68+
return w;
6969
}
7070

7171
/**

code/graphics/font.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ extern int gr_get_fontnum(const char *filename);
7373
extern void gr_set_font(int fontnum);
7474

7575
void gr_print_timestamp(int x, int y, fix timestamp, int resize_mode);
76-
char *gr_force_fit_string(char *str, int max_str, int max_width);
76+
int gr_force_fit_string(char *str, int max_str, int max_width);
7777
void gr_font_init();
7878
void gr_font_close();
7979

code/hud/hudescort.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ void HudGaugeEscort::initShipNameMaxWidth(int w)
202202
ship_name_max_width = w;
203203
}
204204

205+
void HudGaugeEscort::initRightAlignNames(bool align)
206+
{
207+
right_align_names = align;
208+
}
209+
205210
void HudGaugeEscort::initBitmaps(char *fname_top, char *fname_middle, char *fname_bottom)
206211
{
207212
Escort_gauges[0].first_frame = bm_load_animation(fname_top, &Escort_gauges[0].num_frames);
@@ -368,10 +373,14 @@ void HudGaugeEscort::renderIcon(int x, int y, int index)
368373

369374
// print out ship name
370375
strcpy_s(buf, sp->ship_name);
371-
gr_force_fit_string(buf, 255, ship_name_max_width);
372376
end_string_at_first_hash_symbol(buf);
373-
374-
renderString( x + ship_name_offsets[0], y + ship_name_offsets[1], EG_ESCORT1 + index, buf);
377+
const int w = gr_force_fit_string(buf, 255, ship_name_max_width);
378+
379+
if (right_align_names) {
380+
renderString( x + ship_name_offsets[0] + ship_name_max_width - w, y + ship_name_offsets[1], EG_ESCORT1 + index, buf);
381+
} else {
382+
renderString( x + ship_name_offsets[0], y + ship_name_offsets[1], EG_ESCORT1 + index, buf);
383+
}
375384

376385
// show ship integrity
377386
hud_get_target_strength(objp, &shields, &integrity);

code/hud/hudescort.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class HudGaugeEscort: public HudGauge
5252
int ship_integrity_offsets[2]; // Offset of the Ship Hull column
5353
int ship_status_offsets[2]; // Offset of the Ship Status column
5454
int ship_name_max_width; // max width of ship name entries
55+
bool right_align_names; // whether or not to right-align ship names
5556
public:
5657
HudGaugeEscort();
5758
void initBitmaps(char *fname_top, char *fname_middle, char *fname_bottom);
@@ -65,6 +66,7 @@ class HudGaugeEscort: public HudGauge
6566
void initShipIntegrityOffsets(int x, int y);
6667
void initShipStatusOffsets(int x, int y);
6768
void initShipNameMaxWidth(int w);
69+
void initRightAlignNames(bool align);
6870
int setGaugeColorEscort(int index, int team);
6971
virtual void render(float frametime);
7072
void pageIn();

code/hud/hudparse.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,7 @@ void load_gauge_escort_view(int base_w, int base_h, int hud_font, bool scale_gau
17021702
int ship_name_max_w = 100;
17031703
int ship_integrity_offsets[2];
17041704
int ship_status_offsets[2];
1705+
bool right_align_names = false;
17051706
char header_text[MAX_FILENAME_LEN] = "";
17061707
char fname_top[MAX_FILENAME_LEN] = "escort1";
17071708
char fname_middle[MAX_FILENAME_LEN] = "escort2";
@@ -1784,6 +1785,10 @@ void load_gauge_escort_view(int base_w, int base_h, int hud_font, bool scale_gau
17841785
stuff_int(&ship_name_max_w);
17851786
}
17861787

1788+
if ( optional_string("Right-Align Ship Names:") ) {
1789+
stuff_boolean(&right_align_names);
1790+
}
1791+
17871792
if (header_text[0] == '\0') {
17881793
strcpy_s(header_text, XSTR("monitoring", 285));
17891794
}
@@ -1799,6 +1804,7 @@ void load_gauge_escort_view(int base_w, int base_h, int hud_font, bool scale_gau
17991804
hud_gauge->initShipNameOffsets(ship_name_offsets[0], ship_name_offsets[1]);
18001805
hud_gauge->initShipStatusOffsets(ship_status_offsets[0], ship_status_offsets[1]);
18011806
hud_gauge->initShipNameMaxWidth(ship_name_max_w);
1807+
hud_gauge->initRightAlignNames(right_align_names);
18021808

18031809
if(ship_idx->at(0) >= 0) {
18041810
for (SCP_vector<int>::iterator ship_index = ship_idx->begin(); ship_index != ship_idx->end(); ++ship_index) {

0 commit comments

Comments
 (0)