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 } } }
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; } }
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); }
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; }
bool ExampleUpdate() { if( ExampleStep >= 100 ) { manager.stop(); while( manager.get_queue().begin() != manager.get_queue().end() ) manager.clean(*manager.get_queue().begin()); ExampleStep = 0; } if( !ExampleStep ) { printf("--------------- STARTING ---------------\n"); manager.start(); } manager.step(); ExampleStep += 1; if( manager.get_queue().size() < 20 ) { char buf[256]; sprintf(buf,HTTP_TILES,matrix.get_z(),matrix.get_x(),matrix.get_y()); manager.get(buf); matrix.step(); } if( manager.active_requests() < manager.get_max_handles() ) { std::list<Request *>::const_iterator e = manager.get_queue().end(); std::list<Request *>::const_iterator i = manager.get_queue().begin(); for( ; i != e; i++ ) { if( (*i)->get_state() == kOK || (*i)->get_state() == kError ) { manager.clean(*i); break; } } } if( s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED ) { // random cancel std::list<Request *>::const_iterator e = manager.get_queue().end(); std::list<Request *>::const_iterator i = manager.get_queue().begin(); for( ; i != e; i++ ) { if( (*i)->get_state() == kDownloading ) { (*i)->cancel(); break; } } } s3eDeviceYield(0); return true; }
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(); } }
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; }
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(); } }
bool MapBackground::UpdatePositionFromMouseAndKeyboard(CIwSVec2& clickPos, bool* pbClicked) { bool forceUpdate = false; bool downLoad = false; if (this->IsInitialized()) { bool updateLocation = false; CIwSVec2 pos; s3eLocation newLocation; this->GetScaler()->LocationToPosition(gLocation, &pos); if (s3eKeyboardGetState(s3eKeyUp) & S3E_KEY_STATE_DOWN) { pos.y -= 10; this->GetScaler()->PositionToLocation(pos, &newLocation); if (this->IsScaled()) { gLocation = newLocation; } else { gLocation.m_Latitude = newLocation.m_Latitude; } updateLocation = true; } if (s3eKeyboardGetState(s3eKeyDown) & S3E_KEY_STATE_DOWN) { pos.y += 10; this->GetScaler()->PositionToLocation(pos, &newLocation); if (this->IsScaled()) { gLocation = newLocation; } else { gLocation.m_Latitude = newLocation.m_Latitude; } updateLocation = true; } if (s3eKeyboardGetState(s3eKeyLeft) & S3E_KEY_STATE_DOWN) { pos.x -= 10; this->GetScaler()->PositionToLocation(pos, &newLocation); if (this->IsScaled()) { gLocation = newLocation; } else { gLocation.m_Longitude = newLocation.m_Longitude; } g_bShowCursor = false; updateLocation = true; } if (s3eKeyboardGetState(s3eKeyRight) & S3E_KEY_STATE_DOWN) { pos.x += 10; this->GetScaler()->PositionToLocation(pos, &newLocation); if (this->IsScaled()) { gLocation = newLocation; } else { gLocation.m_Longitude = newLocation.m_Longitude; } g_bShowCursor = false; updateLocation = true; } if (g_iActiveTouches > 1) { if (!g_bMultiTouch) { g_multitouchZoom = g_actualZoom; g_bMultiTouch = true; } CTouch* pTouch1 = NULL; CTouch *pTouch2 = NULL; g_iActiveTouches = 0; for (uint i = 0; i < MAX_TOUCHES; ++i) { if (g_Touches[i].active) { g_iActiveTouches++; if (!pTouch1) { pTouch1 = &g_Touches[i]; } else if (!pTouch2) { pTouch2 = &g_Touches[i]; } } } if (pTouch1 && pTouch2) { int startDistance = sqrt(pow(pTouch1->startX - pTouch2->startX, 2) + pow(pTouch1->startY - pTouch2->startY, 2)); int currDistance = sqrt(pow(pTouch1->x - pTouch2->x, 2) + pow(pTouch1->y - pTouch2->y, 2)); int distance = MIN(50, (startDistance - currDistance)); g_tempZoom = g_newZoom = g_actualZoom = MIN(19, MAX(14, g_multitouchZoom - ((float)distance / 25))); g_bLocationChanged = true; } } //else if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN) //{ // CIwSVec2 currentPos; // g_bShowCursor = false; // updateLocation = true; // currentPos.x = (int16)s3ePointerGetX(); // currentPos.y = (int16)s3ePointerGetY(); // if (g_bMouseDown) // { // if (ABS(currentPos.x - g_downMousePos.x) > 5 || ABS(currentPos.y - g_downMousePos.y) > 5) // { // gLocation.m_Longitude += -(currentPos.x - g_lastMousePos.x) * this->GetLongitudePerPixel(); // gLocation.m_Latitude += -(currentPos.y - g_lastMousePos.y) * this->GetLatitudePerPixel(); // forceUpdate = true; // } // } // else // { // g_downMousePos.x = currentPos.x; // g_downMousePos.y = currentPos.y; // } // g_lastMousePos.x = currentPos.x; // g_lastMousePos.y = currentPos.y; // g_bMouseDown = true; //} else if (s3ePointerGetState(S3E_POINTER_BUTTON_RIGHTMOUSE) & S3E_POINTER_STATE_RELEASED) { forceUpdate = true; g_newZoom = g_actualZoom - .25; } else { g_bMultiTouch = false; if (g_bMouseDown) { if (ABS(g_downMousePos.x - g_lastMousePos.x) < 5 && ABS(g_downMousePos.y - g_lastMousePos.y) < 5) { *pbClicked = true; clickPos.x = g_lastMousePos.x; clickPos.y = g_lastMousePos.y; } } g_bMouseDown = false; } if (updateLocation) { this->SetLocation(gLocation.m_Longitude, gLocation.m_Latitude); } } if (g_bInitialLoad) { g_bInitialLoad = false; downLoad = true; } double dLat = gPrevLocation.m_Latitude - gLocation.m_Latitude; double dLng = gPrevLocation.m_Longitude - gLocation.m_Longitude; if (dLat < 0) { dLat = -dLat; } if (dLng < 0) { dLng = -dLng; } if ((dLat > 0.00050 || dLng > 0.00050)) { downLoad = true; } if (downLoad) { gPrevLocation = gLocation; } this->Update(downLoad || forceUpdate); return forceUpdate; }
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 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]--; } } } }
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; } } }
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); } } }
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); } }
//----------------------------------------------------------------------------- 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; }
void doMain() { if(s3ePointerGetInt(S3E_POINTER_MULTI_TOUCH_AVAILABLE)){ s3ePointerRegister(S3E_POINTER_TOUCH_EVENT, (s3eCallback)MultiTouchButtonCB, NULL); s3ePointerRegister(S3E_POINTER_TOUCH_MOTION_EVENT, (s3eCallback)MultiTouchMotionCB, NULL); } else { s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, (s3eCallback)SingleTouchButtonCB, NULL); s3ePointerRegister(S3E_POINTER_MOTION_EVENT, (s3eCallback)SingleTouchMotionCB, NULL); } IwGetResManager()->LoadGroup("resource_groups/palate.group"); palateGroup = IwGetResManager()->GetGroupNamed("Palate"); std::vector<int> ui_texture_hashes; uint background_hash = IwHashString("background_clean"); CIwResList* resources = palateGroup->GetListHashed(IwHashString("CIwTexture")); for(CIwManaged** itr = resources->m_Resources.GetBegin(); itr != resources->m_Resources.GetEnd(); ++itr) { if(background_hash != (*itr)->m_Hash) { ui_texture_hashes.push_back((*itr)->m_Hash); } } CIwMaterial* background = new CIwMaterial(); background->SetTexture((CIwTexture*)palateGroup->GetResNamed("background_clean", IW_GX_RESTYPE_TEXTURE)); background->SetModulateMode(CIwMaterial::MODULATE_NONE); background->SetAlphaMode(CIwMaterial::ALPHA_DEFAULT); unit_ui = new CIwMaterial(); unit_ui->SetModulateMode(CIwMaterial::MODULATE_NONE); unit_ui->SetAlphaMode(CIwMaterial::ALPHA_DEFAULT); unit_ui->SetTexture((CIwTexture*)palateGroup->GetResNamed("TAKE2", IW_GX_RESTYPE_TEXTURE)); CIwSVec2 bg_wh(320, 480); CIwSVec2 ui_wh(80, 480); CIwSVec2 ui_offset(240, 0); CIwSVec2 uv(0, 0); CIwSVec2 duv(IW_GEOM_ONE, IW_GEOM_ONE); init(); IwGxLightingOff(); IwGxSetColClear(255, 255, 255, 255); float worldScrollMultiplier = 0.75; if(s3eDeviceGetInt(S3E_DEVICE_OS) == S3E_OS_ID_IPHONE) { worldScrollMultiplier = 0.925; } while (1) { int64 start = s3eTimerGetMs(); s3eDeviceYield(0); s3eKeyboardUpdate(); s3ePointerUpdate(); if ((s3eKeyboardGetState(s3eKeyEsc) & S3E_KEY_STATE_DOWN) || (s3eKeyboardGetState(s3eKeyAbsBSK) & S3E_KEY_STATE_DOWN) || (s3eDeviceCheckQuitRequest())) { break; } switch(currentState) { case MAIN_MENU: if(s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED) { currentState = IN_GAME; } if(frameCount % FRAMES_PER_UPDATE == 0) { mainMenu->tick(); } mainMenu->render(); break; case IN_GAME: IwGxSetMaterial(background); IwGxSetScreenSpaceSlot(-1); IwGxDrawRectScreenSpace(&CIwSVec2::g_Zero, &bg_wh, &uv, &duv); IwGxSetMaterial(unit_ui); IwGxSetScreenSpaceSlot(1); IwGxDrawRectScreenSpace(&ui_offset, &ui_wh, &uv, &duv); if (worldScrollSpeed > .0005 || worldScrollSpeed < -.0005) { game->rotate(worldScrollSpeed); worldScrollSpeed *= worldScrollMultiplier; } if(frameCount % FRAMES_PER_UPDATE == 0) { game->tick(); } game->render(); if(!renderTouches()) { break; } break; } IwGxFlush(); IwGxSwapBuffers(); // Attempt frame rate while ((s3eTimerGetMs() - start) < MS_PER_FRAME){ int32 yield = (MS_PER_FRAME - (s3eTimerGetMs() - start)); if (yield < 0) { break; } s3eDeviceYield(yield); } frameCount++; IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F); } delete game; delete mainMenu; delete localPlayer; delete opponentPlayer; delete background; delete unit_ui; palateGroup->Finalise(); for(int i = 0; i < MAX_TOUCHES; ++i) if(touches[i].unit) delete touches[i].unit; }
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()); } }
bool Input::clicked() const { return s3ePointerGetState(S3E_POINTER_BUTTON_LEFTMOUSE) == S3E_POINTER_STATE_RELEASED || s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) == S3E_POINTER_STATE_RELEASED; }
bool Input::pressed() const { return s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN; }
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; }
void IntroState::HandleEvent(StateEngine* state) { if( (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN)) state->ChangeState(MainMenuState::Instance()); }