summaryrefslogtreecommitdiff
path: root/csrc/font.c
diff options
context:
space:
mode:
authorIru Cai <mytbk920423@gmail.com>2018-09-06 16:37:18 +0800
committerIru Cai <mytbk920423@gmail.com>2018-09-06 16:37:18 +0800
commitadb71a489fa1a0fdd5ae5529efa62e316bbf661c (patch)
tree3917f47f872176345b7a0ef2e584e729c6e149d4 /csrc/font.c
parent5aac9b7cafc27cbe18bcde27373dc0b1a72e9c69 (diff)
downloadrich4-adb71a489fa1a0fdd5ae5529efa62e316bbf661c.tar.xz
font.c: surface_bound, more beautify
Diffstat (limited to 'csrc/font.c')
-rw-r--r--csrc/font.c91
1 files changed, 70 insertions, 21 deletions
diff --git a/csrc/font.c b/csrc/font.c
index 6489863..9a824b5 100644
--- a/csrc/font.c
+++ b/csrc/font.c
@@ -3,7 +3,8 @@
HFONT gFont; // 0x4762d0
int gFontHeight; // 0x4762d4
-uint32_t gfa[4]; // 0x4762d8, 0x4762dc, 0x4762e0, 0x4762e4
+uint32_t gfa[2]; // 0x4762d8, 0x4762dc
+COLORREF txt_colors[2]; // 0x4762e0, 0x4762e4
const char tfname[] = "\xb2\xd3\xa9\xfa\xc5\xe9"; // 0x4660a0, typeface name, BIG5:细明体
static inline uint32_t swapbytes3(uint32_t x)
@@ -14,8 +15,8 @@ static inline uint32_t swapbytes3(uint32_t x)
/* 0x0044f9d8 */
HFONT create_some_font(int a0, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4)
{
- gfa[2] = swapbytes3(a1);
- gfa[3] = swapbytes3(a2);
+ txt_colors[0] = swapbytes3(a1);
+ txt_colors[1] = swapbytes3(a2);
gfa[0] = a3;
gfa[1] = a4;
int weight = (a3==2)?400:700;
@@ -45,6 +46,54 @@ void drawStringY(HDC hdc, int nXStart, int nYStart, LPCSTR str)
}
}
+void surface_bound(uint16_t *lpSurface, RECT *dim1, RECT *dim2)
+{
+ j_min = 10000;
+ i_min = 10000;
+ j_max = -10000;
+ i_max = -10000;
+
+
+ for (int i = 0; i < dim1->bottom; i++) {
+ int t = 0;
+ for (int j = dim1->left; j < dim1->right; j++) {
+ if (lpSurface[t+j] != 0) {
+ if (j < j_min)
+ j_min = j;
+
+ if (i < i_min)
+ i_min = i;
+
+ if (j > j_max)
+ j_max = j;
+
+ if (i > i_max)
+ i_max = i;
+ }
+ }
+ t += 0x200;
+ }
+
+ if (j_min == 10000) {
+ dim2->top = dim2->left = dim2->right = dim2->bottom = 0;
+ } else {
+ dim2->left = j_min;
+ dim2->top = i_min;
+ dim2->right = j_max
+ dim2->bottom = i_max;
+ }
+}
+
+void fcn_4564e6(void *sf, int a1, int a2, int a3, int a4, int a5, int a6, int a7)
+{
+ fcn.00455fd9(640, sf, a1, a2, a3, a4, a5, a6, a7, 1);
+}
+
+void fcn_456495(void *sf, int a1, int a2, int a3, int a4, int a5, int a6, int a7)
+{
+ fcn.00455fd9(640, sf, a1, a2, a3, a4, a5, a6, a7, 0);
+}
+
void draw_some_text(a1, const char *str, int a3, int a4, int a5)
{
DDSURFACEDESC desc; /* esp */
@@ -83,7 +132,7 @@ void draw_some_text(a1, const char *str, int a3, int a4, int a5)
}
uint8_t dh = gfa[0];
if ( (dh & 1) != 0 ) {
- SetTextColor(hDC, dw_4762e4);
+ SetTextColor(hDC, txt_colors[1]);
fmt_dim1.left = 1;
fmt_dim1.top = 1;
if (a5 >= 4) {
@@ -98,7 +147,7 @@ void draw_some_text(a1, const char *str, int a3, int a4, int a5)
drawStringY(hDC, 1, 1, str);
}
} else if ( (dh & 4) != 0 ) {
- SetTextColor(hDC, dw_4762e4);
+ SetTextColor(hDC, txt_colors[1]);
if (a5 == 3) {
drawStringY(hDC, 1, 0, str);
drawStringY(hDC, 1, 2, str);
@@ -129,7 +178,7 @@ void draw_some_text(a1, const char *str, int a3, int a4, int a5)
}
}
- SetTextColor(hDC, dw_4762e0);
+ SetTextColor(hDC, txt_colors[0]);
if ( ((uint8_t)gfa[0] & 4) != 0 ) {
edi = 1;
fmt_dim1.left = 1;
@@ -156,30 +205,30 @@ void draw_some_text(a1, const char *str, int a3, int a4, int a5)
desc.dwSize = 0x6c;
IDirectDrawSurface_Lock(pddrawsf3, NULL, &desc, 1, 0);
- fcn.0044f70c(desc.lpSurface, &fmt_dim2, &fmt_dim1);
- esi = fmt_dim1.right - fmt_dim1.left + 1;
- ebx = fmt_dim1.bottom - fmt_dim1.top + 1;
+ surface_bound(desc.lpSurface, &fmt_dim2, &fmt_dim1);
+ int width = fmt_dim1.right - fmt_dim1.left + 1;
+ int height = fmt_dim1.bottom - fmt_dim1.top + 1;
dw_4762f0 = desc.lpSurface;
eax = a5-1;
switch (eax) {
case 0:
- a3 -= esi;
+ a3 -= width;
break;
case 1:
case 2:
case 3:
- a3 -= esi / 2;
+ a3 -= width / 2;
/* fall through */
case 4:
- a4 -= ebx / 2;
+ a4 -= height / 2;
break;
case 5:
- a3 -= esi;
- a4 -= ebx / 2;
+ a3 -= width;
+ a4 -= height / 2;
break;
case 6:
- a3 -= esi / 2;
- a4 -= ebx;
+ a3 -= width / 2;
+ a4 -= height;
break;
default:
break;
@@ -187,17 +236,17 @@ void draw_some_text(a1, const char *str, int a3, int a4, int a5)
if ( ((uint8_t)gfa[0] & 8) != 0) {
if (!a1) {
- fcn.004564e6(sfdesc1.lpSurface, 0x4762e8, a3, a4, fmt_dim1.left, fmt_dim1.top, esi, ebx);
+ fcn_4564e6(sfdesc1.lpSurface, 0x4762e8, a3, a4, fmt_dim1.left, fmt_dim1.top, width, height);
} else {
- fcn.00456356(a1, 0x4762e8, a3, a4, fmt_dim1.left, fmt_dim1.top, esi, ebx);
+ fcn.00456356(a1, 0x4762e8, a3, a4, fmt_dim1.left, fmt_dim1.top, width, height);
}
} else {
if (!a1) {
- fcn.00456495(sfdesc1.lpSurface, 0x4762e8, a3, a4, fmt_dim1.left, fmt_dim1.top, esi, ebx);
+ fcn_456495(sfdesc1.lpSurface, 0x4762e8, a3, a4, fmt_dim1.left, fmt_dim1.top, width, height);
} else {
- fcn.00456328(a1, 0x4762e8, a3, a4, fmt_dim1.left, fmt_dim1.top, esi, ebx);
+ fcn.00456328(a1, 0x4762e8, a3, a4, fmt_dim1.left, fmt_dim1.top, width, height);
}
}
- fcn.004561be(0x4762e8, fmt_dim1.left, fmt_dim1.top, esi, ebx, 0);
+ fcn.004561be(0x4762e8, fmt_dim1.left, fmt_dim1.top, width, height, 0);
IDirectDrawSurface_Unlock(NULL);
}