Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

General Open Source Topics

Reply
New Contributor
trevornunes
Posts: 3
Registered: 12-23-2011
My Carrier: Bell

TouchControlOverlay and sdl-controls.xml

Hi,

 

I've managed to port FCEUX an NES emulator sans Sound, LUA and i'm working through issues.  I can't get the SDL+TCO lib to recognise anything but a swipe down from top which pauses the game.   I can diagonal swipe to get the keyboard up but none of the event inputs are being processed.   SDL sound initialization seems to freeze but I'll discuss this in a different topic.

 

1) I need an sdl-controls.xml that maps keyboard or 'dpad' to emulator an NES controller ideally

     note that the screen initializes to PAL or NTSC sizes via SDL e.g. 256x224 

 

<?xml version="1.0" encoding="ISO-8859-1"?>
<emulation version="1">
<toucharea x="0" y="0" width="256" height="224"/>
</emulation>

 

thanks in advance,

 

Trev.

 

 

Please use plain text.
New Contributor
trevornunes
Posts: 3
Registered: 12-23-2011
My Carrier: Bell

Re: TouchControlOverlay and sdl-controls.xml

Jeremy Nicholl ( created the TCO library ) was a huge help the other day with detailed email responses so I can now define a key layout that mimics a 4 way NES PAD layout:

 

So picture an NES pad it has a 4 way 'pad' on the left, then a select ,start button in the middle and A + B on the right.  The following layout defines 4 buttons for up,down,left,right  select, start buttons and finally a,b on the top of the screen. When you swipe down TCO pauses the current running program and you can use your finger to re-position each key.  The keys show up as different coloured squares.

 

 

<?xml version="1.0" encoding="ISO-8859-1"?>
<emulation version="1">
<key x="25" y="0" width="20" height="20" scancode="13"/>
<key x="25" y="50" width="20" height="20" scancode="13"/>
<key x="0" y="25" width="20" height="20" scancode="13"/>
<key x="50" y="25" width="20" height="20" scancode="13"/>

<key x="100" y="25" width="25" height="20" scancode="13"/>
<key x="140" y="25" width="25" height="20" scancode="13"/>

<key x="200" y="25" width="20" height="20" scancode="13"/>
<key x="225" y="25" width="20" height="20" scancode="13"/>
</emulation>

 

You can expand the key to include an image ( so each key gets it's own image ) or 'mod' 'sym' mappings. A similar structure exists for 'dpad'  and 'mouse' when defining a mapping general info on TCO is here:

 

https://github.com/blackberry/TouchControlOverlay/wiki

 

 

NOTE: scancode 13 is the ENTER key, obviously in a real mapping you would map different keys, 

Please use plain text.
BlackBerry Development Advisor
epelegrillopart
Posts: 77
Registered: 10-03-2009

Re: TouchControlOverlay and sdl-controls.xml

Thanks for reporting back, Trevor.  Drop us an email if you write anything longer about it, like a post blog, or if you submit an application based on the package.

 

  - eduard/o

Please use plain text.
New Contributor
trevornunes
Posts: 3
Registered: 12-23-2011
My Carrier: Bell

Re: TouchControlOverlay and sdl-controls.xml

Just a quick update, t's the 'sym=<value>'  entry that maps key entry and not 'scancode'.  scancode is ignored same values apply ( ASCII codes ). I've uploaded the FCEUX emulator  which includes the NES pad layout sdl-controls.xml.

     

https://github.com/trevornunes/FCEUXpb

 

Please use plain text.
Contributor
boris812
Posts: 18
Registered: 02-02-2012
My Carrier: none

Re: TouchControlOverlay and sdl-controls.xml

Hi,

I'm trying to modify Lazy Foo's key presses handler to work with TouchControlOverlay. The code I'm using:

/*This source code copyrighted by Lazy Foo' Productions (2004-2012)
and may not be redestributed without written permission.*/

//The headers
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h"
#include <string>

//Screen attributes
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;

//The surfaces
SDL_Surface *background = NULL;
SDL_Surface *upMessage = NULL;
SDL_Surface *downMessage = NULL;
SDL_Surface *leftMessage = NULL;
SDL_Surface *rightMessage = NULL;
SDL_Surface *message = NULL;
SDL_Surface *screen = NULL;

//The event structure
SDL_Event event;

//The font
TTF_Font *font = NULL;

//The color of the font
SDL_Color textColor = { 0, 0, 0 };

SDL_Surface *load_image( std::string filename )
{
    //The image that's loaded
    SDL_Surface* loadedImage = NULL;

    //The optimized surface that will be used
    SDL_Surface* optimizedImage = NULL;

    //Load the image
    loadedImage = IMG_Load( filename.c_str() );

    //If the image loaded
    if( loadedImage != NULL )
    {
        //Create an optimized surface
        optimizedImage = SDL_DisplayFormat( loadedImage );

        //Free the old surface
        SDL_FreeSurface( loadedImage );

        //If the surface was optimized
        if( optimizedImage != NULL )
        {
            //Color key surface
            SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ) );
        }
    }

    //Return the optimized surface
    return optimizedImage;
}

