Skip to content

Commit 16cd05c

Browse files
committed
Fix bad centering with libngdevkit's display functions
Closes #121
1 parent 804a650 commit 16cd05c

3 files changed

Lines changed: 31 additions & 5 deletions

File tree

runtime/libngdevkit/ng-text.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2026 Damien Ciabrini
3+
* This file is part of ngdevkit
4+
*
5+
* ngdevkit is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as
7+
* published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* ngdevkit is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with ngdevkit. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#ifndef __NG_TEXT_H__
20+
#define __NG_TEXT_H__
21+
22+
#define FIXED_LAYOUT_WIDTH 40
23+
24+
#endif /* __NG_TEXT_H__ */

runtime/libngdevkit/ng_center_text_args.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020 Damien Ciabrini
2+
* Copyright (c) 2020-2026 Damien Ciabrini
33
* This file is part of ngdevkit
44
*
55
* ngdevkit is free software: you can redistribute it and/or modify
@@ -19,10 +19,11 @@
1919
#include <ngdevkit/neogeo.h>
2020
#include <ngdevkit/ng-fix.h>
2121
#include <string.h>
22+
#include "ng-text.h"
2223

2324

2425
/// Handy function to display a centered string on the fix map
2526
void ng_center_text_args(u8 y, u8 palette, u16 start_tile, const char *text) {
2627
u8 len = strlen(text);
27-
ng_text_args((42 - len)>>1, y, palette, start_tile, text);
28+
ng_text_args((FIXED_LAYOUT_WIDTH - len)>>1, y, palette, start_tile, text);
2829
}

runtime/libngdevkit/ng_center_text_tall_args.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020 Damien Ciabrini
2+
* Copyright (c) 2020-2026 Damien Ciabrini
33
* This file is part of ngdevkit
44
*
55
* ngdevkit is free software: you can redistribute it and/or modify
@@ -19,11 +19,12 @@
1919
#include <ngdevkit/neogeo.h>
2020
#include <ngdevkit/ng-fix.h>
2121
#include <string.h>
22+
#include "ng-text.h"
2223

2324

2425
/// Handy function to display a tall string on the fix map
2526
void ng_center_text_tall_args(u8 y, u8 palette, u16 start_tile, const char *text) {
2627
u8 len = strlen(text);
27-
ng_text_args((42 - len)>>1, y, palette, start_tile, text);
28-
ng_text_args((42 - len)>>1, y+1, palette, start_tile+256, text);
28+
ng_text_args((FIXED_LAYOUT_WIDTH - len)>>1, y, palette, start_tile, text);
29+
ng_text_args((FIXED_LAYOUT_WIDTH - len)>>1, y+1, palette, start_tile+256, text);
2930
}

0 commit comments

Comments
 (0)