示例#1
0
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);
}
示例#2
0
void btnDrawButton(button * aButton) {
    if (!aButton->visible) {
        return;
    }
    
    if (aButton->buttonType == btnButtonTypeSlider) {
        btnDrawSlider(aButton);
        return;
    }
    
    rgbColour *aRGB;
    
    if (aButton->highlighted) {
        aRGB = tintColour();
        
    }
    else {
        aRGB = inactiveColour();
    }
    
    u8 r = aRGB->r;
    u8 g = aRGB->g;
    u8 b = aRGB->b;
    
    
    if (aButton->buttonType == btnButtonTypeToolbarLeft) {
        if (themeImageExists(themeImageTopLeftButton)) {
            if (aButton->highlighted && themeImageExists(themeImageTopLeftButtonSelected)) {
                drawThemeImage(themeImageTopLeftButtonSelected, aButton->screen, aButton->x-(36-aButton->h), aButton->y);
            }
            else {
                drawThemeImage(themeImageTopLeftButton, aButton->screen, aButton->x-(36-aButton->h), aButton->y);
            }
        }
        else {
            gfxDrawSpriteAlphaBlendFade(aButton->screen, aButton->side, (u8*)toolbarbuttonshadowleft_bin, 41, 41, aButton->x-(41-aButton->h), aButton->y, translucencyBarIcons);
            btnDrawMaskedBitmapForButton(aButton, lefttoolbarbuttonalphamask_bin, r, g, b, translucencyBarIcons);
        }
    }
    else if (aButton->buttonType == btnButtonTypeToolbarRight) {
        if (themeImageExists(themeImageTopRightButton)) {
            if (aButton->highlighted && themeImageExists(themeImageTopRightButtonSelected)) {
                drawThemeImage(themeImageTopRightButtonSelected, aButton->screen, aButton->x-(36-aButton->h), aButton->y-(36-aButton->w));
            }
            else {
                drawThemeImage(themeImageTopRightButton, aButton->screen, aButton->x-(36-aButton->h), aButton->y-(36-aButton->w));
            }
        }
        else {
            gfxDrawSpriteAlphaBlendFade(aButton->screen, aButton->side, (u8*)toolbarbuttonshadowright_bin, 41, 41, aButton->x-(41-aButton->h), aButton->y-(41-aButton->w), translucencyBarIcons);
            btnDrawMaskedBitmapForButton(aButton, righttoolbarbuttonalphamask_bin, r, g, b, translucencyBarIcons);
        }
    }
    else if (aButton->buttonType == btnButtonTypeToolbarBottomRight) {
        if (themeImageExists(themeImageBottomRightButton)) {
            if (aButton->highlighted && themeImageExists(themeImageBottomRightButtonSelected)) {
                drawThemeImage(themeImageBottomRightButtonSelected, aButton->screen, aButton->x, aButton->y-(36-aButton->w));
            }
            else {
                drawThemeImage(themeImageBottomRightButton, aButton->screen, aButton->x, aButton->y-(36-aButton->w));
            }
        }
        else {
            gfxDrawSpriteAlphaBlendFade(aButton->screen, aButton->side, (u8*)toolbarbuttonshadowbottomright_bin, 41, 41, aButton->x, aButton->y-(41-aButton->w), translucencyBarIcons);
            btnDrawMaskedBitmapForButton(aButton, bottomrighttoolbarbuttonalphamask_bin, r, g, b, translucencyBarIcons);
        }
    }
    else if (aButton->buttonType == btnButtonTypeToolbarBottomLeft) {
        if (themeImageExists(themeImageBottomLeftButton)) {
            if (aButton->highlighted && themeImageExists(themeImageBottomLeftButtonSelected)) {
                drawThemeImage(themeImageBottomLeftButtonSelected, aButton->screen, aButton->x, aButton->y);
            }
            else {
                drawThemeImage(themeImageBottomLeftButton, aButton->screen, aButton->x, aButton->y);
            }
        }
        else {
            gfxDrawSpriteAlphaBlendFade(aButton->screen, aButton->side, (u8*)toolbarbuttonshadowbottomleft_bin, 41, 41, aButton->x, aButton->y, translucencyBarIcons);
            btnDrawMaskedBitmapForButton(aButton, bottomlefttoolbarbuttonalphamask_bin, r, g, b, translucencyBarIcons);
        }
    }
    else if (aButton->buttonType == btnButtonTypePageArrowLeft) {
        btnDrawMaskedBitmapForButton(aButton, arrowleftalphamask_bin, r, g, b, translucencyPageControls);
    }
    else if (aButton->buttonType == btnButtonTypePageArrowRight) {
        btnDrawMaskedBitmapForButton(aButton, arrowrightalphamask_bin, r, g, b, translucencyPageControls);
    }
    else if (aButton->buttonType == btnButtonTypeRect) {
        drawButtonRectForButton(aButton, r, g, b);
    }
    else {
        return;
    }
    
    rgbColour * dark = darkTextColour();
    
    if (aButton->selected) {        
        gfxDrawSpriteAlphaBlend(aButton->screen, aButton->side, (u8*)tick_bin, 48, 48, aButton->x, aButton->y);
    }
    
    if (aButton->buttonIcon == btnButtonIconBackArrow) {
        if (themeImageExists(themeImageBackSymbol)) {
            drawThemeImage(themeImageBackSymbol, aButton->screen, aButton->x, aButton->y);
        }
        else {
            btnDrawIcon(aButton, (u8*)backarrow_bin);
        }
    }
    else if (aButton->buttonIcon == btnButtonIconSpanner) {
        if (themeImageExists(themeImageSettingsSymbol)) {
            drawThemeImage(themeImageSettingsSymbol, aButton->screen, aButton->x, aButton->y);
        }
        else {
            btnDrawIcon(aButton, (u8*)spanner_bin);
        }
    }
    else if (aButton->buttonIcon == btnButtonIconQuestionMark) {
        if (themeImageExists(themeImageHelpSymbol)) {
            drawThemeImage(themeImageHelpSymbol, aButton->screen, aButton->x, aButton->y);
        }
        else {
            btnDrawIcon(aButton, (u8*)questionmark_bin);
        }
    }
    else if (aButton->buttonIcon == btnButtonIconFolder) {
        if (themeImageExists(themeImageFoldersSymbol)) {
            drawThemeImage(themeImageFoldersSymbol, aButton->screen, aButton->x, aButton->y);
        }
        else {
            btnDrawIcon(aButton, (u8*)folder_bin);
        }
    }
    else if (aButton->buttonIcon == btnButtonIconHome) {
        if (themeImageExists(themeImageHomeSymbol)) {
            drawThemeImage(themeImageHomeSymbol, aButton->screen, aButton->x, aButton->y);
        }
        else {
            btnDrawIcon(aButton, (u8*)home_bin);
        }
    }
    
    MAFont *font = &MAFontRobotoRegular10;
    
    int lineHeight = font->lineHeight;
    
    int textOffset = 10;
    
    if (strlen(aButton->shortText1) > 0) {
        MADrawTextWrap(aButton->screen, aButton->side, aButton->x + (aButton->w/2), aButton->y+textOffset, aButton->shortText1, font, dark->r, dark->g, dark->b, 0, 0);
    }

    if (strlen(aButton->shortText2) > 0) {
        MADrawTextWrap(aButton->screen, aButton->side, aButton->x + (aButton->w/2) - lineHeight, aButton->y + textOffset, aButton->shortText2, font, dark->r, dark->g, dark->b, 0, 0);
    }

    if (strlen(aButton->longText) > 0) {
        MADrawTextWrap(aButton->screen, aButton->side, aButton->x + (aButton->w/2) - (lineHeight/2), aButton->y + textOffset, aButton->longText, font, dark->r, dark->g, dark->b, 0, 0);
    }

}
示例#3
0
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;
}