Results 1 to 5 of 5

Thread: Scrolling in RTSimpleApp

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

    Default Scrolling in RTSimpleApp

    Is this really the only way to set vertical limits with "scroll" content?

    Code:
    /*
    	 //this is one way to clip the image on the bottom - glClipPlane is too slow/broken on Android so we actually won't use it
    	 EntityComponent *pClip = pScroll->AddComponent(new RenderClipComponent);
    	 pClip->GetVar("clipMode")->Set(uint32(RenderClipComponent::CLIP_MODE_BOTTOM));
    	 */
    	
    	//another way would be to just blit a colored bar over the bottom:
    	//pEnt = CreateOverlayRectEntity(pBG, CL_Rectf(0, GetScreenSizeYf()-offsetFromBottom, GetScreenSizeXf(), 320), MAKE_RGBA(0,0,0,100));
    	
    	//but the nicest way is to blit a matching bar at the bottom with transparency:
    	//Entity *pOverlay = CreateOverlayEntity(pBG, "", "interface/bg_stone_overlay.rttex", 0, GetScreenSizeYf()+1); 
    	//SetAlignmentEntity(pOverlay, ALIGNMENT_DOWN_LEFT);
    I'm trying to set up a "CreateFrame" function that I then add scrollable content to:

    Code:
    	uint32 width = GetScreenSize().x;
    	uint32 height = GetScreenSize().y;
    	uint32 nBodyTop = height/10;
    	uint32 nBodyBottom = height - height/10;
    	uint32 nBodyHeight = (nBodyBottom - nBodyTop);
    	
    	Entity *pMain = pParentEnt->AddEntity(new Entity("Main"));
    	pMain->AddComponent(new FocusRenderComponent);
    	AddFocusIfNeeded(pMain);
    	
    	Entity *pHeader, *pBody, *pFooter;
    	
    	//
    	// Body
    	//
    	
    	// green overlay
    	pBody = CreateOverlayRectEntity(pMain, 
    									CL_Vec2f(0, nBodyTop), 
    									CL_Vec2f(width, nBodyHeight), 
    									MAKE_RGBA(0,200,0,100),
    									RectRenderComponent::STYLE_NORMAL);
    	pBody->SetName("body");
    	pBody->GetComponentByName("RectRender")->GetVar("borderColor")->Set(MAKE_RGBA(255,255,0,100));
    	pBody->GetComponentByName("RectRender")->GetVar("borderWeight")->Set(5.0f);
    	
    	//
    	// Header
    	//
    	pHeader = CreateOverlayRectEntity(pMain, 
    									CL_Vec2f(0, 0), 
    									CL_Vec2f(width, nBodyTop), 
    									MAKE_RGBA(0,0,0,0),
    									RectRenderComponent::STYLE_NORMAL);
    	//
    	// Footer 
    	//
    	pFooter = CreateOverlayEntity(pMain, "Logo", "interface/logo.rttex", width-100, nBodyBottom - 50);
    	pFooter->GetVar("alignment")->Set(uint32(ALIGNMENT_UPPER_RIGHT)); // TODO: don't know why it lower right isn't supported
    		
    	return pMain;
    Problem is, that function sets up 3 Entities: Header, Body and Footer. I'm then trying to add scrollable text into the Body. Seems the methods mentioned above wont work. Any suggestions?

    UPDATE: I tried this:
    Code:
    EntityComponent *pClip = pBody->AddComponent(new RenderClipComponent);
    	pClip->GetVar("clipMode")->Set(uint32(RenderClipComponent::CLIP_POSITION_FROM_SIZE));
    but it only clips the bottom.

    Also, the background color of my Body Entity changes (I'm assuming with the scroll bar) when I click on it.

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

    Default

    RenderClipComponent::CLIP_POSITION_FROM_SIZE is not implemented, only stubbed out. (check the comments by it in the .h it's defined in) - the method I had planned to use (glClipPlane) is so badly supported (only 1 at a time on iOS, and fails or is slow on many android devices) I didn't bother continuing in that path.

    So how can we clip scrolling content of "anything"? Well, the way I do it is just draw the header and footer AFTER the content, so it covers up content that is bleeding through and that works ok. (ie, nothing is really clipped, we just hide it)

    You just need to make sure pos2d and sized2d of the ScrollComponent that is attached is the content area you want to show and it should work.

    If you have any problems I'd probably need a full example to cut and paste into AboutMenu.cpp or such to really understand it.

    Also, the background color of my Body Entity changes (I'm assuming with the scroll bar) when I click on it.
    Hmm, if I had to guess it sounds like you might have your content childed to your scroll bar (bad!) or something like that, strange. (or I set a render state and don't set it back somewhere)

    You might want to compare the entity hierarchy to the example by calling GetEntityRoot()->PrintTreeAsText() after creating it as a sanity check to make sure everything is where it should be.
    Seth A. Robinson
    Robinson Technologies

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

    Default

    I tried setting bounds and position of the ScrollComponent:

    Code:
    	AddFocusIfNeeded(pBody, true, 500);
    	pBody->AddComponent(new FocusRenderComponent);
    	
    	CL_Vec2f vTextAreaPos = pBody->GetVar("pos2d")->GetVector2();
    	CL_Vec2f vTextAreaBounds = pBody->GetVar("size2d")->GetVector2();
    	
    	// make the body of the frame scrollable (quirk in P+)
    	pBody->SetName("scroll"); // TODO: hopfully renaming this doesn't cause problems 
    	pBody->AddComponent(new TouchHandlerComponent);
    	
    	pBody->AddComponent(new FilterInputComponent);
    	
    	EntityComponent* pScroll = pBody->AddComponent(new ScrollComponent);
    	pScroll->GetVar("pos2d")->Set(vTextAreaPos);
    	pScroll->GetVar("size2d")->Set(vTextAreaBounds);
    	
    	pBody->AddComponent(new ScrollBarRenderComponent); 	//also let's add a visual way to see the scroller position
    	//pScroll->GetVar("color")->Set(MAKE_RGBA(61,155, 193, 255)); 
    	pBody->AddEntity(new Entity("scroll_child"));
    and I tried adding the body entity first:

    Code:
    //
    	// Body
    	//
    	
    	// green overlay
    	pBody = CreateOverlayRectEntity(pMain, 
    									CL_Vec2f(0, nBodyTop + 1), 
    									CL_Vec2f(width, nBodyHeight), 
    									MAKE_RGBA(0,200,0,100),
    									RectRenderComponent::STYLE_NORMAL);
    	pBody->SetName("body");
    	pBody->GetComponentByName("RectRender")->GetVar("borderColor")->Set(MAKE_RGBA(255,255,0,100));
    	pBody->GetComponentByName("RectRender")->GetVar("borderWeight")->Set(5.0f);
    	pBody->GetVar("color")->Set(MAKE_RGBA(0,200,0,100));	
    	
    	//
    	// Header
    	//
    									  RectRenderComponent::STYLE_NORMAL);
    	pHeader = CreateOverlayEntity(pMain, "Header", "interface/header.rttex", 0,0);
    	
    	//
    	// Footer
    	//
    	pFooter = CreateOverlayRectEntity(pMain, 
    									CL_Vec2f(0, nBodyBottom), 
    									CL_Vec2f(width, height - nBodyBottom), 
    									MAKE_RGBA(0,0,0,100),
    									RectRenderComponent::STYLE_NORMAL);
    still not working

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

    Default

    Well, hard to say from snippets, but I think I see some problems in your code:

    Code:
    CL_Vec2f vTextAreaPos = pBody->GetVar("pos2d")->GetVector2();
    CL_Vec2f vTextAreaBounds = pBody->GetVar("size2d")->GetVector2();
    You get the position and size of "pBody" - are you sure these have been set? If not, they'll be 0...

    Then we have this:

    Code:
    	EntityComponent* pScroll = pBody->AddComponent(new ScrollComponent);
    	pScroll->GetVar("pos2d")->Set(vTextAreaPos);
    	pScroll->GetVar("size2d")->Set(vTextAreaBounds);
    This can't be right because you're setting the "pos2d" and "size2d" in the ScrollComponent, instead, you should be setting it in the Entity containing it. (In pBody)

    It will use that size to calculate how scrolling should work. If these are indeed zero, that would explain why stuff is broken.

    To debug, I'd just get the scroll window stuff working, and then add the top and bottom headers AFTERWARDS - just pretend you can't see those areas at first, until the scrolling is working right. I'd start from the example code again.
    Seth A. Robinson
    Robinson Technologies

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

    Default

    OK, going back to your RTSimpleApp code, this is the only way I was able to get a header and footer to work - 2 RenderClipComponent and 2 OverlayRectEntity:

    Code:
    Entity * AboutMenuCreate( Entity *pParentEnt)
    {
    	Entity *pBG = NULL;
    	pBG =  CreateOverlayEntity(pParentEnt, "AboutMenu", "interface/bkgd_stone.rttex", 0,0);
    	AddFocusIfNeeded(pBG, true, 500);
    	pBG->AddComponent(new FocusRenderComponent);
    
    	//setup the dimensions of where the scroll area will go
    	CL_Vec2f vTextAreaPos = iPhoneMap(5,50);
    	float offsetFromBottom = iPhoneMapY(50);
    	float offsetFromRight = iPhoneMapY(0);
    
    	CL_Vec2f vTextAreaBounds = (GetScreenSize()- CL_Vec2f(offsetFromRight,offsetFromBottom))-vTextAreaPos;
    	Entity *pScroll = pBG->AddEntity(new Entity("scroll"));
    	pScroll->GetVar("pos2d")->Set(vTextAreaPos);
    	pScroll->GetVar("size2d")->Set(vTextAreaBounds);
    	pScroll->AddComponent(new TouchHandlerComponent);
    
    	EntityComponent *pFilter = pScroll->AddComponent(new FilterInputComponent);
    	EntityComponent *pScrollComp = pScroll->AddComponent(new ScrollComponent);
    	
    	//note: If you don't want to see a scroll bar progress indicator, comment out the next line.  Also note that it only draws
    	//a vertical progress bar if needed but doesn't draw a horizontal if needed (I just haven't needed a horizontal scroll bar yet)
    	EntityComponent *pScrollBarComp = pScroll->AddComponent(new ScrollBarRenderComponent); 	//also let's add a visual way to see the scroller position
    	pScroll->GetVar("color")->Set(MAKE_RGBA(61,155, 193, 255)); 
    	Entity *pScrollChild = pScroll->AddEntity(new Entity("scroll_child"));
    	
    
    	//this is one way to clip the image on the bottom - glClipPlane is too slow/broken on Android so we actually won't use it
    	EntityComponent *pClipTop = pScroll->AddComponent(new RenderClipComponent);
    	pClipTop->GetVar("clipMode")->Set(uint32(RenderClipComponent::CLIP_MODE_TOP));
    
    	//this is one way to clip the image on the bottom - glClipPlane is too slow/broken on Android so we actually won't use it
    	EntityComponent *pClipBottom = pScroll->AddComponent(new RenderClipComponent);
    	pClipBottom->GetVar("clipMode")->Set(uint32(RenderClipComponent::CLIP_MODE_BOTTOM));
    	
    	//another way would be to just blit a colored bar over the bottom:
    	CreateOverlayRectEntity(pBG, CL_Rectf(0, 0, GetScreenSizeXf(), 50), MAKE_RGBA(0,100,0,255));
    	CreateOverlayRectEntity(pBG, CL_Rectf(0, GetScreenSizeYf()-offsetFromBottom, GetScreenSizeXf(), 768), MAKE_RGBA(0,100,0,255));
    	
    	//but the nicest way is to blit a matching bar at the bottom with transparency:
    	//Entity *pOverlay = CreateOverlayEntity(pBG, "", "interface/bg_stone_overlay.rttex", 0, GetScreenSizeYf()+1); 
    	//SetAlignmentEntity(pOverlay, ALIGNMENT_DOWN_LEFT);
    	
    	//actually add all our content
    	AboutMenuAddScrollContent(pBG);
    
    
    	//oh, let's put the Back button on the bottom bar thing
    	Entity *pEnt = CreateTextButtonEntity(pBG, "Back", 20, GetScreenSizeYf()-30, "Back", false);
    	pEnt->GetFunction("OnButtonSelected")->sig_function.connect(&AboutMenuOnSelect);
    	SetupTextEntity(pEnt, FONT_SMALL);
    	AddHotKeyToButton(pEnt, VIRTUAL_KEY_BACK); //for androids back button and window's Escape button
    
    	SlideScreen(pBG, true, 500);
    	return pBG;
    }

Similar Threads

  1. Edge scrolling in editor.
    By NovaLaw in forum Novashell Game Creation System
    Replies: 2
    Last Post: 11-20-2008, 02:25 AM
  2. Screen scrolling
    By Blint in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 08-21-2008, 08:40 PM
  3. scrolling shooter...
    By harrio in forum Novashell Game Creation System
    Replies: 2
    Last Post: 02-19-2008, 02:17 AM
  4. Scrolling to optimize?
    By Snakesoft in forum Novashell Game Creation System
    Replies: 6
    Last Post: 03-28-2007, 11:57 AM
  5. Strange scrolling bug in OSX version:
    By whisperstorm in forum Novashell Game Creation System
    Replies: 3
    Last Post: 03-22-2007, 05:20 AM

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
  •