Esempio n. 1
0
//-----------------------------------------------------------------------------
void HexMapTest::Render()
{
//	if (mouse_mode == MOUSE_MODE_CHECKING) 
	{
//		int32 px = IwGxGetScreenWidth() - s3ePointerGetX();
//		int32 py = IwGxGetScreenHeight() - s3ePointerGetY();
		int32 closestX = -1, closestY = -1;

		CIwVec3 vect = getWorldCoords(s3ePointerGetX(), s3ePointerGetY());
//		hexGrid->findClosestArray(origin, dir, closestX, closestY);
		//WORKING!!!
		hexGrid->findClosestSimple(vect.x, vect.y, closestX, closestY);
		DebugPrint(closestX, closestY);
	}
//		s_PickSurface->MakeCurrent();
    // Clear the screen
    IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F);
	// Set the model matrix
    IwGxSetModelMatrix(&s_ModelMatrix);
	hexGrid->render();


    // End drawing
    IwGxFlush();

	IwGxPrintSetScale(2);
	IwGxPrintFrameRate(0, 0); 
	// Swap buffers
	IwGxSwapBuffers();
}
static void CursorRender()
{
    if (!s3ePointerGetInt(S3E_POINTER_AVAILABLE))
        return;

    uint16* ptr = (uint16*)s3eSurfacePtr();
    int height = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT);
    int width = s3eSurfaceGetInt(S3E_SURFACE_WIDTH);
    int pitch = s3eSurfaceGetInt(S3E_SURFACE_PITCH);

    int pointerx = s3ePointerGetX();
    int pointery = s3ePointerGetY();

    pointerx = (pointerx > width)?width-1:pointerx;
    pointery = (pointery > height)?height-1:pointery;

    int cursor_size = 10;

    for (int y = pointery-cursor_size; y < pointery+cursor_size; y++)
    {
        if (y < 0 || y >= height)
            continue;
        int location = y*pitch/sizeof(uint16) + pointerx;
        ptr[location] = 0x5555;
    }

    for (int x = pointerx-cursor_size; x < pointerx+cursor_size; x++)
    {
        if (x < 0 || x >= width)
            continue;
        int location = pointery*pitch/sizeof(uint16) + x;
        ptr[location] = 0x5555;
    }
}
Esempio n. 3
0
void ImGui_Marmalade_NewFrame()
{
    if (!g_FontTexture)
        ImGui_Marmalade_CreateDeviceObjects();

    ImGuiIO& io = ImGui::GetIO();

    // Setup display size (every frame to accommodate for window resizing)
    int w = IwGxGetScreenWidth(), h = IwGxGetScreenHeight();
    io.DisplaySize = ImVec2((float)w, (float)h);
     // For retina display or other situations where window coordinates are different from framebuffer coordinates. User storage only, presently not used by ImGui.
    io.DisplayFramebufferScale = g_scale;

    // Setup time step
    double current_time = s3eTimerGetUST() / 1000.0f;
    io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f);
    g_Time = current_time;

    double mouse_x, mouse_y;
    mouse_x = s3ePointerGetX();
    mouse_y = s3ePointerGetY();
    io.MousePos = ImVec2((float)mouse_x/g_scale.x, (float)mouse_y/g_scale.y);   // Mouse position in screen coordinates (set to -1,-1 if no mouse / on another screen, etc.)

    for (int i = 0; i < 3; i++)
    {
        io.MouseDown[i] = g_MousePressed[i] || s3ePointerGetState((s3ePointerButton)i) != S3E_POINTER_STATE_UP;    // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
        g_MousePressed[i] = false;
    }

    io.MouseWheel = g_MouseWheel;
    g_MouseWheel = 0.0f;

    // TODO: Hide OS mouse cursor if ImGui is drawing it
    // s3ePointerSetInt(S3E_POINTER_HIDE_CURSOR,(io.MouseDrawCursor ? 0 : 1));

    // Start the frame
    ImGui::NewFrame();

     // Show/hide OSD keyboard
    if (io.WantTextInput)
    {
        // Some text input widget is active?
        if (!g_osdKeyboardEnabled)
        {
            g_osdKeyboardEnabled = true;
            s3eKeyboardSetInt(S3E_KEYBOARD_GET_CHAR, 1);    // show OSD keyboard
        }
    }
    else
    {
        // No text input widget is active
        if (g_osdKeyboardEnabled)
        {
            g_osdKeyboardEnabled = false;
            s3eKeyboardSetInt(S3E_KEYBOARD_GET_CHAR, 0);    // hide OSD keyboard
        }
    }
}
static void SoftkeyRender(const char* text, s3eDeviceSoftKeyPosition pos, void(*handler)())
{
    // TODO: Hardocoded font width and height (boo!)
    int width = 7;
    int height = 30;

    width *= strlen(text) * 2;
    int x = 0;
    int y = 0;
    switch (pos)
    {
        case S3E_DEVICE_SOFTKEY_BOTTOM_LEFT:
            y = IwGxGetScreenHeight() - height;
            x = 0;
            break;
        case S3E_DEVICE_SOFTKEY_BOTTOM_RIGHT:
            y = IwGxGetScreenHeight() - height;
            x = IwGxGetScreenWidth() - width;
            break;
        case S3E_DEVICE_SOFTKEY_TOP_RIGHT:
            y = 0;
            x = IwGxGetScreenWidth() - width;
            break;
        case S3E_DEVICE_SOFTKEY_TOP_LEFT:
            x = 0;
            y = 0;
            break;
    }

    CIwMaterial *fadeMat = IW_GX_ALLOC_MATERIAL();
    fadeMat->SetAlphaMode(CIwMaterial::SUB);
    IwGxSetMaterial(fadeMat);

    IwGxPrintString(x + 10, y+10, text, false);

    CIwColour* cols = IW_GX_ALLOC(CIwColour, 4);
    memset(cols, 50, sizeof(CIwColour)*4);

    if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED)
    {
        int pointerx = s3ePointerGetX();
        int pointery = s3ePointerGetY();
        if (pointerx >= x && pointerx <= x+width && pointery >=y && pointery <= y+height)
        {
            memset(cols, 15, sizeof(CIwColour)*4);
            handler();
        }
    }

    // Draw button area
    CIwSVec2 XY(x, y-2), dXY(width, height);
    IwGxDrawRectScreenSpace(&XY, &dXY, cols);
}
Esempio n. 5
0
void CGame::Update()
{
    // game logic goes here

    // for example, move a red square towards any touch event...
    if( s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN )
    {
        CIwFVec2 target((float)s3ePointerGetX(), (float)s3ePointerGetY());

        m_Position += (target - m_Position) * 0.05f;
    }
}
Esempio n. 6
0
PointerEventType UpdatePointer()
{
	PointerEventType res = petNone;
	s3ePointerUpdate();
	if (g_pointerdown)
	{
		if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN)
		{
			int32 x = s3ePointerGetX();
			int32 y = s3ePointerGetY();
			if (x != g_pointerx || y != g_pointery)
			{
				res = petMove;
				g_pointerx = x;
				g_pointery = y;
			}
		}
		else
		{
			g_pointerdown = false;
			res = petUp;
		}
	}
	else
	{
		if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN)
		{
			g_pointerx = s3ePointerGetX();
			g_pointery = s3ePointerGetY();
			g_pointerdown = true;
			res = petDown;
		}
	}

	return res;
}
static void SoftkeyRender(const char* text, s3eDeviceSoftKeyPosition pos, void(*handler)())
{
    // Get area of text displayed
    int width = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_WIDTH);
    int height = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_HEIGHT);
    width *= strlen(text) - 8; //-8 to ignore colour flag (e.g. "`x666666")

    // Expand area by half text height to make easier to click
    width += height;
    height += height;

    int x = 0;
    int y = 0;
    switch (pos)
    {
        case S3E_DEVICE_SOFTKEY_BOTTOM_LEFT:
            y = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT) - height;
            x = 0;
            break;
        case S3E_DEVICE_SOFTKEY_BOTTOM_RIGHT:
            y = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT) - height;
            x = s3eSurfaceGetInt(S3E_SURFACE_WIDTH) - width;
            break;
        case S3E_DEVICE_SOFTKEY_TOP_RIGHT:
            y = 0;
            x = s3eSurfaceGetInt(S3E_SURFACE_WIDTH) - width;
            break;
        case S3E_DEVICE_SOFTKEY_TOP_LEFT:
            x = 0;
            y = 0;
            break;
    }
    s3eDebugPrint(x + (height/4), y + (height/4), text, 0); // place in centre of touchable area
    if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED)
    {
        int pointerx = s3ePointerGetX();
        int pointery = s3ePointerGetY();
        if (pointerx >= x && pointerx <= x+width && pointery >=y && pointery <= y+height)
            handler();
    }
}
Esempio n. 8
0
int main()
{
	GameInit();
	DrawMap();
	
//	DrawMap();
    while(!s3eDeviceCheckQuitRequest())
    {
		s3ePointerUpdate();
		s3eKeyboardUpdate();
		if(s3ePointerGetState(S3E_POINTER_BUTTON_SELECT))
		{
			Go(s3ePointerGetX(),s3ePointerGetY());
		}
        // S3E applications should yield frequently
        s3eDeviceYield();
    }


    return 0;
}
void CursorRender()
{
    if (!s3ePointerGetInt(S3E_POINTER_AVAILABLE))
        return;

    if (!g_CursorMaterial)
    {
        g_CursorMaterial = new CIwMaterial();
        g_CursorMaterial->SetColAmbient(0, 0, 255, 255);
    }

    IwGxSetMaterial(g_CursorMaterial);
    int pointerx = s3ePointerGetX();
    int pointery = s3ePointerGetY();

    int cursor_size = 10;
    CIwSVec2 wh(cursor_size*2, 1);
    CIwSVec2 wh2(1, cursor_size*2);
    CIwSVec2 pos = CIwSVec2((int16)pointerx-cursor_size, (int16)pointery);
    CIwSVec2 pos2 = CIwSVec2((int16)pointerx, (int16)pointery-cursor_size);
    IwGxDrawRectScreenSpace(&pos, &wh);
    IwGxDrawRectScreenSpace(&pos2, &wh2);
}
Esempio n. 10
0
static void RenderSoftkey(const char* text, s3eDeviceSoftKeyPosition pos, void(*handler)())
{
    int width = 7;
    int height = 10;
    width *= strlen(text);
    int x = 0;
    int y = 0;
    switch (pos)
    {
        case S3E_DEVICE_SOFTKEY_BOTTOM_LEFT:
            y = Iw2DGetSurfaceHeight() - height;
            x = 0;
            break;
        case S3E_DEVICE_SOFTKEY_BOTTOM_RIGHT:
            y = Iw2DGetSurfaceHeight() - height;
            x = Iw2DGetSurfaceWidth() - width;
            break;
        case S3E_DEVICE_SOFTKEY_TOP_RIGHT:
            y = 0;
            x = Iw2DGetSurfaceWidth() - width;
            break;
        case S3E_DEVICE_SOFTKEY_TOP_LEFT:
            x = 0;
            y = 0;
            break;
    }
    char buffer[256] = "`x808080";
    strcat(buffer, text);
    s3eDebugPrint(x, y, buffer, false);
    if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED)
    {
        int pointerx = s3ePointerGetX();
        int pointery = s3ePointerGetY();
        if (pointerx >= x && pointerx <= x+width && pointery >=y && pointery <= y+height)
            handler();
    }
}
Esempio n. 11
0
int Input::getPointerY() const
{
	return s3ePointerGetY();
}
void createButton(char* p_btnName)
{
	// Draw button area
	int fontWidth = s3eDebugGetInt(S3E_DEBUG_FONT_WIDTH);
	int x,y,width;
	if(p_btnName != NULL && strlen(p_btnName) > 1)
		width = strlen(p_btnName)*fontWidth+10;
	int height = 40;
	//x = IwGxGetScreenWidth() - width;
	x = s3eSurfaceGetInt(S3E_SURFACE_WIDTH) - width;
	y = 2;
	 if (!(s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_UP))
    {
        int pointerx = s3ePointerGetX();
        int pointery = s3ePointerGetY();
		if (pointerx >=x && pointerx <= x+width && pointery >=y && pointery <= y+height)
        {
            if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN)
            {
                keyPressedState = S3E_KEY_STATE_DOWN;
            }
            if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED)
            {
                keyPressedState = S3E_KEY_STATE_PRESSED;
            }
			if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_RELEASED)
            {
                keyPressedState = S3E_KEY_STATE_RELEASED;
				s3eDebugTraceLine("-------------Example Update Key Released-------------------");
            }
        }
    }

	if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_RELEASED)
	{
		char color[64] = "`xe0ff00"; 
		char* dispText = strcat(color,p_btnName);
		s3eDebugPrint(x+5, 20,  dispText, 0);
	}

	 if (s3ePointerGetInt(S3E_POINTER_AVAILABLE))
    {
        if (keyPressedState == S3E_KEY_STATE_DOWN)
		{
			char color[64] = "`xe0ff00"; 
			char* dispText = strcat(color,p_btnName);
			s3eDebugPrint(x+5, 20,  dispText, 0);
		}
		else if(keyPressedState == S3E_KEY_STATE_PRESSED)
		{
			DrawButtonRect(x, y, width, height,97,97,249);
			char color[64] = "`xe0ff00"; 
			char* dispText = strcat(color,p_btnName);
			s3eDebugPrint(x+5, 20,  dispText, 0);
		}
		else if(keyPressedState == S3E_KEY_STATE_RELEASED)
		{
			s3eSurfaceClear(0,0,0);
			char color[64] = "`xe0ff00"; 
			char* dispText = strcat(color,p_btnName);
			s3eDebugPrint(x+5, 20,  dispText, 0);
		}
		else
		{
			char color[64] = "`xD8F809";
			char* dispText = strcat(color,p_btnName);
			s3eDebugPrint(x+5, 20,  dispText, 0);
		}
    }
}
void GameplayState::HandleEvent(StateEngine* state)
{
	m_Moving = false;
	if ( (s3eKeyboardGetState(s3eKeySpace) & S3E_POINTER_STATE_DOWN) && m_SpacePressed == false)
	{
		if (m_CharacterIndex == MANDY)
		{
			characters[MANDY]->Jump();
		}
		m_SpacePressed = true;
	}

	if( (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN))
    {
		m_ClickLocation = (CIwFVec2((s3ePointerGetX() - (float)m_Cam->GetPosition().x) , (s3ePointerGetY() - (float)m_Cam->GetPosition().y )));
		for (int i = 0; i < 3; i++)
		{
			// Check collision with the character portraits
			if (m_Portraits[i]->isColliding(CIwFVec2((float)s3ePointerGetX(), (float)s3ePointerGetY())))
			{
				if (m_CharacterIndex != i)
				{
					m_Cam->SetPosition(CIwSVec2(static_cast<int16>(-characters[i]->GetPosition().x + (screenWidth /2)), static_cast<int16>(-characters[i]->GetPosition().y + (screenHeight - characters[i]->GetHeight()))));
					m_CharacterIndex = i; // Set the character to be the element that was collided against
					m_PortraitSounds[i]->Play();
				}
			}
		}

		if (n_guiButtons[0]->isColliding((CIwFVec2((float)s3ePointerGetX(), (float)s3ePointerGetY()))))
		{
			if (characters[m_CharacterIndex]->GetDirection() == FACING_RIGHT)
				characters[m_CharacterIndex]->SetDirection(FACING_LEFT);
			m_Moving = true;

			characters[m_CharacterIndex]->MoveBy(CIwFVec2((-5 * state->m_deltaTime) - characters[m_CharacterIndex]->GetMovSpeed().x, 0),state->m_deltaTime);
			CheckCollisions(m_CharacterIndex);
		}

		if (n_guiButtons[1]->isColliding((CIwFVec2((float)s3ePointerGetX(), (float)s3ePointerGetY()))))
		{
			if (characters[m_CharacterIndex]->GetDirection() == FACING_LEFT)
				characters[m_CharacterIndex]->SetDirection(FACING_RIGHT);
			m_Moving = true;

			characters[m_CharacterIndex]->MoveBy(CIwFVec2((5 * state->m_deltaTime) + characters[m_CharacterIndex]->GetMovSpeed().x, 0),state->m_deltaTime);
			CheckCollisions(m_CharacterIndex);
		}

		if (characters[DAVE]->isColliding(characters[NIGEL]->GetPosition()) && (m_canThrow == false) && m_CharacterIndex == DAVE)
		{
			if (characters[NIGEL]->isColliding((CIwFVec2(s3ePointerGetX() - (float)m_Cam->GetPosition().x , s3ePointerGetY() - (float)m_Cam->GetPosition().y ))))
			{
				while (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN)
				{
					// Continue to poll input
					s3ePointerUpdate();
					s3eKeyboardUpdate();
					m_canThrow = true;
					m_throwingTarget->SetPosition((CIwFVec2((s3ePointerGetX() - (float)m_Cam->GetPosition().x)  - ( m_throwingTarget->GetWidth() /2) , (s3ePointerGetY() - (float)m_Cam->GetPosition().y ) - (m_throwingTarget->GetHeight() /2))));
					m_throwingTarget->UpdateCollider();
					
					// Draw the current state or else we'll be in a loop that will show no updated frame
					state->Draw();
					m_ThrowingSound->ResetCounter();
				}

				m_isThrowing = true;
				m_ThrowingSound->Play();
				m_CharacterIndex = NIGEL;
			}
		}

		m_MouseClicked = true;
	}

	if (m_isThrowing)
	{
		characters[NIGEL]->UpdateCollider();
		if (m_canThrow)
		{
			if (!characters[NIGEL]->isColliding(m_throwingTarget, CIwFVec2(m_throwingTarget->GetWidth() /2, -(m_throwingTarget->GetHeight() / 2))) && m_ThrowingTargetSide == 0 && m_Moving == false)
			{
				m_ThrowingNigelSound->Play();
				characters[NIGEL]->LerpTo(CIwFVec2(m_throwingTarget->GetPosition().x, m_throwingTarget->GetPosition().y), 0.05f);
			}

			else
			{
				m_canThrow = false;
				m_ThrowingNigelSound->ResetCounter();
			}
		}
		else
		{
			m_isThrowing = false;
			characters[NIGEL]->MoveBy(CIwFVec2(m_ThrowingTargetSide * 2,2),state->m_deltaTime);
		}
	}

	if (m_gameOver)
	{
		state->ChangeState(GameoverState::Instance());
	}
}
Esempio n. 14
0
extern "C" void RenderCursorskeys()
{
    int height = 20;
    int width = 45;

    int lefty = IwGxGetScreenHeight() - (height * 2);
    int leftx = (IwGxGetScreenWidth() - 220) / 2;
    int upy = IwGxGetScreenHeight() - (height * 3);
    int upx = leftx+width + (width/2);
    int downy = IwGxGetScreenHeight() - height;
    int downx = upx;
    int righty = IwGxGetScreenHeight() - (height * 2);
    int rightx = downx + width + (width/2);

    CIwMaterial *fadeMat = IW_GX_ALLOC_MATERIAL();
    fadeMat->SetAlphaMode(CIwMaterial::SUB);
    IwGxSetMaterial(fadeMat);

    g_Cursorkey = EXCURSOR_NONE;

    if ( (s3eKeyboardGetState(s3eKeyLeft) & S3E_KEY_STATE_DOWN) )
        g_Cursorkey = EXCURSOR_LEFT;
    if ( (s3eKeyboardGetState(s3eKeyRight) & S3E_KEY_STATE_DOWN) )
        g_Cursorkey = EXCURSOR_RIGHT;
    if ( (s3eKeyboardGetState(s3eKeyUp) & S3E_KEY_STATE_DOWN) )
        g_Cursorkey = EXCURSOR_UP;
    if ( (s3eKeyboardGetState(s3eKeyDown) & S3E_KEY_STATE_DOWN) )
        g_Cursorkey = EXCURSOR_DOWN;

    if(s3ePointerGetInt(S3E_POINTER_AVAILABLE))
    {
        if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN)
        {
            int pointerx = s3ePointerGetX();
            int pointery = s3ePointerGetY();
            // Check left
            if (pointerx >= leftx && pointerx <= leftx+width && pointery >=lefty && pointery <= lefty+height)
                g_Cursorkey = EXCURSOR_LEFT;
            // Check right
            if (pointerx >= rightx && pointerx <= rightx+width && pointery >=righty && pointery <= righty+height)
                g_Cursorkey = EXCURSOR_RIGHT;
            // Check up
            if (pointerx >= upx && pointerx <= upx+width && pointery >=upy && pointery <= upy+height)
                g_Cursorkey = EXCURSOR_UP;
            // Check down
            if (pointerx >= downx && pointerx <= downx+width && pointery >=downy && pointery <= downy+height)
                g_Cursorkey = EXCURSOR_DOWN;
        }

        CIwColour* cols = IW_GX_ALLOC(CIwColour, 4);
        if((s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN) && (g_Cursorkey != EXCURSOR_NONE))
            memset(cols, 10, sizeof(CIwColour)*4);
        else
            memset(cols, 50, sizeof(CIwColour)*4);

        // draw black rect covering screen
        CIwSVec2 rectdim(width, height);

        CIwSVec2 uXY(upx, upy-2);
        IwGxDrawRectScreenSpace(&uXY, &rectdim, cols);
        IwGxPrintString(upx + 10, upy + 5, "Up", false);

        CIwSVec2 dXY(downx, downy-2);
        IwGxDrawRectScreenSpace(&dXY, &rectdim, cols);
        IwGxPrintString(downx + 10, downy + 5, "Down", false);

        CIwSVec2 lXY(leftx, lefty-2);
        IwGxDrawRectScreenSpace(&lXY, &rectdim, cols);
        IwGxPrintString(leftx + 10, lefty + 5, "Left", false);

        CIwSVec2 rXY(rightx, righty-2);
        IwGxDrawRectScreenSpace(&rXY, &rectdim, cols);
        IwGxPrintString(rightx + 10, righty + 5, "Right", false);
    }
}
Esempio n. 15
0
extern "C" void RenderButtons()
{
    ExButtons* pbutton = g_ButtonsHead;

    if(g_ButtonsHead)
    {
        pbutton = g_ButtonsHead;
        while(pbutton != NULL)
        {
            // Check the key and pointer states.
            pbutton->key_state = s3eKeyboardGetState(pbutton->key);
            if( s3eKeyboardGetState(pbutton->key) & S3E_KEY_STATE_DOWN )
            {
                if(pbutton->handler)
                    pbutton->handler();
            }

            if (!(s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_UP))
            {
                int pointerx = s3ePointerGetX();
                int pointery = s3ePointerGetY();
                if (pointerx >= pbutton->x && pointerx <= pbutton->x+pbutton->w && pointery >=pbutton->y && pointery <= pbutton->y+pbutton->h)
                {
                    if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN)
                    {
                        pbutton->key_state = S3E_KEY_STATE_DOWN;
                    }
                    if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED)
                    {
                        pbutton->key_state = S3E_KEY_STATE_PRESSED;
                    }

                    if(pbutton->handler)
                        pbutton->handler();
                }

            }

            // Draw the text
            IwGxSetScreenSpaceSlot(0);

            if(s3ePointerGetInt(S3E_POINTER_AVAILABLE))
            {
                CIwMaterial *fadeMat = IW_GX_ALLOC_MATERIAL();
                fadeMat->SetAlphaMode(CIwMaterial::SUB);
                IwGxSetMaterial(fadeMat);

                CIwColour* cols = IW_GX_ALLOC(CIwColour, 4);
                if(pbutton->key_state == S3E_KEY_STATE_DOWN)
                    memset(cols, 15, sizeof(CIwColour)*4);
                else
                    memset(cols, 50, sizeof(CIwColour)*4);

                // Draw button area
                CIwSVec2 XY(pbutton->x, pbutton->y-2), dXY(pbutton->w, pbutton->h);
                IwGxDrawRectScreenSpace(&XY, &dXY, cols);
            }

            IwGxPrintString(pbutton->x + 2, pbutton->y + ((pbutton->h - 10)/2), pbutton->name, false);
            pbutton = pbutton->next;
        }
    }
}
Esempio n. 16
0
void Update()
{
	// Allow device OS time to do its processing
	s3eDeviceYield(0);

	// Update pointer (actually touch screen!) inputs
	s3ePointerUpdate();

	// Read current touch screen inputs and use them to update Button states
	uint32 lTouchState = s3ePointerGetState(S3E_POINTER_BUTTON_SELECT);
	int32 x = s3ePointerGetX();
	int32 y = s3ePointerGetY();
	for (uint32 i = 0; i < BUTTON_COUNT; i++)
	{
		gButton[i]->Update(lTouchState, x, y);
	}

	// Check for button presses
	if (gButton[BUTTON_AUDIO_MUSIC]->IsReleased())
	{
		s3eAudioPlay("black-hole.mp3");
	}
	else if (gButton[BUTTON_AUDIO_SFX]->IsReleased())
	{
		if (gpGunBattleSound)
			gpGunBattleSound->Play();
	}
	else if (gButton[BUTTON_AUDIO_SPEECH]->IsReleased())
	{
		if (gpFemaleCountingSound)
			gpFemaleCountingSound->Play();
	}
	else if (gButton[BUTTON_AUDIO_OFF]->IsReleased())
	{
		s3eAudioStop();
		s3eSoundStopAllChannels();
	}

	if (gButton[BUTTON_FILTER_OFF]->IsReleased())
	{
		if (gDolbyInitialised)
		{
			s3eDolbyAudioSetEnabled(S3E_FALSE);
		}
	}
	else if (gButton[BUTTON_FILTER_MUSIC]->IsReleased())
	{
		if (gDolbyInitialised)
		{
			s3eDolbyAudioSetEnabled(S3E_TRUE);
			s3eDolbyAudioSetProfile(MUSIC);
		}
	}
	else if (gButton[BUTTON_FILTER_MOVIE]->IsReleased())
	{
		if (gDolbyInitialised)
		{
			s3eDolbyAudioSetEnabled(S3E_TRUE);
			s3eDolbyAudioSetProfile(MOVIE);
		}
	}
	else if (gButton[BUTTON_FILTER_GAME]->IsReleased())
	{
		if (gDolbyInitialised)
		{
			s3eDolbyAudioSetEnabled(S3E_TRUE);
			s3eDolbyAudioSetProfile(GAME);
		}
	}
	else if (gButton[BUTTON_FILTER_VOICE]->IsReleased())
	{
		if (gDolbyInitialised)
		{
			s3eDolbyAudioSetEnabled(S3E_TRUE);
			s3eDolbyAudioSetProfile(VOICE);
		}
	}
}
Esempio n. 17
0
void CInventory::Update()
{
	// add an atom to the beaker when selected from the inventory
	int touchX = 0;
	int touchY = 0;
	if (g_Game.getGameState() == GS_Playing && s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED)
	{
		touchX = s3ePointerGetX();
		touchY = s3ePointerGetY();

		for (int i = 0; i < inventoryCount; i++)
		{
			if (atomObjs[i]->isTouched(touchX, touchY))
			{
				if (g_Beaker.getAtomSymbol() != NULL && !strcmp(atomObjs[i]->getSymbol(), g_Beaker.getAtomSymbol()))
				{
					// Early-terminate because the same inventory item was clicked more than once & can be ignored
					break;
				}

				if (atomCount[i] == 1)
				{
					// hide atom to indicate zero are left
					atomObjs[i]->setVisible(false);
					// HASAN - new to display the inventory count image
					atomCountImages[i]->setVisible(false);
				}

				// create new CAtom object to be held in the beaker, so inventory atom can remain unchanged
				CAtom* newAtom = new CAtom();
				newAtom->Init(atomObjs[i]->getSymbol());

				CAtom* prevAtom = g_Beaker.setAtom(newAtom);
				if (prevAtom != NULL)
				{
					// replacing previously selected atom in the beaker, so moving previous one back into this inventory
					// 1 - find previous atom slot in inventory
					// 2 - if previously zero count, then set back to visible
					// 3 - increment the atom counter
					for (int j = 0; j < inventoryCount; j++)
					{
						if (!strcmp(prevAtom->getSymbol(), atomObjs[j]->getSymbol()))
						{
							// match found
							if (atomCount[j] <= 0)
							{
								atomObjs[j]->setVisible(true);
								atomCountImages[j]->setVisible(true);
							}

							atomCount[j]++;

							// This was a clone of the object in the inventory, need to delete it (happens inside the sprite manager) when it's being replaced and not shot into the environment
							g_Game.getSpriteManager()->removeSprite(prevAtom);

							break;
						}
					}
				}

				atomCount[i]--;
			}
		}
	}
}
Esempio n. 18
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;
}
Esempio n. 19
0
//-----------------------------------------------------------------------------
bool HexMapTest::Update()
{
	int16 sprite1_pos_x,sprite1_pos_y;
	int16 sprite2_pos_x,sprite2_pos_y;
	if (mouse_mode == MOUSE_MODE_CHECKING)
		mouse_mode  = MOUSE_MODE_DOWN;

	// UI processing
	if (((s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED)) && mouse_mode == MOUSE_MODE_IDLE)
		mouse_mode = MOUSE_MODE_IDLE;
	if ((s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_RELEASED))
		mouse_mode = MOUSE_MODE_CHECKING;

//	UpdateKey();

	IwGxSetViewMatrix(&s_viewMatrix);

    // Generate a ray pointing to the view plane from the camera
    CIwVec3 dir(s3ePointerGetX() - IwGxGetScreenWidth()/2, 
        s3ePointerGetY() - IwGxGetScreenHeight()/2, 
        IwGxGetPerspMul());
    
    // Rotate into camera space
    dir = s_viewMatrix.RotateVec(dir);

	// Update pointer system
	g_Input.Update();
	if (g_Input.finger1IsDown()) {
		if (g_Input.overThreshold()) {
			if (!g_Input.finger1Continuing()) {
				s_ModelMatrix_initial = s_ModelMatrix;
				CIwVec3 vectCenter = getWorldCoords(0, 0);
				zoom_initial = zoom;
				rotation_initial = rotation;
				screenTranslationX_initial = screenTranslationX;
				screenTranslationY_initial = screenTranslationY;
				if (!g_Input.isMultiTouch()) {
					if (g_Input.finger1MovedTo(sprite1_pos_x, sprite1_pos_y)) {
						if (sprite1_pos_x > int(IwGxGetScreenWidth()) - SCREEN_MARGIN) {
							zooming = true;
						}
						if (sprite1_pos_y > int(IwGxGetScreenHeight()) - SCREEN_MARGIN) {
							rotating = true;
						}
					}
				}
			}
			if (!g_Input.finger2IsDown() && g_Input.finger1MovedTo(sprite1_pos_x, sprite1_pos_y)) {
				if (g_Input.finger1Continuing()) {
					if (zooming) {
						if (sprite1_pos_x > int(IwGxGetScreenWidth()) - SCREEN_MARGIN) {
							int16 dsprite1_pos_x, dsprite1_pos_y;
							if (g_Input.finger1MovementDelta(dsprite1_pos_x, dsprite1_pos_y)) {
								float deltaZoom = 1.0f - 1.0f*(dsprite1_pos_y)/IwGxGetScreenHeight();
								SetZoom(deltaZoom, 8);
							}
						}
					} else if (rotating) {
						if (sprite1_pos_y > int(IwGxGetScreenHeight()) - SCREEN_MARGIN) {
							int16 dsprite1_pos_x, dsprite1_pos_y;
							if (g_Input.finger1MovementDelta(dsprite1_pos_x, dsprite1_pos_y)) {
								float deltaRotation = 360.0f*(dsprite1_pos_x)/IwGxGetScreenWidth();
								SetRotation(deltaRotation);
							}
						}
					} else {
						SetTranslation();
					}
				}
			} else {
				if (g_Input.finger1MovedTo(sprite1_pos_x, sprite1_pos_y)) {
					if (g_Input.finger2MovedTo(sprite2_pos_x, sprite2_pos_y)) {
						if (!g_Input.finger2Continuing()) {
							screenTranslationX_initial = screenTranslationX;
							screenTranslationY_initial = screenTranslationY;
							g_Input.resetInitial(0);
						} else {
							int16 sprite1_pos_x_initial,sprite1_pos_y_initial,sprite2_pos_x_initial,sprite2_pos_y_initial;
							g_Input.finger1Initial(sprite1_pos_x_initial,sprite1_pos_y_initial);
							g_Input.finger2Initial(sprite2_pos_x_initial,sprite2_pos_y_initial);
							int d12x=sprite1_pos_x-sprite2_pos_x;
							int d12y=sprite1_pos_y-sprite2_pos_y;
							int d12x_initial=sprite1_pos_x_initial-sprite2_pos_x_initial;
							int d12y_initial=sprite1_pos_y_initial-sprite2_pos_y_initial;
							int Delta_initial = d12x_initial*d12x_initial+d12y_initial*d12y_initial;
							int Delta = d12x*d12x+d12y*d12y;
							float newZoom = float(sqrt(1.0*Delta)/sqrt(Delta_initial));
							SetZoom(newZoom, 1);
							float oldRotation = float(atan2(float(d12y_initial), float(d12x_initial)));
							float newRotation = float(atan2(float(d12y), float(d12x)));
							SetRotation(180.0f*(oldRotation-newRotation)/PI);
							{
								char string[256];
								//sprintf(string, "`1`a  del %04d, %04d",d1x,d2x);
								//IwGxPrintString(2, 96, string);
								sprintf(string, "`1`a  zoo %5.2f, %5.2f, %5.2f",newZoom,oldRotation,newRotation);
								IwGxPrintString(2, 96, string);
							}
						}
					}
				}
			}
		}
	} else {
		zooming = false;
		rotating = false;
		//		s_ModelMatrix = CIwMat::g_Identity;
	}
	return true;
}