xboxscene.org forums

Author Topic: Setting A Xuitextelement's Textcolor Property  (Read 123 times)

dschu012

  • Archived User
  • Jr. Member
  • *
  • Posts: 84
Setting A Xuitextelement's Textcolor Property
« 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.
Logged

node21

  • Archived User
  • Sr. Member
  • *
  • Posts: 385
Setting A Xuitextelement's Textcolor Property
« Reply #1 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

Logged

MaesterRowen

  • Archived User
  • Newbie
  • *
  • Posts: 39
Setting A Xuitextelement's Textcolor Property
« Reply #2 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!
Logged

node21

  • Archived User
  • Sr. Member
  • *
  • Posts: 385
Setting A Xuitextelement's Textcolor Property
« Reply #3 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
Logged