Results 1 to 3 of 3

Thread: RectRenderComponents not registering color and other variants

  1. #1
    Lesser Wizard
    Join Date
    Nov 2010
    Location
    Los Angeles, California, United States, United States
    Posts
    126

    Default RectRenderComponents not registering color and other variants

    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:
    Code:
    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:
    Code:
    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;
    }

  2. #2
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,377

    Default

    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:

    Code:
    	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..

    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)

    Code:
    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;
    }
    Seth A. Robinson
    Robinson Technologies

  3. #3
    Lesser Wizard
    Join Date
    Nov 2010
    Location
    Los Angeles, California, United States, United States
    Posts
    126

    Default

    Ahhhh! That did it, thank you!!!

Similar Threads

  1. Change Color of Labeltext
    By Ziagl in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 06-30-2010, 04:47 PM
  2. Color-key transparency
    By MaxEd in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 01-18-2010, 10:46 PM
  3. canvas can not run in 16bit color?
    By silekey in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 09-13-2007, 02:45 AM
  4. [PATCH] Color interpolation
    By Mange in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 08-01-2007, 08:50 AM
  5. I am having color inversion problems
    By in forum Dink Smallwood HD
    Replies: 2
    Last Post: 08-13-2004, 06:50 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •