マウスがホバーされると文字色を変える、というのをやりたいです。
個人的には頑張ったのですがどこが悪いのでしょうか?
#include "../DxLib/DxLib.h"
#define SCREEN_WIDTH (1366)
#define SCREEN_HEIGHT (768)
#define SCREEN_COLOR_BIT (32)
int menuNum;
int nowSelect;
int mouseX, mouseY;
unsigned int Write, Black, Red, Green, Yellow, Blue;
int textWidth;
void isFullScreen();
void Load();
enum {
TITLE
}scene = TITLE;
typedef struct {
int x, y;
unsigned int color;
char name[32];
}MENU;
MENU menu[4] {
{1000, 400, Write, "Game Start"},
{1000 - 50 * 1, 400 + 80 * 1, Write, "Operation Method"},
{1000 - 50 * 2, 400 + 80 * 2, Write, "Option"},
{1000 - 50 * 3, 400 + 80 * 3, Write, "Game Finish"}
};
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
isFullScreen();
SetDrawScreen(DX_SCREEN_BACK);
SetMainWindowText("東方静天地");
SetMouseDispFlag(TRUE);
if (DxLib_Init() == -1) return -1;
ChangeFontType(DX_FONTTYPE_ANTIALIASING_EDGE_8X8);
SetFontSize(50);
Load();
while(ProcessMessage() == 0 && CheckHitKey(KEY_INPUT_ESCAPE) == 0)
{
ClearDrawScreen();
GetMousePoint(&mouseX, &mouseY);
// 問題の部分
for (int i = 0; i < menuNum; i++) {
DrawFormatString(menu[i].x, menu[i].y, menu[i].color, menu[i].name); // メニュー項目を表示
textWidth = GetDrawFormatStringWidth(menu[nowSelect].name); // 選択されているテキストの幅を取得
if (menu[i].x >= mouseX && menu[i].x + textWidth <= mouseX && // 当たり判定?
menu[i].y >= mouseY && menu[i].y + 50 <= mouseY) {
nowSelect = i; // 条件を満たしていればその数をnowSelectに代入
menu[nowSelect].color = Red; // 色変更
} else { // それ以外は
menu[i].color = Write; // 白
}
}
ScreenFlip();
}
DxLib_End();
return 0;
}
void isFullScreen() {
int result = MessageBox(
NULL,
"フルスクリーンで表示しますか?",
"スクリーンの設定",
MB_YESNO
);
if (result == IDYES) {
SetGraphMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_COLOR_BIT);
ChangeWindowMode(FALSE);
} else if (result = IDNO) {
SetGraphMode(SCREEN_WIDTH, SCREEN_HEIGHT - 20, SCREEN_COLOR_BIT);
SetWindowInitPosition(-8, 0);
ChangeWindowMode(TRUE);
}
}
void Load() {
menuNum = 4;
nowSelect = 0;
Write = GetColor(255, 255, 255);
Black = GetColor( 0, 0, 0);
Red = GetColor(255, 0, 0);
}