void HelloWorldInit()
{
	// Fill background blue
        s3eSurfaceClear(0, 0, 255);
		int scale;
		if (s3eSurfaceGetInt(S3E_SURFACE_WIDTH) < 320 || s3eSurfaceGetInt(S3E_SURFACE_HEIGHT) < 320)
        scale = 1;
		else if (s3eSurfaceGetInt(S3E_SURFACE_WIDTH) < 480 || s3eSurfaceGetInt(S3E_SURFACE_HEIGHT) < 480)
        scale = 2;
		else
        scale = 3;
		s3eDebugSetInt(S3E_DEBUG_FONT_SCALE, scale);
		s3eSurfaceRegister(S3E_SURFACE_SCREENSIZE, HelloWorldRotationCallBack, NULL);
}
void LevelSelectMainInit()
{
    // Determine if the device has a keyboard
    if (s3eKeyboardGetInt(S3E_KEYBOARD_HAS_KEYPAD) || s3eKeyboardGetInt(S3E_KEYBOARD_HAS_ALPHA))
        g_DeviceHasKeyboard = true;

    int scale = 1;
    // Set default button size relative to screen resolution
    if (s3eSurfaceGetInt(S3E_SURFACE_WIDTH) < 320 || s3eSurfaceGetInt(S3E_SURFACE_HEIGHT) < 320)
        scale = 1;
    else if (s3eSurfaceGetInt(S3E_SURFACE_WIDTH) < 480 || s3eSurfaceGetInt(S3E_SURFACE_HEIGHT) < 480)
        scale = 2;
    else
        scale = 3;

    SetButtonScale(scale);

    // Scale font up to be easier to read
    int fontScale = scale > 1 ? scale-1 : 1;
    s3eDebugSetInt(S3E_DEBUG_FONT_SCALE, fontScale);
    LevelInit();
}
Example #3
0
void ButtonsRender()
{
    int previousDebugTextSize = s3eDebugGetInt(S3E_DEBUG_FONT_SCALE);
    int fontScale = g_ButtonScale;
    char buf[128];

    // select double sized text
    if (previousDebugTextSize != (int)g_ButtonScale)
        s3eDebugSetInt(S3E_DEBUG_FONT_SCALE, g_ButtonScale);

    // find out the dimensions of the font
    const int textWidthDefault = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_WIDTH);
    const int textHeight = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_HEIGHT);

    // get the current pointer position and selection state
    int pointerX = s3ePointerGetX();
    int pointerY = s3ePointerGetY();
    s3ePointerState pointerState = s3ePointerGetState(S3E_POINTER_BUTTON_SELECT);

    int x = 10;
    int y = 50;
    
    g_SelectedButton = 0;

    // draw the buttons
    for (Button* iter = g_ButtonsHead; iter; iter = iter->m_Next)
    {
        if (!iter->m_Display)
            continue;

        if (g_HideDisabledButtons && !iter->m_Enabled)
            continue;

        fontScale = g_ButtonScale;
        int textWidth = textWidthDefault;
        if (s3eDebugGetInt(S3E_DEBUG_FONT_SCALE) != fontScale)
            s3eDebugSetInt(S3E_DEBUG_FONT_SCALE, fontScale);

        if (iter->m_Key != S3E_KEY_INVALID)
        {
            if (s3eKeyboardGetState(iter->m_Key) & S3E_KEY_STATE_PRESSED)
            {
                g_SelectedButton = iter;
                s3eDebugTracePrintf("button selected using key");
            }
        }

        if (iter->m_Key != S3E_KEY_INVALID)
        {
            char keyName[32];
            s3eKeyboardGetDisplayName(keyName, iter->m_Key);
            if (iter->m_Enabled)
                snprintf(buf, sizeof(buf), "`x000000%s: %s", keyName, iter->m_Name);
            else
                snprintf(buf, sizeof(buf), "`xa0a0a0%s: %s", keyName, iter->m_Name);
        }
        else
        {
            if (iter->m_Enabled)
                snprintf(buf, sizeof(buf), "`x000000%s", iter->m_Name);
            else
                snprintf(buf, sizeof(buf), "`xa0a0a0%s", iter->m_Name);
        }

        int len = strlen(buf) - 8;
        int _x0 = x - 2;
        int _y0 = y - 4;
        int _h = textHeight + 4;
        int _y1 = _y0 + _h;
        int _w;
        int _x1;
        int textOffset = 0;
        
        // Scale down font size if button contents are too long for screen
        while (true)
        {
            _w = (textWidth * len) + 8;
            
            _x1 = _x0 + _w;

            if (fontScale == 1 || _x1 <= s3eSurfaceGetInt(S3E_SURFACE_WIDTH))
                break;

            fontScale -= 1;
            s3eDebugSetInt(S3E_DEBUG_FONT_SCALE, fontScale);
            textWidth = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_WIDTH);
            textOffset += (textHeight-s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_HEIGHT))/2;
        }

        if (pointerX >= _x0 && pointerX <= _x1 &&
            pointerY >= _y0 && pointerY <= _y1 && iter->m_Enabled)
        {
            if (pointerState & S3E_POINTER_STATE_DOWN)
                DrawRect(_x0, _y0, _w, _h, 0, 255, 0);
            else
                DrawRect(_x0, _y0, _w, _h, 255, 0, 0);

            if (pointerState & S3E_POINTER_STATE_RELEASED)
                g_SelectedButton = iter;
        }
        else
        {
            if (iter->m_Enabled)
                DrawRect(_x0, _y0, _w, _h, 255, 0, 0);
            else
                DrawRect(_x0, _y0, _w, _h, 127, 0, 0);
        }

        s3eDebugPrint(x, y+textOffset,  buf, 0);

        // Store button's position and size
        iter->m_XPos = _x0;
        iter->m_YPos = _y0;
        iter->m_Width = _w;
        iter->m_Height = _h;

        y = y + textHeight * 2;
    }

    if (g_SelectedButton && g_SelectedButton->m_Callback)
        g_SelectedButton->m_Callback(g_SelectedButton);

    if (previousDebugTextSize != fontScale)
        s3eDebugSetInt(S3E_DEBUG_FONT_SCALE, previousDebugTextSize);

    g_YBelowButtons = y;
}