1
0
mirror of https://github.com/DragonMinded/jubeatmenu.git synced 2024-11-24 06:40:13 +01:00

Add sliding animation when changing pages.

This commit is contained in:
Jennifer Taylor 2019-07-02 01:17:44 -07:00
parent e8d967723d
commit 42c8ae4b00
10 changed files with 863 additions and 682 deletions

66
JubeatMenu/Animation.cpp Normal file
View File

@ -0,0 +1,66 @@
#include <windows.h>
#include "Animation.h"
Animation::Animation()
{
distance = 0;
speed = 0.0;
lastMilliseconds = 0;
location = 0.0;
offset = 0;
isAnimating = false;
}
Animation::~Animation()
{
// Empty
}
void Animation::Animate(int animationOffset, int animationDistance, double pixelsPerSecond)
{
if (isAnimating) { return; }
distance = animationDistance;
location = 0.0;
offset = animationOffset;
speed = pixelsPerSecond / (1000.0);
isAnimating = true;
lastMilliseconds = CurrentMilliseconds();
}
bool Animation::IsAnimating()
{
return isAnimating;
}
int Animation::Position()
{
int position = (unsigned int)location;
if (distance < 0) { position = -position; }
return position + offset;
}
LONG Animation::CurrentMilliseconds()
{
SYSTEMTIME time;
GetSystemTime(&time);
return (time.wSecond * 1000) + time.wMilliseconds;
}
void Animation::Tick()
{
LONG currentMilliseconds = CurrentMilliseconds();
if (currentMilliseconds - lastMilliseconds > 0)
{
// Calculate how much we should have moved
location += speed * (double)(currentMilliseconds - lastMilliseconds);
if (location >= abs(distance))
{
location = abs(distance);
isAnimating = false;
}
// Remeber we moved
lastMilliseconds = currentMilliseconds;
}
}

22
JubeatMenu/Animation.h Normal file
View File

@ -0,0 +1,22 @@
#pragma once
class Animation
{
public:
Animation();
~Animation();
void Animate(int animationOffset, int animationDistance, double pixelsPerSecond);
bool IsAnimating();
void Tick();
int Position();
private:
LONG CurrentMilliseconds();
bool isAnimating;
int distance;
double location;
int offset;
double speed;
LONG lastMilliseconds;
};

View File