void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
{
    //Holds offsets
    SDL_Rect offset;

    //Get offsets
    offset.x = x;
    offset.y = y;

    //Blit
    SDL_BlitSurface( source, clip, destination, &offset );
}

bool load_files()
{
    //Load the background image
    background = load_image( "app/native/background.png" );

    //Open the font
    font = TTF_OpenFont( "app/native/lazy.ttf", 72 );

    //If there was a problem in loading the background
    if( background == NULL )
    {
        return false;
    }

    //If there was an error in loading the font
    if( font == NULL )
    {
        return false;
    }

    //If everything loaded fine
    return true;
}

void clean_up()
{
    //Free the surfaces
    SDL_FreeSurface( background );
    SDL_FreeSurface( upMessage );
    SDL_FreeSurface( downMessage );
    SDL_FreeSurface( leftMessage );
    SDL_FreeSurface( rightMessage );

    //Close the font
    TTF_CloseFont( font );

    //Quit SDL_ttf
    TTF_Quit();

    //Quit SDL
    SDL_Quit();
}

int main( int argc, char* args[] )
{
    //Quit flag
    bool quit = false;

    //Initialize all SDL subsystems
	SDL_Init( SDL_INIT_EVERYTHING );

    //Set up the screen
    screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );

    //Initialize SDL_ttf
    TTF_Init();

    //Load the files
    if( load_files() == false )
    {
        return 1;
    }

    //Generate the message surfaces
    upMessage = TTF_RenderText_Solid( font, "Up was pressed.", textColor );
    downMessage = TTF_RenderText_Solid( font, "Down was pressed.", textColor );
    leftMessage = TTF_RenderText_Solid( font, "Left was pressed", textColor );
    rightMessage = TTF_RenderText_Solid( font, "Right was pressed", textColor );

    //Apply the background
    apply_surface( 0, 0, background, screen );

    //While the user hasn't quit
    while( quit == false )
    {
        //If there's an event to handle
        if( SDL_PollEvent( &event ) )
        {
            //If a key was pressed
            if( event.type == SDL_KEYDOWN )
            {
                //Set the proper message surface
                switch( event.key.keysym.sym )
                {
                    case SDLK_UP: message = upMessage; break;
                    case SDLK_DOWN: message = downMessage; break;
                    case SDLK_LEFT: message = leftMessage; break;
                    case SDLK_RIGHT: message = rightMessage; break;
                }
            }

            //If the user has Xed out the window
            else if( event.type == SDL_QUIT )
            {
                //Quit the program
                quit = true;
            }
        }

        //If a message needs to be displayed
        if( message != NULL )
        {
            //Apply the background to the screen
            apply_surface( 0, 0, background, screen );

            //Apply the message centered on the screen
            apply_surface( ( SCREEN_WIDTH - message->w ) / 2, ( SCREEN_HEIGHT - message->h ) / 2, message, screen );

            //Null the surface pointer
            message = NULL;
        }

        //Update the screen
        if( SDL_Flip( screen ) == -1 )
        {
            return 1;
        }
    }

    //Clean up
    clean_up();

    return 0;
}

 My sdl-controls.xml file (i've just put it to project directory, that's right?):

<?xml version="1.0" encoding="ISO-8859-1"?>
<emulation version="1">

	<key x="150" y="150" width="16" height="16" sym="273" scancode="273">
	<label x="0" y="0" width="16" height="16" image="R.png"/>
	</key>
	
	<key x="150" y="175" width="16" height="16" sym="274" scancode="274">
	<label x="0" y="0" width="16" height="16" image="R.png"/>
	</key>
	
	<key x="150" y="200" width="16" height="16" sym="275" scancode="275">
	<label x="0" y="0" width="16" height="16" image="R.png"/>
	</key>
	
	<key x="150" y="225" width="16" height="16" sym="276" scancode="276">
	<label x="0" y="0" width="16" height="16" image="R.png"/>
	</key>
	
</emulation>

 Well, when i click to these images, nothing happens. Can anybody please help me?

 

Please use plain text.