xboxscene.org forums

Xbox360 Forums => Xbox360 Software Forums => XeXDK development => Topic started by: dschu012 on April 14, 2010, 10:48:00 PM

Title: Setting A Xuitextelement's Textcolor Property
Post by: dschu012 on April 14, 2010, 10:48:00 PM
CODE

Some text

I haven't fool around much with the xdk, but it looks like the color for the text element can't be set in code. But I think the above should work.
Title: Setting A Xuitextelement's Textcolor Property
Post by: node21 on April 15, 2010, 11:51:00 AM
CODE

 HRESULT OnGetSourceDataText(XUIMessageGetSourceText *pGetSourceTextData, BOOL& bHandled)


I've got this:

CODE

            if( ( 3 == pGetSourceTextData->iData ) && ( ( !pGetSourceTextData->bItemData ) ) ) {
                pGetSourceTextData->szText = L"Title";
                if (sortCol == pGetSourceTextData->iData) {
                    pGetSourceTextData->nTextFormatInfo = 1;
                    pGetSourceTextData->pTextFormatInfo = formatInfoRed;
                }
                bHandled = TRUE;
            }


 pGetSourceTextData->iData is the "Data Association" that you specify for the presenter in the XUI tool.
 pGetSourceTextData->bItemData lets you determine if the presenter is in a sub-control (item of a listbox), or the control itself.

in this case formatInfoRed looks like this:

CODE

        formatInfoRed[0].nStart = 0;
        formatInfoRed[0].nEnd = 255;
        formatInfoRed[0].dwTextColor = 0xffff0000;
        formatInfoRed[0].hBrush = NULL;


Be absolutely certain that the memory you pass as your pTextFormatInfo isn't allocated on the stack, because it's likely to be gone/different/overwritten by the time OnGetSourceDataText() gets around to actually looking at it.

-node

Title: Setting A Xuitextelement's Textcolor Property
Post by: MaesterRowen on April 15, 2010, 04:57:00 PM
CODE

        CXuiTextElement m_myText;
        HRESULT hr = GetChildById(L"TestText", &m_myText);

        XUIElementPropVal ppVal;
        DWORD dwPropId = 0;
        XuiObjectGetPropertyId(m_myText.m_hObj, L"TextColor", &dwPropId);
        ppVal.SetColorVal(0xFF,0xFF,0x00, 0x00);
        XuiObjectSetProperty(m_myText.m_hObj, dwPropId, 0, &ppVal);



This will change your TextElement to Red.

Works like a treat!
Title: Setting A Xuitextelement's Textcolor Property
Post by: node21 on April 16, 2010, 04:57:00 AM
CODE

// XuiElement property names
#define XUI_ELEM_PROP_ID        L"Id"
#define XUI_ELEM_PROP_WIDTH     L"Width"
#define XUI_ELEM_PROP_HEIGHT    L"Height"
#define XUI_ELEM_PROP_POSITION  L"Position"
#define XUI_ELEM_PROP_SCALE     L"Scale"
#define XUI_ELEM_PROP_ROTATION  L"Rotation"


So, I would never have guessed to try L"TextColor".

Interestingly enough, the sample code for XuiObjectGetPropertyId shows the use of a constant that isn't in the above list: "XUI_SCENE_TRANS_TO", So, I suppose there was a hint there...

If I would have switched to Text and Image presenters just for this I would be pissed...fortunately, I really like the way the presenters work overall anyway. :-)

-node