void btnDrawSlider(button * slider) { if (!slider->visible) { return; } rgbColour * aRGB = inactiveColour(); drawButtonRectForButton(slider, aRGB->r, aRGB->g, aRGB->b); u8 rgb[3] = {0, 0, 0}; gfxDrawRectangle(slider->screen, slider->side, rgb, slider->x, (slider->y+slider->value)-(sliderIndicatorWidth/2), slider->w, sliderIndicatorWidth); rgb[0] = 255; rgb[1] = 255; rgb[2] = 255; gfxDrawRectangle(slider->screen, slider->side, rgb, slider->x+1, ((slider->y+slider->value)-(sliderIndicatorWidth/2))+1, slider->w-2, sliderIndicatorWidth-2); rgbColour * dark = darkTextColour(); MAFont *font = &MAFontRobotoRegular10; int lineHeight = font->lineHeight; if (strlen(slider->shortText1) > 0) { MADrawTextWrap(slider->screen, slider->side, slider->x + (slider->w/2) - (lineHeight/2), slider->y + 20, slider->shortText1, font, dark->r, dark->g, dark->b, 0, 0); } if (strlen(slider->shortText2) > 0) { int width = MATextWidthInPixels(slider->shortText2, font); MADrawTextWrap(slider->screen, slider->side, slider->x + (slider->w/2) - (lineHeight/2), (slider->y + slider->h) - width - 20, slider->shortText2, font, dark->r, dark->g, dark->b, 0, 0); } drawButtonRect(slider->screen, slider->side, sliderButtonX, sliderMinusButtonY, sliderButtonWidth, sliderButtonHeight, dark->r, dark->g, dark->b); drawButtonRect(slider->screen, slider->side, sliderButtonX, sliderPlusButtonY, sliderButtonWidth, sliderButtonHeight, dark->r, dark->g, dark->b); rgbColour *light = lightTextColour(); MADrawText(slider->screen, slider->side, sliderButtonX-2, sliderMinusButtonY+10, "-", &MAFontRobotoRegular16, light->r, light->g, light->b); MADrawText(slider->screen, slider->side, sliderButtonX-2, sliderPlusButtonY+10, "+", &MAFontRobotoRegular16, light->r, light->g, light->b); }
int drawAlert(char * title, char * body, u8 * image, int numButtons, char buttonTitles[3][32]) { //int ret = alertButtonNone; if (hidKeysDown()&KEY_A) { return alertSelectedButton; } if (hidKeysDown()&KEY_B) { return alertButtonKeyB; } if (hidKeysDown()&KEY_DOWN) { alertSelectedButton++; if (alertSelectedButton >= numButtons) { alertSelectedButton = 0; } } if (hidKeysDown()&KEY_UP) { alertSelectedButton--; if (alertSelectedButton < 0) { alertSelectedButton = numButtons-1; } } MAGFXDrawPanel(GFX_TOP, true); MAGFXDrawPanel(GFX_BOTTOM, false); MAFont font = MAFontRobotoRegular16; int leftOffset = 30; int topOffset = 240 - 50 - font.lineHeight; rgbColour * textCol = titleTextColour(); MADrawText(GFX_TOP, GFX_LEFT, topOffset, leftOffset, title, &font, textCol->r, textCol->g, textCol->b); font = MAFontRobotoRegular10; topOffset -= font.lineHeight * 2; int totalWidthForText = 400; rgbColour * dark = darkTextColour(); MADrawTextWrap(GFX_TOP, GFX_LEFT, topOffset, leftOffset, body, &font, dark->r, dark->g, dark->b, totalWidthForText-(2*leftOffset), 0); //MADrawTextWrap(GFX_TOP, GFX_LEFT, topOffset, leftOffset, body, &font, dark->r, dark->g, dark->b, totalWidthForText, 0); /* WEIRD BUG ALERT! It was discovered that some alerts did not display their body text. In the process of trying to work out what was happening, I created a string containing the number of lines drawn by MADrawTextWrap and drew this on the screen so I could see what was actually happening. When I did this, the body text started appearing as well as the text showing how many lines it had drawn. I then found that it was the process of creating a string and putting something in it which was allowing the text to be drawn. I actually have no idea why this fixes the bug with drawing the body text. It feels like a memory management thing, but I can't figure it out. */ char s[64]; strcpy(s, "5"); int screenHeight = 240; int screenWidth = 320; int buttonGap = 10; int totalHeight = (numButtons*btnRectWidth) + ((numButtons-1)*buttonGap); int diff = screenHeight-totalHeight; int x = screenHeight - (diff/2) - btnRectWidth; int y = (screenWidth/2) - (btnRectHeight/2); touchPosition touch; hidTouchRead(&touch); int touchX = touch.px; int touchY = touch.py; int i; for (i=0; i<numButtons; i++) { button * aButton = malloc(sizeof(button)); btnSetButtonType(aButton, btnButtonTypeRect); strcpy(aButton->longText, buttonTitles[i]); strcpy(aButton->shortText1, ""); strcpy(aButton->shortText2, ""); aButton->x = x; aButton->y = y; aButton->highlighted = (i == alertSelectedButton); aButton->selected = false; x -= (btnRectWidth+buttonGap); btnDrawButton(aButton); if (!touchesAreBlocked && hidKeysDown()&KEY_TOUCH && btnTouchWithin(touchX, touchY, aButton)) { if (i == alertSelectedButton) { return alertSelectedButton; } else { alertSelectedButton = i; } } free(aButton); } return alertButtonNone; }