@ -2,6 +2,7 @@
#include <windows.h>
#include "Display.h"
#include "Animation.h"
static Menu *globalMenu;
static bool globalQuit;
@ -9,280 +10,315 @@ static unsigned int globalButtonsHeld;
static unsigned int globalSelected;
static unsigned int globalPage;
static unsigned int globalSeconds;
static Animation *globalAnimation;
static const unsigned int SELECTION_MAPPING[12] = {
0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11
0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11
};
static const unsigned int DRAW_MAPPING[15] = {
0, 3, 6, 9, 12, 1, 4, 7, 10, 13, 2, 5, 8, 11, 14
};
static const unsigned int HIGHLIGHT_MAPPING[15] = {
0, 1, 2, 3, 16, 4, 5, 6, 7, 16, 8, 9, 10, 11, 16
};
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
globalQuit = true;
return 0;
case WM_DESTROY:
PostQuitMessage(0);
globalQuit = true;
return 0;
case WM_QUIT:
globalQuit = true;
return 0;
case WM_PAINT:
/* Grab the maximum number of menu items */
unsigned int maxEntries = globalMenu->NumberOfEntries();
case WM_CLOSE:
DestroyWindow(hwnd);
globalQuit = true;
return 0;
case WM_DESTROY:
PostQuitMessage(0);
globalQuit = true;
return 0;
case WM_QUIT:
globalQuit = true;
return 0;
case WM_ERASEBKGND:
return 1;
case WM_PAINT:
/* Grab the maximum number of menu items */
unsigned int maxEntries = globalMenu->NumberOfEntries();
/* Start patinting */
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
/* Set up double buffer */
PAINTSTRUCT ps;
HDC windowHdc = BeginPaint(hwnd, &ps);
HDC hdc = CreateCompatibleDC(windowHdc);
HBITMAP Membitmap = CreateCompatibleBitmap(windowHdc, SCREEN_WIDTH, SCREEN_HEIGHT);
SelectObject(hdc, Membitmap);
/* Paint the window background */
HBRUSH background = CreateSolidBrush(RGB(0,0,0));
FillRect(hdc, &ps.rcPaint, background);
DeleteObject(background);
/* Paint the window background */
HBRUSH background = CreateSolidBrush(RGB(0,0,0));
FillRect(hdc, &ps.rcPaint, background);
DeleteObject(background);
/* Set up text display */
SetTextColor(hdc, RGB(240, 240, 240));
SetBkMode(hdc, TRANSPARENT);
HFONT hItemFont = CreateFont(ITEM_FONT_SIZE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, L"Verdana");
HFONT hInstructionsFont = CreateFont(INSTRUCTIONS_FONT_SIZE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, L"Verdana");
HFONT hArrowFont = CreateFont(ARROW_FONT_SIZE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, L"Verdana");
/* Set up text display */
SetTextColor(hdc, RGB(240, 240, 240));
SetBkMode(hdc, TRANSPARENT);
HFONT hItemFont = CreateFont(ITEM_FONT_SIZE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, L"Verdana");
HFONT hInstructionsFont = CreateFont(INSTRUCTIONS_FONT_SIZE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, L"Verdana");
HFONT hArrowFont = CreateFont(ARROW_FONT_SIZE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, L"Verdana");
/* Draw top instructions */
{
RECT rect;
rect.top = VIEWPORT_TOP + TEXT_PADDING;
rect.bottom = VIEWPORT_BOTTOM - TEXT_PADDING;
rect.left = TEXT_PADDING;
rect.right = SCREEN_WIDTH - TEXT_PADDING;
/* Set up rectangle display */
HPEN redPen = CreatePen(PS_SOLID, 2, RGB(255,0,0));
HPEN whitePen = CreatePen(PS_SOLID, 2, RGB(255,255,255));
char instruction_text[1024];
sprintf_s(
instruction_text,
1024,
"Select a game by tapping its panel.\n"
"Start %s by tapping the Start Game panel.\n"
"The selected game will auto-start in %d seconds.",
globalMenu->GetEntryName(globalSelected),
globalSeconds
);
/* Draw top instructions */
{
RECT rect;
rect.top = VIEWPORT_TOP + TEXT_PADDING;
rect.bottom = VIEWPORT_BOTTOM - TEXT_PADDING;
rect.left = TEXT_PADDING;
rect.right = SCREEN_WIDTH - TEXT_PADDING;
wchar_t* wString = new wchar_t[4096];
MultiByteToWideChar(CP_ACP, 0, instruction_text, -1, wString, 4096);
SelectObject(hdc, hInstructionsFont);
DrawText(hdc, wString, -1, &rect, DT_HIDEPREFIX | DT_LEFT | DT_TOP | DT_WORDBREAK);
delete wString;
}
char instruction_text[1024];
sprintf_s(
instruction_text,
1024,
"Select a game by tapping its panel.\n"
"Start %s by tapping the Start Game panel.\n"
"The selected game will auto-start in %d seconds.",
globalMenu->GetEntryName(globalSelected),
globalSeconds
);
/* Draw hover icons for every square, regardless of whether we put graphics in them */
for( unsigned int position = 0; position < 15; position++ )
{
unsigned int xPos = position % 4;
unsigned int yPos = position / 4;
wchar_t* wString = new wchar_t[4096];
MultiByteToWideChar(CP_ACP, 0, instruction_text, -1, wString, 4096);
SelectObject(hdc, hInstructionsFont);
DrawText(hdc, wString, -1, &rect, DT_HIDEPREFIX | DT_LEFT | DT_TOP | DT_WORDBREAK);
delete wString;
}
/* There is an extra pixel of bump for the second half of the squares */
unsigned int xBump = xPos >= 2 ? 1 : 0;
unsigned int yBump = yPos >= 2 ? 1 : 0;
/* Draw hover icons for every square, regardless of whether we put graphics in them */
{
/* Set up background colors */
SelectObject(hdc, GetStockObject(DC_BRUSH));
SetDCBrushColor(hdc, RGB(0,0,0));
unsigned int top = BUTTON_TOP + (BUTTON_VERTICAL_STRIDE * yPos) + yBump;
unsigned int bottom = top + BUTTON_WIDTH;
unsigned int left = BUTTON_LEFT + (BUTTON_HORIZONTAL_STRIDE * xPos) + xBump;
unsigned int right = left + BUTTON_HEIGHT;
/* Set up background colors */
SelectObject(hdc, GetStockObject(DC_BRUSH));
SetDCBrushColor(hdc, RGB(0,0,0));
/* Set up border color to show current held buttons */
SelectObject(hdc, redPen);
// Set up border color to show current held buttons
SelectObject(hdc, GetStockObject(DC_PEN));
if ((globalButtonsHeld >> position) & 1)
{
SetDCPenColor(hdc, RGB(255,0,0));
}
else
{
continue;
}
// Draw bounding rectangle
Rectangle(hdc, left, top, right, bottom);
}
/* Intentionally skip button 16 because pressing it will always
insta-launch the selected game, so we will never need to show
a hover square. */
for( unsigned int position = 0; position < 15; position++ )
{
if (!((globalButtonsHeld >> position) & 1))
{
// This button isn't being held, no need to show a held box.
continue;
}
if (globalAnimation->IsAnimating() && position < 12)
{
// Don't show hover while moving selection panels.
continue;
}
/* Draw selection button */
{
unsigned int top = BUTTON_TOP + (BUTTON_VERTICAL_STRIDE * 3) + 1;
unsigned int bottom = top + BUTTON_WIDTH;
unsigned int left = BUTTON_LEFT + (BUTTON_HORIZONTAL_STRIDE * 3) + 1;
unsigned int right = left + BUTTON_HEIGHT;
unsigned int xPos = position % 4;
unsigned int yPos = position / 4;
SelectObject(hdc, GetStockObject(DC_BRUSH));
SetDCBrushColor(hdc, RGB(24,24,24));
SetDCPenColor(hdc, RGB(255,255,255));
Rectangle(hdc, left, top, right, bottom);
RECT rect;
rect.top = top + TEXT_PADDING;
rect.bottom = bottom - TEXT_PADDING;
rect.left = left + TEXT_PADDING;
rect.right = right - TEXT_PADDING;
/* There is an extra pixel of bump for the second half of the squares */
unsigned int xBump = xPos >= 2 ? 1 : 0;
unsigned int yBump = yPos >= 2 ? 1 : 0;
char start_text[64];
sprintf_s(start_text, 64, "Start Game\n\n%d seconds left", globalSeconds);
unsigned int top = BUTTON_TOP + (BUTTON_VERTICAL_STRIDE * yPos) + yBump;
unsigned int bottom = top + BUTTON_WIDTH;
unsigned int left = BUTTON_LEFT + (BUTTON_HORIZONTAL_STRIDE * xPos) + xBump;
unsigned int right = left + BUTTON_HEIGHT;
wchar_t* wString = new wchar_t[4096];
MultiByteToWideChar(CP_ACP, 0, start_text, -1, wString, 4096);
SelectObject(hdc, hItemFont);
DrawText(hdc, wString, -1, &rect, DT_HIDEPREFIX | DT_CENTER | DT_TOP);
delete wString;
}
// Draw bounding rectangle
Rectangle(hdc, left, top, right, bottom);
}
}
/* Draw previous/next page buttons */
if (maxEntries > GAMES_PER_PAGE)
{
unsigned int max_pages = ((maxEntries - GAMES_PER_PAGE) + 2) / 3;
/* Scroll left button */
if (globalPage < max_pages)
{
unsigned int top = BUTTON_TOP + (BUTTON_VERTICAL_STRIDE * 3) + 1;
unsigned int bottom = top + BUTTON_WIDTH;
unsigned int left = BUTTON_LEFT + (BUTTON_HORIZONTAL_STRIDE * 0) + 1;
unsigned int right = left + BUTTON_HEIGHT;
/* Draw selection button */
{
unsigned int top = BUTTON_TOP + (BUTTON_VERTICAL_STRIDE * 3) + 1;
unsigned int bottom = top + BUTTON_WIDTH;
unsigned int left = BUTTON_LEFT + (BUTTON_HORIZONTAL_STRIDE * 3) + 1;
unsigned int right = left + BUTTON_HEIGHT;
SelectObject(hdc, GetStockObject(DC_BRUSH));
SetDCBrushColor(hdc, RGB(24,24,24));
if ((globalButtonsHeld >> 12) & 1)
{
SetDCPenColor(hdc, RGB(255,0,0));
}
else
{
SetDCPenColor(hdc, RGB(255,255,255));
}
SelectObject(hdc, GetStockObject(DC_BRUSH));
SetDCBrushColor(hdc, RGB(24,24,24));
SelectObject(hdc, whitePen);
Rectangle(hdc, left, top, right, bottom);
// Draw bounding rectangle
Rectangle(hdc, left, top, right, bottom);
// Draw text
RECT rect;
rect.top = top + TEXT_PADDING;
rect.bottom = bottom - TEXT_PADDING;
rect.left = left + TEXT_PADDING;
rect.right = right - TEXT_PADDING;
RECT rect;
rect.top = top + TEXT_PADDING;
rect.bottom = bottom - TEXT_PADDING;
rect.left = left + TEXT_PADDING;
rect.right = right - TEXT_PADDING;
wchar_t* wString = new wchar_t[4096];
MultiByteToWideChar(CP_ACP, 0, "<<", -1, wString, 4096);
SelectObject(hdc, hArrowFont);
DrawText(hdc, wString, -1, &rect, DT_HIDEPREFIX | DT_CENTER | DT_VCENTER | DT_SINGLELINE);
delete wString;
}
char start_text[64];
sprintf_s(start_text, 64, "Start Game\n\n%d seconds left", globalSeconds);
/* Scroll right button */
if (globalPage > 0)
{
unsigned int top = BUTTON_TOP + (BUTTON_VERTICAL_STRIDE * 3) + 1;
unsigned int bottom = top + BUTTON_WIDTH;
unsigned int left = BUTTON_LEFT + (BUTTON_HORIZONTAL_STRIDE * 1) + 1;
unsigned int right = left + BUTTON_HEIGHT;
wchar_t* wString = new wchar_t[4096];
MultiByteToWideChar(CP_ACP, 0, start_text, -1, wString, 4096);
SelectObject(hdc, hItemFont);
DrawText(hdc, wString, -1, &rect, DT_HIDEPREFIX | DT_CENTER | DT_TOP);
delete wString;
}
SelectObject(hdc, GetStockObject(DC_BRUSH));
SetDCBrushColor(hdc, RGB(24,24,24));
if ((globalButtonsHeld >> 13) & 1)
{
SetDCPenColor(hdc, RGB(255,0,0));
}
else
{
SetDCPenColor(hdc, RGB(255,255,255));
}
/* Draw previous/next page buttons */
if (maxEntries > GAMES_PER_PAGE)
{
unsigned int max_pages = ((maxEntries - GAMES_PER_PAGE) + 2) / 3;
// Draw bounding rectangle
Rectangle(hdc, left, top, right, bottom);
// Draw text
RECT rect;
rect.top = top + TEXT_PADDING;
rect.bottom = bottom - TEXT_PADDING;
rect.left = left + TEXT_PADDING;
rect.right = right - TEXT_PADDING;
SelectObject(hdc, GetStockObject(DC_BRUSH));
SetDCBrushColor(hdc, RGB(24,24,24));
wchar_t* wString = new wchar_t[4096];
MultiByteToWideChar(CP_ACP, 0, ">>", -1, wString, 4096);
SelectObject(hdc, hArrowFont);
DrawText(hdc, wString, -1, &rect, DT_HIDEPREFIX | DT_CENTER | DT_VCENTER | DT_SINGLELINE);
delete wString;
}
}
/* Draw each menu item */
for( unsigned int position = 0; position < 12; position++ ) {
unsigned int xPos = position % 4;
unsigned int yPos = position / 4;
/* Scroll left button */
if (globalPage < max_pages)
{
unsigned int top = BUTTON_TOP + (BUTTON_VERTICAL_STRIDE * 3) + 1;
unsigned int bottom = top + BUTTON_WIDTH;
unsigned int left = BUTTON_LEFT + (BUTTON_HORIZONTAL_STRIDE * 0) + 1;
unsigned int right = left + BUTTON_HEIGHT;
/* Look up the actual item at this position */
unsigned int item = SELECTION_MAPPING[position] + (globalPage * 3);
if (item >= maxEntries) { continue; }
if ((globalButtonsHeld >> 12) & 1)
{
SelectObject(hdc, redPen);
}
else
{
SelectObject(hdc, whitePen);
}
/* There is an extra pixel of bump for the second half of the squares */
unsigned int xBump = xPos >= 2 ? 1 : 0;
unsigned int yBump = yPos >= 2 ? 1 : 0;
// Draw bounding rectangle
Rectangle(hdc, left, top, right, bottom);
unsigned int top = BUTTON_TOP + (BUTTON_VERTICAL_STRIDE * yPos) + yBump;
unsigned int bottom = top + BUTTON_WIDTH;
unsigned int left = BUTTON_LEFT + (BUTTON_HORIZONTAL_STRIDE * xPos) + xBump;
unsigned int right = left + BUTTON_HEIGHT;
/* Set up background colors */
SelectObject(hdc, GetStockObject(DC_BRUSH));
if (globalSelected == item)
{
SetDCBrushColor(hdc, RGB(96,96,96));
}
else
{
SetDCBrushColor(hdc, RGB(24,24,24));
}
// Draw text
RECT rect;
rect.top = top + TEXT_PADDING;
rect.bottom = bottom - TEXT_PADDING;
rect.left = left + TEXT_PADDING;
rect.right = right - TEXT_PADDING;
// Set up border color to show current held buttons
SelectObject(hdc, GetStockObject(DC_PEN));
if ((globalButtonsHeld >> position) & 1)
{
SetDCPenColor(hdc, RGB(255,0,0));
}
else
{
SetDCPenColor(hdc, RGB(255,255,255));
}
// Draw bounding rectangle
Rectangle(hdc, left, top, right, bottom);
wchar_t* wString = new wchar_t[4096];
MultiByteToWideChar(CP_ACP, 0, "<<", -1, wString, 4096);
SelectObject(hdc, hArrowFont);
DrawText(hdc, wString, -1, &rect, DT_HIDEPREFIX | DT_CENTER | DT_VCENTER | DT_SINGLELINE);
delete wString;
}
// Set text color
SelectObject(hdc, GetStockObject(DC_PEN));
SetDCPenColor(hdc, RGB(255,255,255));
/* Scroll right button */
if (globalPage > 0)
{
unsigned int top = BUTTON_TOP + (BUTTON_VERTICAL_STRIDE * 3) + 1;
unsigned int bottom = top + BUTTON_WIDTH;
unsigned int left = BUTTON_LEFT + (BUTTON_HORIZONTAL_STRIDE * 1) + 1;
unsigned int right = left + BUTTON_HEIGHT;
// Draw text
RECT rect;
rect.top = top + TEXT_PADDING;
rect.bottom = bottom - TEXT_PADDING;
rect.left = left + TEXT_PADDING;
rect.right = right - TEXT_PADDING;
if ((globalButtonsHeld >> 13) & 1)
{
SelectObject(hdc, redPen);
}
else
{
SelectObject(hdc, whitePen);
}
wchar_t* wString = new wchar_t[4096];
MultiByteToWideChar(CP_ACP, 0, globalMenu->GetEntryName(item), -1, wString, 4096);
SelectObject(hdc, hItemFont);
DrawText(hdc, wString, -1, &rect, DT_HIDEPREFIX | DT_CENTER | DT_TOP | DT_WORDBREAK);
delete wString;
}
// Draw bounding rectangle
Rectangle(hdc, left, top, right, bottom);
DeleteObject(hItemFont);
DeleteObject(hInstructionsFont);
DeleteObject(hArrowFont);
EndPaint(hwnd, &ps);
return 0;
}
// Draw text
RECT rect;
rect.top = top + TEXT_PADDING;
rect.bottom = bottom - TEXT_PADDING;
rect.left = left + TEXT_PADDING;
rect.right = right - TEXT_PADDING;
wchar_t* wString = new wchar_t[4096];
MultiByteToWideChar(CP_ACP, 0, ">>", -1, wString, 4096);
SelectObject(hdc, hArrowFont);
DrawText(hdc, wString, -1, &rect, DT_HIDEPREFIX | DT_CENTER | DT_VCENTER | DT_SINGLELINE);
delete wString;
}
}
/* Draw each menu item */
for( unsigned int position = 0; position < 15; position++ )
{
/* Leave room for animating left/right swipe */
unsigned int xPos = position % 5;
unsigned int yPos = position / 5;
/* Look up the actual item at this position */
unsigned int item = DRAW_MAPPING[position] + (globalPage * 3);
if (item >= maxEntries) { continue; }
/* There is an extra pixel of bump for the second half of the squares */
unsigned int xBump = xPos >= 2 ? 1 : 0;
unsigned int yBump = yPos >= 2 ? 1 : 0;
/* Adjust position for animations */
int animationBump = 0;
if (globalAnimation->IsAnimating())
{
animationBump = globalAnimation->Position();
}
int top = BUTTON_TOP + (BUTTON_VERTICAL_STRIDE * yPos) + yBump;
int bottom = top + BUTTON_WIDTH;
int left = BUTTON_LEFT + (BUTTON_HORIZONTAL_STRIDE * xPos) + xBump + animationBump;
int right = left + BUTTON_HEIGHT;
/* Set up background colors */
SelectObject(hdc, GetStockObject(DC_BRUSH));
if (globalSelected == item)
{
SetDCBrushColor(hdc, RGB(96,96,96));
}
else
{
SetDCBrushColor(hdc, RGB(24,24,24));
}
// Set up border color to show current held buttons
if (!globalAnimation->IsAnimating() && ((globalButtonsHeld >> HIGHLIGHT_MAPPING[position]) & 1))
{
SelectObject(hdc, redPen);
}
else
{
SelectObject(hdc, whitePen);
}
// Draw bounding rectangle
Rectangle(hdc, left, top, right, bottom);
// Draw text
RECT rect;
rect.top = top + TEXT_PADDING;
rect.bottom = bottom - TEXT_PADDING;
rect.left = left + TEXT_PADDING;
rect.right = right - TEXT_PADDING;
wchar_t* wString = new wchar_t[4096];
MultiByteToWideChar(CP_ACP, 0, globalMenu->GetEntryName(item), -1, wString, 4096);
SelectObject(hdc, hItemFont);
DrawText(hdc, wString, -1, &rect, DT_HIDEPREFIX | DT_CENTER | DT_TOP | DT_WORDBREAK);
delete wString;
}
DeleteObject(hItemFont);
DeleteObject(hInstructionsFont);
DeleteObject(hArrowFont);
/* Copy double-buffer over */
BitBlt(windowHdc, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, hdc, 0, 0, SRCCOPY);
DeleteObject(Membitmap);
DeleteDC(hdc);
DeleteDC(windowHdc);
EndPaint(hwnd, &ps);
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
@ -290,138 +326,183 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Display::Display(HINSTANCE hInstance, IO *ioInst, Menu *mInst)
{
inst = hInstance;
globalMenu = mInst;
io = ioInst;
menu = mInst;
page = 0;
selected = 0;
globalAnimation = new Animation();
inst = hInstance;
globalMenu = mInst;
io = ioInst;
menu = mInst;
page = 0;
selected = 0;
newPage = -1;
lastLocation = 0;
// Register the callback
// Register the callback
WNDCLASS wc = { };
wc.lpfnWndProc = WindowProc;
wc.hInstance = inst;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
globalQuit = false;
globalButtonsHeld = 0;
globalSelected = selected;
globalPage = page;
globalSeconds = menu->SecondsLeft();
globalQuit = false;
globalButtonsHeld = 0;
globalSelected = selected;
globalPage = page;
globalSeconds = menu->SecondsLeft();
// Create an empty window
hwnd = CreateWindow(CLASS_NAME, 0, WS_BORDER, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, inst, NULL);
LONG lStyle = GetWindowLong(hwnd, GWL_STYLE);
lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU);
SetWindowLong(hwnd, GWL_STYLE, lStyle);
LONG lExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
lExStyle &= ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE);
SetWindowLong(hwnd, GWL_EXSTYLE, lExStyle);
// Create an empty window
hwnd = CreateWindow(CLASS_NAME, 0, WS_BORDER, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, inst, NULL);
LONG lStyle = GetWindowLong(hwnd, GWL_STYLE);
lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU);
SetWindowLong(hwnd, GWL_STYLE, lStyle);
LONG lExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
lExStyle &= ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE);
SetWindowLong(hwnd, GWL_EXSTYLE, lExStyle);
/* Display it */
SetWindowPos(hwnd, NULL, 0,0,0,0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
ShowWindow(hwnd, SW_SHOW);
/* Display it */
SetWindowPos(hwnd, NULL, 0,0,0,0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
ShowCursor(false);
ShowCursor(false);
}
Display::~Display(void)
Display::~Display()
{
ShowCursor(true);
DestroyWindow(hwnd);
UnregisterClass(CLASS_NAME, inst);
ShowCursor(true);
DestroyWindow(hwnd);
UnregisterClass(CLASS_NAME, inst);
delete globalAnimation;
}
void Display::Tick(void)
{
/* Handle windows message pump */
/* Handle windows message pump */
MSG msg = { };
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
/* Grab the currently held buttons, calculate newly pressed */
bool moved = false;
unsigned int buttonsHeld = io->ButtonsHeld();
/* Don't handle input while animating */
unsigned int buttonsHeld = io->ButtonsHeld();
globalAnimation->Tick();
if (globalAnimation->IsAnimating())
{
bool update = false;
/* Figure out actions */
if (menu->NumberOfEntries() > GAMES_PER_PAGE)
{
unsigned int max_pages = ((menu->NumberOfEntries() - GAMES_PER_PAGE) + 2) / 3;
if (globalButtonsHeld != buttonsHeld)
{
globalButtonsHeld = buttonsHeld;
update = true;
}
/* Activate page left/right buttons */
if (io->ButtonPressed(BUTTON_13))
{
/* Scroll left */
if (page < max_pages)
{
page++;
moved = true;
}
}
if (lastLocation != globalAnimation->Position())
{
lastLocation = globalAnimation->Position();
update = true;
}
if (io->ButtonPressed(BUTTON_14))
{
/* Scroll right */
if (page > 0)
{
page--;
moved = true;
}
}
}
if (update)
{
InvalidateRect(hwnd, NULL, FALSE);
UpdateWindow(hwnd);
}
return;
}
if (!moved) {
/* Allow button presses to make selections */
for (unsigned int btn = 0; btn < 12; btn++) {
if (io->ButtonPressed(1 << btn)) {
unsigned int item = SELECTION_MAPPING[btn] + (globalPage * 3);
if (item < menu->NumberOfEntries())
{
selected = item;
}
}
}
}
/* See if we need to update the page after finishing animation */
if (newPage >= 0)
{
page = newPage;
globalPage = page;
newPage = -1;
globalButtonsHeld = buttonsHeld;
InvalidateRect(hwnd, NULL, FALSE);
UpdateWindow(hwnd);
return;
}
/* Update the screen to show any button presses or selection
changes. */
bool update = false;
if (globalButtonsHeld != buttonsHeld)
{
globalButtonsHeld = buttonsHeld;
update = true;
}
if (globalSelected != selected)
{
globalSelected = selected;
update = true;
}
if (globalPage != page)
{
globalPage = page;
update = true;
}
if (globalSeconds != menu->SecondsLeft()) {
globalSeconds = menu->SecondsLeft();
update = true;
}
/* Grab the currently held buttons, calculate newly pressed */
bool moved = false;
if (update)
{
InvalidateRect(hwnd, NULL, NULL);
UpdateWindow(hwnd);
}
/* Figure out actions */
if (menu->NumberOfEntries() > GAMES_PER_PAGE)
{
unsigned int max_pages = ((menu->NumberOfEntries() - GAMES_PER_PAGE) + 2) / 3;
/* Activate page left/right buttons */
if (io->ButtonPressed(BUTTON_13))
{
/* Scroll left */
if (page < max_pages)
{
globalAnimation->Animate(0, -BUTTON_HORIZONTAL_STRIDE, ANIMATION_SPEED);
lastLocation = globalAnimation->Position();
newPage = page + 1;
moved = true;
}
} else if (io->ButtonPressed(BUTTON_14))
{
/* Scroll right */
if (page > 0)
{
globalAnimation->Animate(-BUTTON_HORIZONTAL_STRIDE, BUTTON_HORIZONTAL_STRIDE, ANIMATION_SPEED);
lastLocation = globalAnimation->Position();
page--;
moved = true;
}
}
}
if (!moved)
{
/* Allow button presses to make selections */
for (unsigned int btn = 0; btn < 12; btn++) {
if (io->ButtonPressed(1 << btn)) {
unsigned int item = SELECTION_MAPPING[btn] + (globalPage * 3);
if (item < menu->NumberOfEntries())
{
selected = item;
}
}
}
}
/* Update the screen to show any button presses or selection
changes. */
bool update = false;
if (globalButtonsHeld != buttonsHeld)
{
globalButtonsHeld = buttonsHeld;
update = true;
}
if (globalSelected != selected)
{
globalSelected = selected;
update = true;
}
if (globalPage != page)
{
globalPage = page;
update = true;
}
if (globalSeconds != menu->SecondsLeft()) {
globalSeconds = menu->SecondsLeft();
update = true;
}
if (update)
{
InvalidateRect(hwnd, NULL, FALSE);
UpdateWindow(hwnd);
}
}
bool Display::WasClosed()
{
return globalQuit;
return globalQuit;
}
unsigned int Display::GetSelectedItem()
{
return selected;
return selected;
}

View File

@ -27,30 +27,34 @@
#define TEXT_PADDING 10
#define ANIMATION_SPEED 1000
/* Number of games to display on one screen */
#define GAMES_PER_PAGE 12
class Display
{
public:
Display(HINSTANCE hInstance, IO *ioInst, Menu *mInst);
~Display(void);
public:
Display(HINSTANCE hInstance, IO *ioInst, Menu *mInst);
~Display();
void Tick();
bool WasClosed();
void Tick();
bool WasClosed();
void ButtonPress(int button);
void ButtonRelease(int button);
void ButtonPress(int button);
void ButtonRelease(int button);
unsigned int GetSelectedItem();
unsigned int GetSelectedItem();
private:
HINSTANCE inst;
HWND hwnd;
private:
HINSTANCE inst;
HWND hwnd;
Menu *menu;
IO *io;
Menu *menu;
IO *io;
unsigned int page;
unsigned int selected;
int newPage;
unsigned int page;
unsigned int selected;
int lastLocation;
};

View File

@ -2,147 +2,147 @@
IO::IO()
{
/* Start with not being ready */
is_ready = false;
/* Start with not being ready */
is_ready = false;
/* Load the log function so we can output debugging */
log_function = NULL;
core = GetModuleHandleA("avs2-core.dll");
if (core != NULL) {
log_function = (log_func)GetProcAddress(core, "XCgsqzn000017c");
} else {
core = GetModuleHandleA("libavs-win32.dll");
if (core != NULL) {
log_function = (log_func)GetProcAddress(core, "XCd229cc000018");
}
}
/* Load the log function so we can output debugging */
log_function = NULL;
core = GetModuleHandleA("avs2-core.dll");
if (core != NULL) {
log_function = (log_func)GetProcAddress(core, "XCgsqzn000017c");
} else {
core = GetModuleHandleA("libavs-win32.dll");
if (core != NULL) {
log_function = (log_func)GetProcAddress(core, "XCd229cc000018");
}
}
debug("Initializing device.dll");
debug("Initializing device.dll");
device = GetModuleHandleA("device.dll");
device = GetModuleHandleA("device.dll");
if (device == NULL) {
debug("Missing device.dll. Did you run this from the right directory?");
return;
}
if (device == NULL) {
debug("Missing device.dll. Did you run this from the right directory?");
return;
}
device_initialize = (INT_RET_ONE_ARG) GetProcAddress(device, "device_initialize");
device_is_initialized = (INT_RET_NO_ARGS) GetProcAddress(device, "device_is_initialized");
device_get_status = (INT_RET_NO_ARGS) GetProcAddress(device, "device_get_status");
device_set_panel_mode = (INT_RET_ONE_ARG) GetProcAddress(device, "device_set_panel_mode");
device_get_panel_trg_on = (INT_RET_THREE_ARGS) GetProcAddress(device, "device_get_panel_trg_on");
device_get_panel_trg_off = (INT_RET_THREE_ARGS) GetProcAddress(device, "device_get_panel_trg_off");
device_get_panel_trg_short_on = (INT_RET_THREE_ARGS) GetProcAddress(device, "device_get_panel_trg_short_on");
device_update = (INT_RET_NO_ARGS) GetProcAddress(device, "device_update");
device_finalize = (INT_RET_NO_ARGS) GetProcAddress(device, "device_finalize");
device_initialize = (INT_RET_ONE_ARG) GetProcAddress(device, "device_initialize");
device_is_initialized = (INT_RET_NO_ARGS) GetProcAddress(device, "device_is_initialized");
device_get_status = (INT_RET_NO_ARGS) GetProcAddress(device, "device_get_status");
device_set_panel_mode = (INT_RET_ONE_ARG) GetProcAddress(device, "device_set_panel_mode");
device_get_panel_trg_on = (INT_RET_THREE_ARGS) GetProcAddress(device, "device_get_panel_trg_on");
device_get_panel_trg_off = (INT_RET_THREE_ARGS) GetProcAddress(device, "device_get_panel_trg_off");
device_get_panel_trg_short_on = (INT_RET_THREE_ARGS) GetProcAddress(device, "device_get_panel_trg_short_on");
device_update = (INT_RET_NO_ARGS) GetProcAddress(device, "device_update");
device_finalize = (INT_RET_NO_ARGS) GetProcAddress(device, "device_finalize");
if (
device_initialize == NULL ||
device_is_initialized == NULL ||
device_get_status == NULL ||
device_set_panel_mode == NULL ||
device_update == NULL ||
device_get_panel_trg_on == NULL ||
device_get_panel_trg_off == NULL ||
device_get_panel_trg_short_on == NULL ||
device_finalize == NULL
) {
debug("Couldn't find correct functions to call! Did you use the right DLLs?");
FreeLibrary(device);
return;
}
if (
device_initialize == NULL ||
device_is_initialized == NULL ||
device_get_status == NULL ||
device_set_panel_mode == NULL ||
device_update == NULL ||
device_get_panel_trg_on == NULL ||
device_get_panel_trg_off == NULL ||
device_get_panel_trg_short_on == NULL ||
device_finalize == NULL
) {
debug("Couldn't find correct functions to call! Did you use the right DLLs?");
FreeLibrary(device);
return;
}
// First, initialize and verify.
debug("Initializing P4IO device");
device_initialize(0);
if (!device_is_initialized()) {
debug("Couldn't initialize P4IO device");
FreeLibrary(device);
return;
}
if (device_get_status() < 0) {
debug("P4IO device status returns error!");
FreeLibrary(device);
return;
}
// First, initialize and verify.
debug("Initializing P4IO device");
device_initialize(0);
// Configure to read panels
debug("Configuring P4IO driver");
device_set_panel_mode(0);
if (!device_is_initialized()) {
debug("Couldn't initialize P4IO device");
FreeLibrary(device);
return;
}
// We're ready to roll
debug("P4IO driver ready for input");
is_ready = true;
buttons = 0;
lastButtons = 0;
if (device_get_status() < 0) {
debug("P4IO device status returns error!");
FreeLibrary(device);
return;
}
// Configure to read panels
debug("Configuring P4IO driver");
device_set_panel_mode(0);
// We're ready to roll
debug("P4IO driver ready for input");
is_ready = true;
buttons = 0;
lastButtons = 0;
}
IO::~IO(void)
IO::~IO()
{
if (!is_ready) { return; }
if (!is_ready) { return; }
debug("Finalizing P4IO driver");
device_finalize();
FreeLibrary(device);
debug("Finalizing P4IO driver");
device_finalize();
FreeLibrary(device);
}
bool IO::Ready()
{
return is_ready;
return is_ready;
}
void IO::ErrorMessage(char *msg)
{
debug(msg);
debug(msg);
}
void IO::Tick()
{
if (!is_ready) { return; }
if (!is_ready) { return; }
if(device_is_initialized()) {
device_update();
}
if(device_is_initialized()) {
device_update();
}
// Remember last buttons so we can calculate newly
// pressed buttons.
lastButtons = buttons;
// Remember last buttons so we can calculate newly
// pressed buttons.
lastButtons = buttons;
for (int panel = 0; panel < 16; panel++) {
int output[2] = { 0 };
for (int panel = 0; panel < 16; panel++) {
int output[2] = { 0 };
device_get_panel_trg_on(panel % 4, panel / 4, output);
if (output[0] != 0) {
// Track the button release
buttons &= ~(1 << panel);
}
device_get_panel_trg_off(panel % 4, panel / 4, output);
if (output[0] != 0) {
// Track the button press
buttons |= (1 << panel);
}
}
device_get_panel_trg_on(panel % 4, panel / 4, output);
if (output[0] != 0) {
// Track the button release
buttons &= ~(1 << panel);
}
device_get_panel_trg_off(panel % 4, panel / 4, output);
if (output[0] != 0) {
// Track the button press
buttons |= (1 << panel);
}
}
}
unsigned int IO::ButtonsHeld()
{
return buttons;
return buttons;
}
bool IO::ButtonHeld(unsigned int button)
{
return (ButtonsHeld() & button) != 0;
return (ButtonsHeld() & button) != 0;
}
unsigned int IO::ButtonsPressed()
{
return buttons & (~lastButtons);
return buttons & (~lastButtons);
}
bool IO::ButtonPressed(unsigned int button)
{
return (ButtonsPressed() & button) != 0;
return (ButtonsPressed() & button) != 0;
}

View File

@ -34,34 +34,34 @@ typedef int(*INT_RET_THREE_ARGS)(int x, int y, int *out);
class IO
{
public:
IO();
~IO(void);
public:
IO();
~IO();
bool Ready();
void Tick();
void ErrorMessage(char *msg);
unsigned int ButtonsHeld();
unsigned int ButtonsPressed();
bool ButtonHeld(unsigned int button);
bool ButtonPressed(unsigned int button);
private:
HMODULE core;
HMODULE device;
bool Ready();
void Tick();
void ErrorMessage(char *msg);
unsigned int ButtonsHeld();
unsigned int ButtonsPressed();
bool ButtonHeld(unsigned int button);
bool ButtonPressed(unsigned int button);
private:
HMODULE core;
HMODULE device;
INT_RET_ONE_ARG device_initialize;
INT_RET_NO_ARGS device_is_initialized;
INT_RET_NO_ARGS device_get_status;
INT_RET_ONE_ARG device_set_panel_mode;
INT_RET_THREE_ARGS device_get_panel_trg_on;
INT_RET_THREE_ARGS device_get_panel_trg_off;
INT_RET_THREE_ARGS device_get_panel_trg_short_on;
INT_RET_NO_ARGS device_update;
INT_RET_NO_ARGS device_finalize;
INT_RET_ONE_ARG device_initialize;
INT_RET_NO_ARGS device_is_initialized;
INT_RET_NO_ARGS device_get_status;
INT_RET_ONE_ARG device_set_panel_mode;
INT_RET_THREE_ARGS device_get_panel_trg_on;
INT_RET_THREE_ARGS device_get_panel_trg_off;
INT_RET_THREE_ARGS device_get_panel_trg_short_on;
INT_RET_NO_ARGS device_update;
INT_RET_NO_ARGS device_finalize;
log_func log_function;
log_func log_function;
bool is_ready;
unsigned int buttons;
unsigned int lastButtons;
bool is_ready;
unsigned int buttons;
unsigned int lastButtons;
};

View File

@ -12,105 +12,105 @@ static Menu *globalMenu = NULL;
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
{
/* Remember our own instance*/
globalModule = hModule;
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
{
/* Remember our own instance*/
globalModule = hModule;
/* Load the original DLL to force dependencies to load.
This must be done BEFORE calling dll_entry_init or
this menu can't be run with a hook DLL. */
LoadLibraryA("jubeat.dll");
/* Initialize the menu before any hooks run so our
file operations don't get intercepted. */
globalMenu = new Menu(L"games.ini");
}
/* Load the original DLL to force dependencies to load.
This must be done BEFORE calling dll_entry_init or
this menu can't be run with a hook DLL. */
LoadLibraryA("jubeat.dll");
return TRUE;
/* Initialize the menu before any hooks run so our
file operations don't get intercepted. */
globalMenu = new Menu(L"games.ini");
}
return TRUE;
}
extern "C" __declspec(dllexport) int __cdecl dll_entry_init(int a1, int a2)
{
// Initialize the IO
IO *io = new IO();
if (!io->Ready())
{
// Failed to initialize, give up
ExitProcess(0);
return 0;
}
// Initialize the IO
IO *io = new IO();
if (!io->Ready())
{
// Failed to initialize, give up
ExitProcess(0);
return 0;
}
// Initialize the menu
Menu *menu = globalMenu;
if( menu->NumberOfEntries() < 1 )
{
io->ErrorMessage("No games configured to launch in games.ini!");
// Initialize the menu
Menu *menu = globalMenu;
if( menu->NumberOfEntries() < 1 )
{
io->ErrorMessage("No games configured to launch in games.ini!");
delete menu;
delete io;
delete menu;
delete io;
ExitProcess(0);
return 0;
}
ExitProcess(0);
return 0;
}
// Create menu screen
Display *display = new Display(globalModule, io, menu);
// Create menu screen
Display *display = new Display(globalModule, io, menu);
/* Actual game to load */
char *path = NULL;
/* It may have taken a long time to init */
menu->ResetTimeout();
/* Actual game to load */
char *path = NULL;
// Input loop
while(true) {
io->Tick();
menu->Tick();
display->Tick();
/* See if somebody killed the display window */
if (display->WasClosed())
{
io->ErrorMessage("Main window closed, exiting!");
break;
}
/* It may have taken a long time to init */
menu->ResetTimeout();
/* Check to see if we ran out of time waiting for input */
if (menu->ShouldBootDefault())
{
io->ErrorMessage("Ran out of time, booting current selection!");
int entry = display->GetSelectedItem();
path = menu->GetEntryPath(entry);
break;
}
// Input loop
while(true) {
io->Tick();
menu->Tick();
display->Tick();
/* Check to see if the user confirmed a selection */
if (io->ButtonPressed(BUTTON_16)) {
int entry = display->GetSelectedItem();
path = menu->GetEntryPath(entry);
break;
}
}
/* See if somebody killed the display window */
if (display->WasClosed())
{
io->ErrorMessage("Main window closed, exiting!");
break;
}
// Close and free libraries
delete display;
delete menu;
delete io;
/* Check to see if we ran out of time waiting for input */
if (menu->ShouldBootDefault())
{
io->ErrorMessage("Ran out of time, booting current selection!");
int entry = display->GetSelectedItem();
path = menu->GetEntryPath(entry);
break;
}
if (path != NULL)
{
/* Launch actual game */
system(path);
}
/* Check to see if the user confirmed a selection */
if (io->ButtonPressed(BUTTON_16)) {
int entry = display->GetSelectedItem();
path = menu->GetEntryPath(entry);
break;
}
}
// Return failure so launcher.exe doesn't attempt to
// further initialize other threads such as the net thread.
ExitProcess(0);
return 0;
// Close and free libraries
delete display;
delete menu;
delete io;
if (path != NULL)
{
/* Launch actual game */
system(path);
}
// Return failure so launcher.exe doesn't attempt to
// further initialize other threads such as the net thread.
ExitProcess(0);
return 0;
}
extern "C" __declspec(dllexport) int __cdecl dll_entry_main()
{
return 0;
return 0;
}

