void DrawRect(int x, int y, int width, int height, uint8 r, uint8 g, uint8 b) { int right = x + width; int bottom = y + height; if (x < 0) x = 0; if (y < 0) y = 0; if (right > (int32)s3eSurfaceGetInt(S3E_SURFACE_WIDTH)) right = s3eSurfaceGetInt(S3E_SURFACE_WIDTH); if (bottom > (int32)s3eSurfaceGetInt(S3E_SURFACE_HEIGHT)) bottom = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT); // Draw the text IwGxSetScreenSpaceSlot(0); CIwMaterial *fadeMat = IW_GX_ALLOC_MATERIAL(); fadeMat->SetAlphaMode(CIwMaterial::NONE); fadeMat->SetShadeMode(CIwMaterial::SHADE_FLAT); IwGxSetMaterial(fadeMat); CIwColour* cols = IW_GX_ALLOC(CIwColour, 4); for (int i = 0; i < 4; i++) cols[i].Set(r, g, b); CIwSVec2 xy(x, y); CIwSVec2 wh(width, height); IwGxDrawRectScreenSpace(&xy, &wh, cols); }
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); }
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); }
void CEndGameState::Render() { IW_CALLSTACK("CEndGameState::Render"); IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F); GetWorld().Render(); IwGxLightingOff(); IwGxSetScreenSpaceOrg( &CIwSVec2::g_Zero ); CIwColour* cols = IW_GX_ALLOC(CIwColour, 4); memset(cols, 255, sizeof(CIwColour) * 4 ); if (GetWorld().GetUICar()->GetPosition() == 1 ) { CIwMaterial* mat = (CIwMaterial *)IwGetResManager()->GetGroupNamed("ui")->GetResNamed("youwin", IW_GX_RESTYPE_MATERIAL); IwGxSetMaterial(mat); } else { CIwMaterial* mat = (CIwMaterial *)IwGetResManager()->GetGroupNamed("ui")->GetResNamed("youlose", IW_GX_RESTYPE_MATERIAL); IwGxSetMaterial(mat); } const uint32 imageWidth = 128; const uint32 imageHeight = 32; CIwSVec2 XY( (int16)((IwGxGetScreenWidth()/2) - (imageWidth/2)), (int16)(IwGxGetScreenHeight()/4) ), dXY( (int16)imageWidth, (int16)imageHeight ); IwGxDrawRectScreenSpace(&XY, &dXY, cols); IwGxLightingOn(); IwGxFlush(); IwGxSwapBuffers(); #ifdef IW_DEBUG // Reset metrics for next frame IwGxMetricsReset(); #endif }
void Unit::displayOnScreen(int x, int y){ CIwMaterial *mat = new CIwMaterial(); mat->SetTexture((CIwTexture*)game->getSprites()->GetResHashed(getTextureName(), IW_GX_RESTYPE_TEXTURE)); mat->SetModulateMode(CIwMaterial::MODULATE_NONE); mat->SetAlphaMode(CIwMaterial::ALPHA_DEFAULT); IwGxSetMaterial(mat); CIwSVec2 xy(x-45, y-45); CIwSVec2 duv(IW_FIXED(1.0/numFrames), IW_GEOM_ONE); static CIwSVec2 wh(90, 90); static CIwSVec2 uv(IW_FIXED(0), IW_FIXED(0)); IwGxSetScreenSpaceSlot(1); IwGxDrawRectScreenSpace(&xy, &wh, &uv, &duv); delete mat; }
void Transitions2D::Fade(uint8 transitionSpeed, bool skipFirstAndLastFrame) { IwGxSetColClear(0, 0, 0, 0); if (mStartTexture == NULL || mEndTexture == NULL) return; if (transitionSpeed == 0) transitionSpeed = 1; IwGxScreenOrient orient = IwGxGetScreenOrient(); if (isUsingPrivateTextures) IwGxSetScreenOrient(IW_GX_ORIENT_NONE); int alpha = 0; if (skipFirstAndLastFrame) alpha += transitionSpeed; CIwMaterial* startMat; CIwMaterial* endMat; while (alpha <= 255) { IwGxClear(); startMat = IW_GX_ALLOC_MATERIAL(); startMat->SetTexture(mStartTexture); IwGxSetMaterial(startMat); IwGxDrawRectScreenSpace(&CIwSVec2(0, 0), &CIwSVec2(mStartTexture->GetWidth(), mStartTexture->GetHeight())); endMat = IW_GX_ALLOC_MATERIAL(); endMat->SetTexture(mEndTexture); endMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND); endMat->SetColAmbient(255, 255, 255, alpha); IwGxSetMaterial(endMat); IwGxDrawRectScreenSpace(&CIwSVec2(0, 0), &CIwSVec2(mEndTexture->GetWidth(), mEndTexture->GetHeight())); IwGxFlush(); IwGxSwapBuffers(); s3eDeviceYield(40); alpha += transitionSpeed; } if (!skipFirstAndLastFrame) { IwGxClear(); endMat = IW_GX_ALLOC_MATERIAL(); endMat->SetTexture(mEndTexture); IwGxSetMaterial(endMat); IwGxDrawRectScreenSpace(&CIwSVec2(0, 0), &CIwSVec2(mEndTexture->GetWidth(), mEndTexture->GetHeight())); IwGxFlush(); IwGxSwapBuffers(); } if (isUsingPrivateTextures) { delete mStartTexture; delete mEndTexture; mStartTexture = NULL; mEndTexture = NULL; } IwGxSetScreenOrient(orient); }
void Transitions2D::Slide(DIR d, uint8 transitionSpeed, bool skipFirstAndLastFrame) { IwGxSetColClear(0, 0, 0, 0); if (mStartTexture == NULL || mEndTexture == NULL) return; if (transitionSpeed == 0) transitionSpeed = 1; IwGxScreenOrient orient = IwGxGetScreenOrient(); if (isUsingPrivateTextures) IwGxSetScreenOrient(IW_GX_ORIENT_NONE); CIwMaterial* startMat; CIwMaterial* endMat; int w = mStartTexture->GetWidth(); int h = mStartTexture->GetHeight(); int pos = 0; int speed, size; if (d == LEFT || d == RIGHT) { speed = (int)((transitionSpeed * w) / 255.0); size = w; } else { speed = (int)((transitionSpeed * h) / 255.0); size = h; } if (skipFirstAndLastFrame) pos += speed; while (pos < size) { IwGxClear(); if (d == LEFT) { startMat = IW_GX_ALLOC_MATERIAL(); startMat->SetTexture(mStartTexture); IwGxSetMaterial(startMat); IwGxDrawRectScreenSpace(&CIwSVec2(-pos, 0), &CIwSVec2(mStartTexture->GetWidth(), mStartTexture->GetHeight())); endMat = IW_GX_ALLOC_MATERIAL(); endMat->SetTexture(mEndTexture); IwGxSetMaterial(endMat); IwGxDrawRectScreenSpace(&CIwSVec2(-pos + size, 0), &CIwSVec2(mEndTexture->GetWidth(), mEndTexture->GetHeight())); } else if (d == RIGHT) { endMat = IW_GX_ALLOC_MATERIAL(); endMat->SetTexture(mEndTexture); IwGxSetMaterial(endMat); IwGxDrawRectScreenSpace(&CIwSVec2(pos - size, 0), &CIwSVec2(mEndTexture->GetWidth(), mEndTexture->GetHeight())); startMat = IW_GX_ALLOC_MATERIAL(); startMat->SetTexture(mStartTexture); IwGxSetMaterial(startMat); IwGxDrawRectScreenSpace(&CIwSVec2(pos, 0), &CIwSVec2(mStartTexture->GetWidth(), mStartTexture->GetHeight())); } else if (d == UP) { startMat = IW_GX_ALLOC_MATERIAL(); startMat->SetTexture(mStartTexture); IwGxSetMaterial(startMat); IwGxDrawRectScreenSpace(&CIwSVec2(0, -pos), &CIwSVec2(mStartTexture->GetWidth(), mStartTexture->GetHeight())); endMat = IW_GX_ALLOC_MATERIAL(); endMat->SetTexture(mEndTexture); IwGxSetMaterial(endMat); IwGxDrawRectScreenSpace(&CIwSVec2(0, -pos + size), &CIwSVec2(mEndTexture->GetWidth(), mEndTexture->GetHeight())); } else if (d == DOWN) { endMat = IW_GX_ALLOC_MATERIAL(); endMat->SetTexture(mEndTexture); IwGxSetMaterial(endMat); IwGxDrawRectScreenSpace(&CIwSVec2(0, pos - size), &CIwSVec2(mEndTexture->GetWidth(), mEndTexture->GetHeight())); startMat = IW_GX_ALLOC_MATERIAL(); startMat->SetTexture(mStartTexture); IwGxSetMaterial(startMat); IwGxDrawRectScreenSpace(&CIwSVec2(0, pos), &CIwSVec2(mStartTexture->GetWidth(), mStartTexture->GetHeight())); } IwGxFlush(); IwGxSwapBuffers(); s3eDeviceYield(40); pos += speed; } if (!skipFirstAndLastFrame) { IwGxClear(); endMat = IW_GX_ALLOC_MATERIAL(); endMat->SetTexture(mEndTexture); IwGxSetMaterial(endMat); IwGxDrawRectScreenSpace(&CIwSVec2(0, 0), &CIwSVec2(mEndTexture->GetWidth(), mEndTexture->GetHeight())); IwGxFlush(); IwGxSwapBuffers(); } if (isUsingPrivateTextures) { delete mStartTexture; delete mEndTexture; mStartTexture = NULL; mEndTexture = NULL; } IwGxSetScreenOrient(orient); }
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; }
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); } }
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; } } }