PDA

View Full Version : RectRenderComponents not registering color and other variants



BigBMan
12-10-2010, 10:17 AM
Not sure what I'm doing wrong here, but all my components are rendering white, and I can't seem to be able to set other variants like border width, size, etc. I'm using the iPad simulator currently.

I have a frame generation function here:


Entity * MenuFrameCreate(Entity *pParentEnt)
{
uint32 nWidth = GetScreenSize().x;
uint32 nHeight = GetScreenSize().y;
uint32 nBodyTop = nHeight/8;
uint32 nBodyBottom = nHeight - nHeight/10;
uint32 nBodyHeight = (nBodyBottom - nBodyTop);

Entity *pMain = pParentEnt->AddEntity(new Entity("MainFrame"));
pMain->AddComponent(new FocusRenderComponent);
AddFocusIfNeeded(pMain);

Entity *pHeader, *pBody, *pFooter;
EntityComponent *pComp;

//
// Body
//
pBody = pMain->AddEntity(new Entity("body"));
pBody->GetVar("pos2d")->Set(CL_Vec2f(0, nBodyTop));
pBody->GetVar("size2d")->Set(CL_Vec2f(nWidth, nBodyHeight));

// green background
pComp = pBody->AddComponent(new RectRenderComponent);
pComp->GetVar("pos2d")->Set(CL_Vec2f(0, nBodyTop));
pComp->GetVar("size2d")->Set(CL_Vec2f(nWidth, nBodyHeight));
pComp->GetVar("color")->Set(MAKE_RGBA(0,200,0,100));

//
// Header
//
pHeader = pMain->AddEntity(new Entity("header"));
pHeader->GetVar("pos2d")->Set(CL_Vec2f(0, 0));
pHeader->GetVar("size2d")->Set(CL_Vec2f(nWidth, nBodyTop));

// black background
pComp = pHeader->AddComponent(new RectRenderComponent);
pComp->GetVar("pos2d")->Set(CL_Vec2f(0, 0));
pComp->GetVar("size2d")->Set(CL_Vec2f(nWidth, nBodyTop));
pComp->GetVar("color")->Set(MAKE_RGBA(0,0,0,255));

// header image
pComp = pHeader->AddComponent(new OverlayRenderComponent());
pComp->GetVar("fileName")->Set("interface/header.rttex"); //local to component

//
// Footer
//
pFooter = pMain->AddEntity(new Entity("footer"));
pFooter->GetVar("pos2d")->Set(CL_Vec2f(0, nBodyBottom));
pFooter->GetVar("size2d")->Set(CL_Vec2f(nWidth, nHeight - nBodyBottom));

// black background
pComp = pFooter->AddComponent(new RectRenderComponent);
pComp->GetVar("pos2d")->Set(CL_Vec2f(0, nBodyBottom));
pComp->GetVar("size2d")->Set(CL_Vec2f(nWidth, nHeight - nBodyBottom));
pComp->GetVar("color")->Set(MAKE_RGBA(0,0,0,255));

// Logo
pComp = pFooter->AddComponent(new OverlayRenderComponent());
pComp->GetVar("pos2d")->Set(CL_Vec2f(nWidth - 100, nBodyBottom));
pComp->GetVar("fileName")->Set("interface/logo.rttex");
pComp->GetVar("alignment")->Set(uint32(ALIGNMENT_UPPER_RIGHT));

return pMain;
}


And here's my body code for the main menu:


Entity * MainMenuCreate(Entity *pParentEnt)
{
// create the frame, get the body
Entity *pMain = CDMMenuFrameCreate(pParentEnt);
Entity* pBody = pMain->GetEntityByName("body");

float x, y;
float nWidth = pBody->GetVar("size2d")->GetVector2().x;
float nHeight = pBody->GetVar("size2d")->GetVector2().y;
float ySpace = nHeight/4; // TODO

y = ySpace; // start at top left
x = nWidth/2;

Entity *pEnt = CreateTextButtonEntity(pBody, "Overview", x, y, "Overview");
pEnt->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&CDMMainMenuOnSelect);
pEnt->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
SetupTextEntity(pEnt, FONT_LARGE);

y += ySpace;

pEnt = CreateTextButtonEntity(pBody, "Start", x, y, "Start");
pEnt->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&CDMMainMenuOnSelect);
pEnt->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
SetupTextEntity(pEnt, FONT_LARGE);

y += ySpace;