View File

@ -170,6 +170,10 @@
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\Animation.cpp"
>
</File>
<File
RelativePath=".\Display.cpp"
>
@ -192,6 +196,10 @@
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\Animation.h"
>
</File>
<File
RelativePath=".\Display.h"
>

View File

@ -5,151 +5,151 @@
Menu::Menu(_TCHAR *inifile)
{
/* Read settings */
settings = LoadSettings( inifile, &num_programs );
/* Read settings */
settings = LoadSettings( inifile, &num_programs );
/* For exiting on defaults */
ftime(&beginning);
/* For exiting on defaults */
ftime(&beginning);
}
Menu::~Menu(void)
Menu::~Menu()
{
}
void Menu::ResetTimeout()
{
ftime(&beginning);
ftime(&beginning);
}
void Menu::Tick()
{
ftime(&current);
ftime(&current);
}
bool Menu::ShouldBootDefault()
{
ftime(&current);
return (current.time - beginning.time) > TIMEOUT_SECONDS;
ftime(&current);
return (current.time - beginning.time) > TIMEOUT_SECONDS;
}
unsigned int Menu::SecondsLeft()
{
ftime(&current);
int seconds = (int)(TIMEOUT_SECONDS - (current.time - beginning.time));
return seconds >= 0 ? seconds : 0;
ftime(&current);
int seconds = (int)(TIMEOUT_SECONDS - (current.time - beginning.time));
return seconds >= 0 ? seconds : 0;
}
/**
* Loads an INI file with the following format:
*
* [Name of game to launch]
* launch=<location of batch/executable>
*/
* Loads an INI file with the following format:
*
* [Name of game to launch]
* launch=<location of batch/executable>
*/
launcher_program_t *Menu::LoadSettings( _TCHAR *ini_file, unsigned int *final_length )
{
launcher_program_t *progs = 0;
*final_length = 0;
unsigned int got_name = 0;
launcher_program_t temp;
launcher_program_t *progs = 0;
*final_length = 0;
unsigned int got_name = 0;
launcher_program_t temp;
// Open the file
HANDLE hFile = CreateFile(ini_file, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
char buffer[16384];
unsigned int eof = 0;
unsigned int eol = 0;
unsigned int buflen = 0;
// Open the file
HANDLE hFile = CreateFile(ini_file, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
char buffer[16384];
unsigned int eof = 0;
unsigned int eol = 0;
unsigned int buflen = 0;
if (hFile == 0)
{
return progs;
}
if (hFile == 0)
{
return progs;
}
memset( &temp, 0, sizeof(temp) );
memset( buffer, 0, sizeof(buffer) );
memset( &temp, 0, sizeof(temp) );
memset( buffer, 0, sizeof(buffer) );
while( !eof )
{
DWORD length;
ReadFile( hFile, buffer + buflen, 1, &length, 0 );
if (length == 0)
{
eof = 1;
eol = 1;
}
else if( *(buffer + buflen) == '\r' )
{
/* Ignore \r completely */
*(buffer + buflen) = 0;
}
else if( *(buffer + buflen) == '\n' )
{
/* End of line */
*(buffer + buflen) = 0;
eol = 1;
}
else
{
/* Valid thing */
buflen++;
}
while( !eof )
{
DWORD length;
ReadFile( hFile, buffer + buflen, 1, &length, 0 );
if (length == 0)
{
eof = 1;
eol = 1;
}
else if( *(buffer + buflen) == '\r' )
{
/* Ignore \r completely */
*(buffer + buflen) = 0;
}
else if( *(buffer + buflen) == '\n' )
{
/* End of line */
*(buffer + buflen) = 0;
eol = 1;
}
else
{
/* Valid thing */
buflen++;
}
if ( eol == 1 )
{
/* Process line */
if (buffer[0] == '[' && buffer[buflen - 1] == ']' && buflen > 2)
{
buffer[buflen - 1] = 0;
char *game = buffer + 1;
if ( eol == 1 )
{
/* Process line */
if (buffer[0] == '[' && buffer[buflen - 1] == ']' && buflen > 2)
{
buffer[buflen - 1] = 0;
char *game = buffer + 1;
/* Copy this into temp structure */
strcpy_s( temp.name, MAX_GAME_NAME_LENGTH, game );
got_name = 1;
}
else
{
if (strncmp(buffer, "launch", 6) == 0) {
unsigned int loc = 6;
// Find equals sign after space
while (loc < buflen && (buffer[loc] == ' ' || buffer[loc] == '\t')) { loc++; }
if (loc < buflen)
{
if (buffer[loc] == '=')
{
loc++;
while (loc < buflen && (buffer[loc] == ' ' || buffer[loc] == '\t')) { loc++; }
if (loc < buflen)
{
char *launch = buffer + loc;
/* Copy this into temp structure */
strcpy_s( temp.name, MAX_GAME_NAME_LENGTH, game );
got_name = 1;
}
else
{
if (strncmp(buffer, "launch", 6) == 0) {
unsigned int loc = 6;
// Find equals sign after space
while (loc < buflen && (buffer[loc] == ' ' || buffer[loc] == '\t')) { loc++; }
if (loc < buflen)
{
if (buffer[loc] == '=')
{
loc++;
while (loc < buflen && (buffer[loc] == ' ' || buffer[loc] == '\t')) { loc++; }
if (loc < buflen)
{
char *launch = buffer + loc;
if( got_name == 1 )
{
/* We have a name to associate with this */
strcpy_s( temp.location, MAX_GAME_LOCATION_LENGTH, launch );
got_name = 0;
if( got_name == 1 )
{
/* We have a name to associate with this */
strcpy_s( temp.location, MAX_GAME_LOCATION_LENGTH, launch );
got_name = 0;
/* Make a new spot for this, copy in */
(*final_length)++;
progs = (launcher_program_t *)realloc( progs, sizeof(launcher_program_t) * (*final_length) );
memcpy( progs + ((*final_length) - 1), &temp, sizeof(launcher_program_t) );
memset( &temp, 0, sizeof(temp) );
}
}
}
}
}
}
/* Make a new spot for this, copy in */
(*final_length)++;
progs = (launcher_program_t *)realloc( progs, sizeof(launcher_program_t) * (*final_length) );
memcpy( progs + ((*final_length) - 1), &temp, sizeof(launcher_program_t) );
memset( &temp, 0, sizeof(temp) );
}
}
}
}
}
}
/* Reset buffer */
if (buflen > 0)
{
memset( buffer, 0, sizeof(buffer) );
buflen = 0;
}
/* Reset buffer */
if (buflen > 0)
{
memset( buffer, 0, sizeof(buffer) );
buflen = 0;
}
/* Not end of line anymore */
eol = 0;
}
}
/* Not end of line anymore */
eol = 0;
}
}
return progs;
return progs;
}

View File

@ -12,29 +12,29 @@
typedef struct
{
char location[MAX_GAME_LOCATION_LENGTH + 1];
char name[MAX_GAME_NAME_LENGTH + 1];
char location[MAX_GAME_LOCATION_LENGTH + 1];
char name[MAX_GAME_NAME_LENGTH + 1];
} launcher_program_t;
class Menu
{
public:
Menu(_TCHAR *inifile);
~Menu(void);
public:
Menu(_TCHAR *inifile);
~Menu();
unsigned int NumberOfEntries() { return num_programs; }
char *GetEntryName(unsigned int game) { return settings[game].name; }
char *GetEntryPath(unsigned int game) { return settings[game].location; }
unsigned int NumberOfEntries() { return num_programs; }
char *GetEntryName(unsigned int game) { return settings[game].name; }
char *GetEntryPath(unsigned int game) { return settings[game].location; }
void Tick();
void ResetTimeout();
bool ShouldBootDefault();
unsigned int SecondsLeft();
private:
unsigned int num_programs;
launcher_program_t *settings;
struct timeb beginning;
struct timeb current;
void Tick();
void ResetTimeout();
bool ShouldBootDefault();
unsigned int SecondsLeft();
private:
unsigned int num_programs;
launcher_program_t *settings;
struct timeb beginning;
struct timeb current;
launcher_program_t *LoadSettings( _TCHAR *ini_file, unsigned int *final_length );
launcher_program_t *LoadSettings( _TCHAR *ini_file, unsigned int *final_length );
};