int PrintMessages(int x, int y) { if (!g_NumMessages || g_MessageIdx == -1) return -1; char* currentMsg; for (int i=0, j = g_MessageIdx; i < g_NumMessages; i++, j = (j + (g_NumMessages-1)) % g_NumMessages) { // Avoid overlapping exit button if (y > s3eSurfaceGetInt(S3E_SURFACE_HEIGHT) - (s3eDebugGetInt(S3E_DEBUG_FONT_HEIGHT)*2)) break; if (j > g_MessageIdx && !g_LoopMessages) continue; currentMsg = g_Messages[j]; if (currentMsg[0]) { s3eDebugPrintf(x, y, 0, "%s", currentMsg); if (i != g_NumMessages -1) y += s3eDebugGetInt(S3E_DEBUG_FONT_HEIGHT)+2; } } return y; }
int main() { IwGxInit(); IwGxSetColClear(0, 0, 0xff, 0xff); IwResManagerInit(); Iw2DInit(); setupTextures(); registerInput(); const int textWidth = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_WIDTH); const int textHeight = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_HEIGHT); const int width = s3eSurfaceGetInt(S3E_SURFACE_WIDTH); const int height = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT); sprintf(g_debugButtonEvent, "ButtonEvent:"); sprintf(g_debugKeyEvent, "KeyEvent:"); sprintf(g_debugMotionEvent, "MotionEvent:"); sprintf(g_debugTouchEvent, "TouchEvent:"); sprintf(g_debugTouchMotionEvent, "TouchMotionEvent:"); while (!s3eDeviceCheckQuitRequest()) { render(); // Yield until unyield is called or a quit request is recieved s3eDeviceYield(S3E_DEVICE_YIELD_FOREVER); } destroyTextures(); Iw2DTerminate(); IwResManagerTerminate(); IwGxTerminate(); return 0; }
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(); } }
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 ExampleRender() { const int textHeight = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_HEIGHT); int y = GetYBelowButtons() + 3 * textHeight; const int x = 10; if (s3eSoundGetInt(S3E_SOUND_STEREO_ENABLED)) { s3eDebugPrintf(x, y, 0, "`x666666Stereo sound output supported and enabled"); } else { s3eDebugPrintf(x, y, 0, "`x666666SStereo sound output disabled or unsupported"); } y += textHeight; y += textHeight; /*if (ogg_hlp->get_nChannels() == 2) s3eDebugPrintf(x, y, 0, "`x666666Input: Stereo"); else s3eDebugPrintf(x, y, 0, "`x666666Input: Mono");*/ /*if (ogg_hlp->get_outputStereoMode() == COggVorbisFileHelper::STEREO_MODE_MONO) { if (!(ogg_hlp->get_nChannels() == 2)) s3eDebugPrintf(x, y, 0, "`x666666Output: Mono"); else s3eDebugPrintf(x, y, 0, "`x666666Output: Mono (left channel of stereo input)"); } else { const char* modeLRString; switch (ogg_hlp->get_outputStereoMode()) { case COggVorbisFileHelper::STEREO_MODE_LEFT: modeLRString = "left only"; break; case COggVorbisFileHelper::STEREO_MODE_RIGHT: modeLRString = "right only"; break; default: modeLRString = "left and right"; break; } s3eDebugPrintf(x, y, 0, "`x666666Output: Stereo (%s)", modeLRString); } y += textHeight; s3eDebugPrintf(x, y, 0, "`x666666Input freq: %ld", ogg_hlp->get_rate()); y += textHeight; s3eDebugPrintf(x, y, 0, "`x666666Output freq: %d", ogg_hlp->get_outputrate()); y += textHeight; s3eDebugPrintf(x, y, 0, "`x666666g_OutputIsStereo: %d", ogg_hlp->get_outputIsStereo()); y += textHeight; s3eDebugPrintf(x, y, 0, "`x666666Buffer: %.2f",ogg_hlp->get_decbuf()*100); y += textHeight; s3eDebugPrintf(x, y, 0, "`x666666Total Samples: %ld", (long)ogg_hlp->get_nsamples()); y += textHeight; s3eDebugPrintf(x, y, 0, "`x666666Total time: %.0f", ogg_hlp->get_time_length()); y += textHeight; s3eDebugPrintf(x, y, 0, "`x666666Current time: %.0f (%0.f%%)", ogg_hlp->get_current_time(),ogg_hlp->get_current_time()/ogg_hlp->get_time_length()*100); y += textHeight; s3eDebugPrintf(x, y, 0, "`x666666Resample: %d - Quality: %d)", g_EnableResample,g_ResampleQuality); y += textHeight; s3eDebugPrintf(x, y, 0, "`x666666Status: %s", ogg_hlp->get_statusstr().c_str()); y += textHeight; y += textHeight; y += textHeight; */ s3eDebugPrintf(x, y, 0, "`x666666channels playing: %i", GetNumOggChannels()); }
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); } } }