pEnt = CreateTextButtonEntity(pBody, "About", x, y, "About");
pEnt->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&CDMMainMenuOnSelect);
pEnt->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
SetupTextEntity(pEnt, FONT_LARGE);

// Enter our menu
SlideScreen(pMain, true);

return pMain;
}

Seth
12-10-2010, 11:12 AM
Ahh, ok, I think I see. The main problem is you are trying to use one entity for more than one visual at a time - the problem is parameters like size2d, pos2d, and color need to be set at the entity level, not the component level.

Setting those parms on a component have no effect, the reason is they are looking at their parent entity for that data - if you aren't sure if you should be setting data in the entity or the component, check the component code. this is the from the RectRenderComponent's OnAdd:


m_pColor = &GetParent()->GetShared()->GetVarWithDefault("color", Variant(MAKE_RGBA(255,255,255,255)))->GetUINT32();


Nearly all of its stuff is using GetParent(), this means the entity level is where the color is set/read, not the component. (this is by design, as main parms such as color, position, size are shared between components rather than a component having its own version)

So you might be wondering, "hey, I added three RectRenderComponents to my entity, how can I set the color and sizes for all three individually?"

Answer: You can't. Use a new entity per overlay rect that you need - entities can hold other entities so there is no problem other than extra code, and that can be minimized with helper functions like CreateOverlayEntity().

Similarly, each overlay image should be in its own entity.

Does that make sense? Yeah, it's complicated.. :sweatdrop:

Here is a corrected version, and it could be made smaller by using helper functions like CreateOverlayRectEntity (if you look its source it's basically doing the same thing, it creates an entity and puts the component in it)

Note: In the case of the rtsoft logo image on the footer, note that we DO set the filename parm at the component level, not the entity level, as this is a component specific setting. Also note that children entity coordinates are relative to their parents upper-left position. (if their parents move, everything else moves with them)



Entity * MenuFrameCreate(Entity *pParentEnt)
{
uint32 nWidth = GetScreenSize().x;
uint32 nHeight = GetScreenSize().y;
uint32 nBodyTop = nHeight/8;
uint32 nBodyBottom = nHeight - nHeight/10;
uint32 nBodyHeight = (nBodyBottom - nBodyTop);

Entity *pMain = pParentEnt->AddEntity(new Entity("MainFrame"));
pMain->AddComponent(new FocusRenderComponent);
AddFocusIfNeeded(pMain);

Entity *pHeader, *pBody, *pFooter;
EntityComponent *pComp;

//
// Body
//
pBody = pMain->AddEntity(new Entity("body"));
pBody->GetVar("pos2d")->Set(CL_Vec2f(0, nBodyTop));
pBody->GetVar("size2d")->Set(CL_Vec2f(nWidth, nBodyHeight));
pBody->GetVar("color")->Set(MAKE_RGBA(0,200,0,100));

// green background
pComp = pBody->AddComponent(new RectRenderComponent);

//
// Header
//
pHeader = pMain->AddEntity(new Entity("header"));
pHeader->GetVar("pos2d")->Set(CL_Vec2f(0, 0));
pHeader->GetVar("size2d")->Set(CL_Vec2f(nWidth, nBodyTop));
pHeader->GetVar("color")->Set(MAKE_RGBA(0,0,0,255));

// black background
pComp = pHeader->AddComponent(new RectRenderComponent);

// header image
//pComp = pHeader->AddComponent(new OverlayRenderComponent());
//pComp->GetVar("fileName")->Set("interface/header.rttex"); //local to component

CreateOverlayEntity(pHeader, "logo", "interface/proton-128.rttex",0,0); //coords local to the header position

//
// Footer
//
pFooter = pMain->AddEntity(new Entity("footer"));
pFooter->GetVar("pos2d")->Set(CL_Vec2f(0, nBodyBottom));
pFooter->GetVar("size2d")->Set(CL_Vec2f(nWidth, nHeight - nBodyBottom));
pFooter->GetVar("color")->Set(MAKE_RGBA(0,0,0,255));

// black background
pComp = pFooter->AddComponent(new RectRenderComponent);

// Logo
Entity *pLogoEnt = pFooter->AddEntity(new Entity("logo"));
pLogoEnt->GetVar("pos2d")->Set(CL_Vec2f(0,0)); //coords relative to the footer, as its our parent
pComp = pLogoEnt->AddComponent(new OverlayRenderComponent());
pComp->GetVar("fileName")->Set("interface/rtsoft_logo.rttex");


return pMain;
}

BigBMan
12-10-2010, 08:07 PM
Ahhhh! That did it, thank you!!!