Esempio n. 1
0
	//! constructor
	CIrrDeviceMarmalade::CIrrDeviceMarmalade(const SIrrlichtCreationParameters& param)
		: CIrrDeviceStub(param), Paused(false)
	{
		initKeyMap();

		CursorControl = new CMarmaladeCursor(this);

		//video::SExposedVideoData data;

		SIrrlichtCreationParameters params = param;
		params.WindowSize.Width = s3eSurfaceGetInt(S3E_SURFACE_WIDTH);
		params.WindowSize.Height = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT);

		int32 glver = s3eGLGetInt(S3E_GL_VERSION);
		if(glver >= 0x200)
			VideoDriver = video::createOGLES2Driver(params, FileSystem);
		else
			VideoDriver = video::createOGLES1Driver(params, FileSystem);

        glViewport(0, 0, params.WindowSize.Width, params.WindowSize.Height);

		if (VideoDriver)
			createGUIAndScene();

		s3eDeviceRegister(S3E_DEVICE_EXIT, &do_Exit, this);
		s3eDeviceRegister(S3E_DEVICE_PAUSE, &do_Pause, this);
		s3eDeviceRegister(S3E_DEVICE_UNPAUSE, &do_Unpause, this);

		s3eKeyboardRegister(S3E_KEYBOARD_KEY_EVENT, &do_KeyEvent, this);
		s3eKeyboardRegister(S3E_KEYBOARD_CHAR_EVENT, &do_CharEvent, this);
	}
void DrawRect(int x, int y, int width, int height, uint8 r, uint8 g, uint8 b)
{
    int right = x + width;
    int bottom = y + height;
    if (x < 0)
        x = 0;
    if (y < 0)
        y = 0;
    if (right > (int32)s3eSurfaceGetInt(S3E_SURFACE_WIDTH))
        right = s3eSurfaceGetInt(S3E_SURFACE_WIDTH);
    if (bottom > (int32)s3eSurfaceGetInt(S3E_SURFACE_HEIGHT))
        bottom = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT);

    // Draw the text
    IwGxSetScreenSpaceSlot(0);

    CIwMaterial *fadeMat = IW_GX_ALLOC_MATERIAL();
    fadeMat->SetAlphaMode(CIwMaterial::NONE);
    fadeMat->SetShadeMode(CIwMaterial::SHADE_FLAT);
    IwGxSetMaterial(fadeMat);

    CIwColour* cols = IW_GX_ALLOC(CIwColour, 4);
    for (int i = 0; i < 4; i++)
        cols[i].Set(r, g, b);

    CIwSVec2 xy(x, y);
    CIwSVec2 wh(width, height);
    IwGxDrawRectScreenSpace(&xy, &wh, cols);
}
int main()
{
	IwGxInit();
	IwGxSetColClear(0, 0, 0xff, 0xff);
	IwResManagerInit();
	Iw2DInit();
	setupTextures();
	registerInput();

    const int textWidth = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_WIDTH);
    const int textHeight = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_HEIGHT);
    const int width = s3eSurfaceGetInt(S3E_SURFACE_WIDTH);
    const int height = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT);

	sprintf(g_debugButtonEvent, "ButtonEvent:");
	sprintf(g_debugKeyEvent, "KeyEvent:");
	sprintf(g_debugMotionEvent, "MotionEvent:");
	sprintf(g_debugTouchEvent, "TouchEvent:");
	sprintf(g_debugTouchMotionEvent, "TouchMotionEvent:");

	while (!s3eDeviceCheckQuitRequest())
	{
		render();

		// Yield until unyield is called or a quit request is recieved
        s3eDeviceYield(S3E_DEVICE_YIELD_FOREVER);
	}
	destroyTextures();
	Iw2DTerminate();
	IwResManagerTerminate();
	IwGxTerminate();
	return 0;
}
/**
* Constructor
* @param pImage the image to use for the trap
* @param pPos the position of the trap
* @param pWorld the physics world the trap is to be added to
*/
BladeTrap::BladeTrap(const char* pImgName, CIwSVec2 pPos, b2World* pWorld): 
	Trap(pImgName, pPos),
	mFrame(0),
	mFrames(3) {


	float X = (((-(s3eSurfaceGetInt(S3E_SURFACE_HEIGHT)/64)*4)+(0.5*4))+(pPos.x*4)) + 0.5;
	float Y = ((((s3eSurfaceGetInt(S3E_SURFACE_WIDTH)/64)*4)-(0.5*4)) + (-pPos.y*4)) - 0.5;
	X = -(768/16) + (0.5*4) + (pPos.x*4) + 0.5;
	Y = (1024/16) - (0.9*4) - (pPos.y*4) - 0.5;
	b2BodyDef bodyDef;
	bodyDef.type = b2_staticBody;
	bodyDef.position.Set(X, Y);

	mBody = pWorld->CreateBody(&bodyDef);
	mBody->SetFixedRotation(true);

	mType = "spikeTrap";

	b2CircleShape shape;
	shape.m_radius = 4.3f;
	b2FixtureDef fd;
	fd.shape = &shape;
	fd.filter.categoryBits = Constants::TRAP;
	fd.filter.maskBits = Constants::ENEMY | Constants::PLAYER | Constants::OBJECT;
	fd.isSensor = true;
	fd.userData = mType;

	mBody->CreateFixture(&fd);
	mBody->SetUserData(this);
}
static void CursorRender()
{
    if (!s3ePointerGetInt(S3E_POINTER_AVAILABLE))
        return;

    uint16* ptr = (uint16*)s3eSurfacePtr();
    int height = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT);
    int width = s3eSurfaceGetInt(S3E_SURFACE_WIDTH);
    int pitch = s3eSurfaceGetInt(S3E_SURFACE_PITCH);

    int pointerx = s3ePointerGetX();
    int pointery = s3ePointerGetY();

    pointerx = (pointerx > width)?width-1:pointerx;
    pointery = (pointery > height)?height-1:pointery;

    int cursor_size = 10;

    for (int y = pointery-cursor_size; y < pointery+cursor_size; y++)
    {
        if (y < 0 || y >= height)
            continue;
        int location = y*pitch/sizeof(uint16) + pointerx;
        ptr[location] = 0x5555;
    }

    for (int x = pointerx-cursor_size; x < pointerx+cursor_size; x++)
    {
        if (x < 0 || x >= width)
            continue;
        int location = pointery*pitch/sizeof(uint16) + x;
        ptr[location] = 0x5555;
    }
}
// Rotate the layout on rotation
static int HelloWorldRotationCallBack(void* systemData, void* userData)
{
	s3eSurfaceClear(0, 0, 255);
    const int width  = s3eSurfaceGetInt(S3E_SURFACE_WIDTH);
    const int height = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT);
	return 0;
}
Esempio n. 7
0
void fillScreen(uint8 r, uint8 g, uint8 b)
{
    uint16* screen = (uint16*)s3eSurfacePtr();
    uint16  colour = (uint16)s3eSurfaceConvertRGB(r,g,b);
    int32 width = s3eSurfaceGetInt(S3E_SURFACE_WIDTH);
    int32 height = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT);
    int32 pitch = s3eSurfaceGetInt(S3E_SURFACE_PITCH);
    for (int y = 0; y < height; y++)
        for (int x = 0; x < width; x++)
            screen[y * pitch/2 + x] = colour;
}
void HelloWorldInit()
{
	// Fill background blue
        s3eSurfaceClear(0, 0, 255);
		int scale;
		if (s3eSurfaceGetInt(S3E_SURFACE_WIDTH) < 320 || s3eSurfaceGetInt(S3E_SURFACE_HEIGHT) < 320)
        scale = 1;
		else if (s3eSurfaceGetInt(S3E_SURFACE_WIDTH) < 480 || s3eSurfaceGetInt(S3E_SURFACE_HEIGHT) < 480)
        scale = 2;
		else
        scale = 3;
		s3eDebugSetInt(S3E_DEBUG_FONT_SCALE, scale);
		s3eSurfaceRegister(S3E_SURFACE_SCREENSIZE, HelloWorldRotationCallBack, NULL);
}
void DrawRect(int x, int y, int width, int height, uint8 r, uint8 g, uint8 b)
{
    int right = x + width;
    int bottom = y + height;
    int pitch = s3eSurfaceGetInt(S3E_SURFACE_PITCH);
    if (x < 0)
        x = 0;
    if (y < 0)
        y = 0;
    if (right > (int32)s3eSurfaceGetInt(S3E_SURFACE_WIDTH))
        right = s3eSurfaceGetInt(S3E_SURFACE_WIDTH);
    if (bottom > (int32)s3eSurfaceGetInt(S3E_SURFACE_HEIGHT))
        bottom = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT);

    uint16* pSurface = (uint16*)s3eSurfacePtr();
    pitch /= 2;
    uint16 colour = (uint16)s3eSurfaceConvertRGB(r,g,b);

    if (((right - x) & 0x3) == 0)
    {
        for (int _y = y; _y < bottom; _y++)
        {
            uint16* p = pSurface + _y*pitch + x;
            uint16* pEnd = p + right - x;

            do
            {
                *p++ = colour;
                *p++ = colour;
                *p++ = colour;
                *p++ = colour;
            } while (p != pEnd);
        }
    }
    else
    {
        for (int _y = y; _y < bottom; _y++)
        {
            uint16* p = pSurface + _y*pitch + x;
            uint16* pEnd = p + right - x;

            do
            {
                *p++ = colour;
            } while (p != pEnd);
        }
    }
}
Esempio n. 10
0
void onRender() {
	// Get pointer to the screen surface
	// (pixel depth is 2 bytes by default)
	uint16* screen = (uint16*)s3eSurfacePtr();
	int height = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT);
	int width = s3eSurfaceGetInt(S3E_SURFACE_WIDTH);
	int pitch = s3eSurfaceGetInt(S3E_SURFACE_PITCH);
	
	// Clear screen to white
	for (int i=0; i < height; i++)
	{
		memset((char*)screen + pitch * i, 255, (width * 2));
	}
	// Print Hello World
	s3eDebugPrint(10, 20, "`x000000Hello World", 0);
}
int PrintMessages(int x, int y)
{
    if (!g_NumMessages || g_MessageIdx == -1)
        return -1;

    char* currentMsg;

    for (int i=0, j = g_MessageIdx; i < g_NumMessages; i++, j = (j + (g_NumMessages-1)) % g_NumMessages)
    {
        // Avoid overlapping exit button
        if (y > s3eSurfaceGetInt(S3E_SURFACE_HEIGHT) - (s3eDebugGetInt(S3E_DEBUG_FONT_HEIGHT)*2))
            break;

        if (j > g_MessageIdx && !g_LoopMessages)
            continue;

        currentMsg = g_Messages[j];
        if (currentMsg[0])
        {
            s3eDebugPrintf(x, y, 0, "%s", currentMsg);

            if (i != g_NumMessages -1)
                y += s3eDebugGetInt(S3E_DEBUG_FONT_HEIGHT)+2;
        }
    }

    return y;
}
Esempio n. 12
0
// Helper function to display message for Debug-Only Examples
void DisplayMessage(const char* strmessage)
{
    uint16* screen = (uint16*)s3eSurfacePtr();
    int32 width     = s3eSurfaceGetInt(S3E_SURFACE_WIDTH);
    int32 height    = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT);
    int32 pitch     = s3eSurfaceGetInt(S3E_SURFACE_PITCH);
    for (int y = 0; y < height; y++)
    for (int x = 0; x < width; x++)
        screen[y * pitch/2 + x] = 0;
    s3eDebugPrint(0, 10, strmessage, 1);
    s3eSurfaceShow();
    while (!s3eDeviceCheckQuitRequest() && !s3eKeyboardAnyKey())
    {
        s3eDeviceYield(0);
        s3eKeyboardUpdate();
    }
}
Esempio n. 13
0
void motionEvent(s3ePointerMotionEvent *event)
{
    IW_CALLSTACK("motionEvent");

    height = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT);

    touchHeight = (float)event->m_y;
    rpm = (float)event->m_y / (float)height * (10000.0f - 1000.0f) + 1000.0f;
    s3eWwiseSoundEngineSetRTPCValueWithID(AK::GAME_PARAMETERS::RPM, rpm, carID);
}
Esempio n. 14
0
void Input_Engine::TransformTouch(Touch &_touch)
{
    int screenWidth = s3eSurfaceGetInt(S3E_SURFACE_WIDTH);
    int screenHeight = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT);
    m_widthFactor = 320.0f/screenWidth;
    m_heightFactor = 480.0f/screenHeight;

    _touch.X *= m_widthFactor;
    _touch.Y *= m_heightFactor;

    /*if(s3eDeviceGetInt(S3E_DEVICE_OS) == S3E_OS_ID_IPHONE)
    {
    	if(hooptyFlip == S3E_SURFACE_BLIT_DIR_ROT270)
    	{
    		_touch.Y = 320 - _touch.Y;
    		_touch.X = 480 - _touch.X;
    	}
    }	*/
}
Esempio n. 15
0
bool MapBackground::CalculateTiles()
{
	if (g_bLocationChanged)
	{
		g_bLocationChanged = false;
		GPSRectangle x;
		std::list<MapTile*> vectorImages;

		int width = Iw2DGetSurfaceWidth();
		int height = Iw2DGetSurfaceHeight();

		float offset = 1 + (ceil(g_tempZoom) - g_tempZoom);
		LiveMaps::GetLocationImages(&vectorImages, &g_rows, &g_cols, &gLocation, (int)(width * offset), (int)(height * offset), &g_corners, &x, ceil(g_tempZoom), &g_latPerPixel, &g_lonPerPixel);

		int count = vectorImages.size();

		if (offset > 1)
		{
			int xOffset = width * (offset - 1) / 2;
			int yOffset = height * (offset - 1) / 2;

			std::list<MapTile*>::iterator iter1 = vectorImages.begin();

			while (iter1 != vectorImages.end())
			{
				MapTile* pTile = *iter1;

				pTile->location.x -= xOffset;
				pTile->location.y -= yOffset;

				iter1++;
			}
		}

		ProcessNewDownloads(&vectorImages);
		gScaler->SetCorners(&g_corners, g_actualZoom, false);

		g_Width = s3eSurfaceGetInt(S3E_SURFACE_WIDTH);
		g_Height = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT);
	}

	return true;
}
static void SoftkeyRender(const char* text, s3eDeviceSoftKeyPosition pos, void(*handler)())
{
    // Get area of text displayed
    int width = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_WIDTH);
    int height = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_HEIGHT);
    width *= strlen(text) - 8; //-8 to ignore colour flag (e.g. "`x666666")

    // Expand area by half text height to make easier to click
    width += height;
    height += height;

    int x = 0;
    int y = 0;
    switch (pos)
    {
        case S3E_DEVICE_SOFTKEY_BOTTOM_LEFT:
            y = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT) - height;
            x = 0;
            break;
        case S3E_DEVICE_SOFTKEY_BOTTOM_RIGHT:
            y = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT) - height;
            x = s3eSurfaceGetInt(S3E_SURFACE_WIDTH) - width;
            break;
        case S3E_DEVICE_SOFTKEY_TOP_RIGHT:
            y = 0;
            x = s3eSurfaceGetInt(S3E_SURFACE_WIDTH) - width;
            break;
        case S3E_DEVICE_SOFTKEY_TOP_LEFT:
            x = 0;
            y = 0;
            break;
    }
    s3eDebugPrint(x + (height/4), y + (height/4), text, 0); // place in centre of touchable area
    if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED)
    {
        int pointerx = s3ePointerGetX();
        int pointery = s3ePointerGetY();
        if (pointerx >= x && pointerx <= x+width && pointery >=y && pointery <= y+height)
            handler();
    }
}
Esempio n. 17
0
void ExampleRender()
{
    // Get pointer to the screen surface
    // (pixel depth is 2 bytes by default)
    uint16* screen = (uint16*)s3eSurfacePtr();
    int height = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT);
    int width = s3eSurfaceGetInt(S3E_SURFACE_WIDTH);
    int pitch = s3eSurfaceGetInt(S3E_SURFACE_PITCH);
    
    // Clear screen to white
    for (int i=0; i < height; i++)
    {
        memset((char*)screen + pitch * i, 255, (width * 2));
    }
    
    // This was causing an error to pop up.
    s3ePointerUpdate();
    
    ButtonsRender();
    
    s3eDebugPrint(20, 365, g_TouchEventMsg, 1);
}
Esempio n. 18
0
void LevelSelectMainInit()
{
    // Determine if the device has a keyboard
    if (s3eKeyboardGetInt(S3E_KEYBOARD_HAS_KEYPAD) || s3eKeyboardGetInt(S3E_KEYBOARD_HAS_ALPHA))
        g_DeviceHasKeyboard = true;

    int scale = 1;
    // Set default button size relative to screen resolution
    if (s3eSurfaceGetInt(S3E_SURFACE_WIDTH) < 320 || s3eSurfaceGetInt(S3E_SURFACE_HEIGHT) < 320)
        scale = 1;
    else if (s3eSurfaceGetInt(S3E_SURFACE_WIDTH) < 480 || s3eSurfaceGetInt(S3E_SURFACE_HEIGHT) < 480)
        scale = 2;
    else
        scale = 3;

    SetButtonScale(scale);

    // Scale font up to be easier to read
    int fontScale = scale > 1 ? scale-1 : 1;
    s3eDebugSetInt(S3E_DEBUG_FONT_SCALE, fontScale);
    LevelInit();
}
Esempio n. 19
0
Input_Engine::Input_Engine()
{
    input_controller = NULL;
    ref_count = 0;
    if( s3ePointerGetInt(S3E_POINTER_MULTI_TOUCH_AVAILABLE) )
    {
        //Register for multi touch events on platforms where the functionality is available.
        s3ePointerRegister(S3E_POINTER_TOUCH_EVENT, (s3eCallback)MultiTouchButtonCB, NULL);
        s3ePointerRegister(S3E_POINTER_TOUCH_MOTION_EVENT, (s3eCallback)MultiTouchMotionCB, NULL);
    }
    else
    {
        //Register for standard pointer events
        s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, (s3eCallback)SingleTouchButtonCB, NULL);
        s3ePointerRegister(S3E_POINTER_MOTION_EVENT, (s3eCallback)SingleTouchMotionCB, NULL);
    }
    //s3eKeyboardRegister(S3E_KEYBOARD_KEY_EVENT, keyboardHandler, NULL);

    int screenWidth = s3eSurfaceGetInt(S3E_SURFACE_WIDTH);
    int screenHeight = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT);
    m_widthFactor = 320.0f/screenWidth;
    m_heightFactor = 480.0f/screenHeight;
}
Esempio n. 20
0
		Point getDisplaySize()
		{
	#if __S3E__
			int width = IwGLGetInt(IW_GL_WIDTH);
			int height = IwGLGetInt(IW_GL_HEIGHT);

			int orient = s3eSurfaceGetInt(S3E_SURFACE_DEVICE_ORIENTATION_LOCK);
			if (height > width)
			{
				if (orient == S3E_SURFACE_LANDSCAPE || orient == S3E_SURFACE_LANDSCAPE_FIXED)
					swap(width, height);
			}
			else
			{
				if (orient == S3E_SURFACE_PORTRAIT || orient == S3E_SURFACE_PORTRAIT_FIXED)
					swap(width, height);
			}

			return Point(width, height);
	#endif
	
	#ifdef OXYGINE_QT
			if (!_window)
			{
				return _qtFixedSize;
			}
	#endif

	#if OXYGINE_SDL
			int w = 0;
			int h = 0;
			SDL_GetWindowSize(_window, &w, &h);
			return Point(w, h);
	#endif

	#if EMSCRIPTEN
			return _displaySize;
	#endif

	#if	__FLASHPLAYER__
			return Point(800, 600);
	#endif
			log::warning("getDisplaySize not implemented");
			return Point(0, 0);
		}
Esempio n. 21
0
long UpdateScreenOrientation()
{
    int rot = s3eSurfaceGetInt(S3E_SURFACE_DEVICE_BLIT_DIRECTION);
    if (rot == S3E_SURFACE_BLIT_DIR_NORMAL)
    {
        s_OrientationCompensation.SetIdentity();
    }
    else if (rot == S3E_SURFACE_BLIT_DIR_ROT90)
    {
        s_OrientationCompensation.SetRotZ(0x0c00);
    }
    else if (rot == S3E_SURFACE_BLIT_DIR_ROT180)
    {
        s_OrientationCompensation.SetRotZ(0x800);
    }
    else if (rot == S3E_SURFACE_BLIT_DIR_ROT270)
    {
        s_OrientationCompensation.SetRotZ(0x400);
    }
    return 0;
}
Esempio n. 22
0
        void init(init_desc* desc_ptr)
        {
            Input::instance.__removeFromDebugList();

            log::messageln("initialize oxygine");
            if (desc_ptr)
                desc = *desc_ptr;

#ifdef __S3E__
            log::messageln("S3E build");
            if (!IwGLInit())
            {
                s3eDebugErrorShow(S3E_MESSAGE_CONTINUE, "IwGLInit failed");
                return;
            }
            //init_ext();

            int width = IwGLGetInt(IW_GL_WIDTH);
            int height = IwGLGetInt(IW_GL_HEIGHT);

            log::messageln("Screen BPP  : %d", s3eSurfaceGetInt(S3E_SURFACE_PIXEL_TYPE) & S3E_SURFACE_PIXEL_SIZE_MASK);
            log::messageln("Screen Size : %dx%d", width, height);
            log::messageln("Vendor      : %s", (const char*)glGetString(GL_VENDOR));
            log::messageln("Renderer    : %s", (const char*)glGetString(GL_RENDERER));

            const char* version = (const char*)glGetString(GL_VERSION);
            log::messageln("Version    : %s", version);

            s3ePointerUpdate();
            if (s3ePointerGetInt(S3E_POINTER_MULTI_TOUCH_AVAILABLE))
            {
                s3ePointerRegister(S3E_POINTER_TOUCH_EVENT, &pointerTouchEvent, 0);
                s3ePointerRegister(S3E_POINTER_TOUCH_MOTION_EVENT, &pointerTouchMotionEvent, 0);
            }
            else
            {
                s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, &pointerEvent, 0);
                s3ePointerRegister(S3E_POINTER_MOTION_EVENT, &pointerMotionEvent, 0);
            }

            s3eDeviceRegister(S3E_DEVICE_UNPAUSE, applicationUnPause, 0);
            s3eDeviceRegister(S3E_DEVICE_PAUSE, applicationPause, 0);

#elif EMSCRIPTEN
            log::messageln("EMSCRIPTEN build");

            if (desc.w == -1 && desc.h == -1)
            {
                int fs = 0;
                emscripten_get_canvas_size(&desc.w, &desc.h, &fs);
            }

            if (SDL_Init(SDL_INIT_VIDEO) != 0)
            {
                log::error("Unable to initialize SDL: %s\n", SDL_GetError());
            }

            SDL_Surface* screen;
            screen = SDL_SetVideoMode(desc.w, desc.h, 32, SDL_OPENGL);
            _displaySize = Point(desc.w, desc.h);

            emscripten_SDL_SetEventHandler(SDL_eventsHandler, 0);

            int v = EM_ASM_INT(
            {
                var p = navigator.platform;
                if (p == 'iPad' || p == 'iPhone' || p == 'iPod')
                    return 1;
                return 0;
            }, 0);
Esempio n. 23
0
void ButtonsRender()
{
    int previousDebugTextSize = s3eDebugGetInt(S3E_DEBUG_FONT_SCALE);
    int fontScale = g_ButtonScale;
    char buf[128];

    // select double sized text
    if (previousDebugTextSize != (int)g_ButtonScale)
        s3eDebugSetInt(S3E_DEBUG_FONT_SCALE, g_ButtonScale);

    // find out the dimensions of the font
    const int textWidthDefault = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_WIDTH);
    const int textHeight = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_HEIGHT);

    // get the current pointer position and selection state
    int pointerX = s3ePointerGetX();
    int pointerY = s3ePointerGetY();
    s3ePointerState pointerState = s3ePointerGetState(S3E_POINTER_BUTTON_SELECT);

    int x = 10;
    int y = 50;
    
    g_SelectedButton = 0;

    // draw the buttons
    for (Button* iter = g_ButtonsHead; iter; iter = iter->m_Next)
    {
        if (!iter->m_Display)
            continue;

        if (g_HideDisabledButtons && !iter->m_Enabled)
            continue;

        fontScale = g_ButtonScale;
        int textWidth = textWidthDefault;
        if (s3eDebugGetInt(S3E_DEBUG_FONT_SCALE) != fontScale)
            s3eDebugSetInt(S3E_DEBUG_FONT_SCALE, fontScale);

        if (iter->m_Key != S3E_KEY_INVALID)
        {
            if (s3eKeyboardGetState(iter->m_Key) & S3E_KEY_STATE_PRESSED)
            {
                g_SelectedButton = iter;
                s3eDebugTracePrintf("button selected using key");
            }
        }

        if (iter->m_Key != S3E_KEY_INVALID)
        {
            char keyName[32];
            s3eKeyboardGetDisplayName(keyName, iter->m_Key);
            if (iter->m_Enabled)
                snprintf(buf, sizeof(buf), "`x000000%s: %s", keyName, iter->m_Name);
            else
                snprintf(buf, sizeof(buf), "`xa0a0a0%s: %s", keyName, iter->m_Name);
        }
        else
        {
            if (iter->m_Enabled)
                snprintf(buf, sizeof(buf), "`x000000%s", iter->m_Name);
            else
                snprintf(buf, sizeof(buf), "`xa0a0a0%s", iter->m_Name);
        }

        int len = strlen(buf) - 8;
        int _x0 = x - 2;
        int _y0 = y - 4;
        int _h = textHeight + 4;
        int _y1 = _y0 + _h;
        int _w;
        int _x1;
        int textOffset = 0;
        
        // Scale down font size if button contents are too long for screen
        while (true)
        {
            _w = (textWidth * len) + 8;
            
            _x1 = _x0 + _w;

            if (fontScale == 1 || _x1 <= s3eSurfaceGetInt(S3E_SURFACE_WIDTH))
                break;

            fontScale -= 1;
            s3eDebugSetInt(S3E_DEBUG_FONT_SCALE, fontScale);
            textWidth = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_WIDTH);
            textOffset += (textHeight-s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_HEIGHT))/2;
        }

        if (pointerX >= _x0 && pointerX <= _x1 &&
            pointerY >= _y0 && pointerY <= _y1 && iter->m_Enabled)
        {
            if (pointerState & S3E_POINTER_STATE_DOWN)
                DrawRect(_x0, _y0, _w, _h, 0, 255, 0);
            else
                DrawRect(_x0, _y0, _w, _h, 255, 0, 0);

            if (pointerState & S3E_POINTER_STATE_RELEASED)
                g_SelectedButton = iter;
        }
        else
        {
            if (iter->m_Enabled)
                DrawRect(_x0, _y0, _w, _h, 255, 0, 0);
            else
                DrawRect(_x0, _y0, _w, _h, 127, 0, 0);
        }

        s3eDebugPrint(x, y+textOffset,  buf, 0);

        // Store button's position and size
        iter->m_XPos = _x0;
        iter->m_YPos = _y0;
        iter->m_Width = _w;
        iter->m_Height = _h;

        y = y + textHeight * 2;
    }

    if (g_SelectedButton && g_SelectedButton->m_Callback)
        g_SelectedButton->m_Callback(g_SelectedButton);

    if (previousDebugTextSize != fontScale)
        s3eDebugSetInt(S3E_DEBUG_FONT_SCALE, previousDebugTextSize);

    g_YBelowButtons = y;
}
void createButton(char* p_btnName)
{
	// Draw button area
	int fontWidth = s3eDebugGetInt(S3E_DEBUG_FONT_WIDTH);
	int x,y,width;
	if(p_btnName != NULL && strlen(p_btnName) > 1)
		width = strlen(p_btnName)*fontWidth+10;
	int height = 40;
	//x = IwGxGetScreenWidth() - width;
	x = s3eSurfaceGetInt(S3E_SURFACE_WIDTH) - width;
	y = 2;
	 if (!(s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_UP))
    {
        int pointerx = s3ePointerGetX();
        int pointery = s3ePointerGetY();
		if (pointerx >=x && pointerx <= x+width && pointery >=y && pointery <= y+height)
        {
            if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN)
            {
                keyPressedState = S3E_KEY_STATE_DOWN;
            }
            if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED)
            {
                keyPressedState = S3E_KEY_STATE_PRESSED;
            }
			if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_RELEASED)
            {
                keyPressedState = S3E_KEY_STATE_RELEASED;
				s3eDebugTraceLine("-------------Example Update Key Released-------------------");
            }
        }
    }

	if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_RELEASED)
	{
		char color[64] = "`xe0ff00"; 
		char* dispText = strcat(color,p_btnName);
		s3eDebugPrint(x+5, 20,  dispText, 0);
	}

	 if (s3ePointerGetInt(S3E_POINTER_AVAILABLE))
    {
        if (keyPressedState == S3E_KEY_STATE_DOWN)
		{
			char color[64] = "`xe0ff00"; 
			char* dispText = strcat(color,p_btnName);
			s3eDebugPrint(x+5, 20,  dispText, 0);
		}
		else if(keyPressedState == S3E_KEY_STATE_PRESSED)
		{
			DrawButtonRect(x, y, width, height,97,97,249);
			char color[64] = "`xe0ff00"; 
			char* dispText = strcat(color,p_btnName);
			s3eDebugPrint(x+5, 20,  dispText, 0);
		}
		else if(keyPressedState == S3E_KEY_STATE_RELEASED)
		{
			s3eSurfaceClear(0,0,0);
			char color[64] = "`xe0ff00"; 
			char* dispText = strcat(color,p_btnName);
			s3eDebugPrint(x+5, 20,  dispText, 0);
		}
		else
		{
			char color[64] = "`xD8F809";
			char* dispText = strcat(color,p_btnName);
			s3eDebugPrint(x+5, 20,  dispText, 0);
		}
    }
}
Esempio n. 25
0
		void init(init_desc *desc_ptr)
		{
			Input::instance.__removeFromDebugList();

			log::messageln("initialize oxygine");
			if (desc_ptr)
				desc = *desc_ptr;

#ifdef __S3E__
			log::messageln("S3E build");
			if (!IwGLInit())
			{
				s3eDebugErrorShow(S3E_MESSAGE_CONTINUE, "IwGLInit failed");
				return;
			}
			//init_ext();

			int width = IwGLGetInt(IW_GL_WIDTH);
			int height = IwGLGetInt(IW_GL_HEIGHT);

			log::messageln("Screen BPP  : %d", s3eSurfaceGetInt(S3E_SURFACE_PIXEL_TYPE) & S3E_SURFACE_PIXEL_SIZE_MASK);
			log::messageln("Screen Size : %dx%d", width, height);
			log::messageln("Vendor      : %s", (const char*)glGetString( GL_VENDOR ) );
			log::messageln("Renderer    : %s", (const char*)glGetString( GL_RENDERER ));

			const char *version = (const char*)glGetString( GL_VERSION );
			log::messageln( "Version    : %s", version);

			s3ePointerUpdate();
			if (s3ePointerGetInt(S3E_POINTER_MULTI_TOUCH_AVAILABLE))
			{
				s3ePointerRegister(S3E_POINTER_TOUCH_EVENT, &pointerTouchEvent, 0);
				s3ePointerRegister(S3E_POINTER_TOUCH_MOTION_EVENT, &pointerTouchMotionEvent, 0);
			}
			else
			{
				s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, &pointerEvent, 0);
				s3ePointerRegister(S3E_POINTER_MOTION_EVENT, &pointerMotionEvent, 0);
			}	

			s3eDeviceRegister(S3E_DEVICE_UNPAUSE, applicationUnPause, 0);
			s3eDeviceRegister(S3E_DEVICE_PAUSE, applicationPause, 0);
#elif EMSCRIPTEN
			log::messageln("EMSCRIPTEN build");

			if (desc.w == -1 && desc.h == -1)
			{
				int fs = 0;
				emscripten_get_canvas_size(&desc.w, &desc.h, &fs);
			}

			if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) 
			{
				log::error("Unable to initialize SDL: %s\n", SDL_GetError());				
			}

			SDL_Surface *screen;
			screen = SDL_SetVideoMode(desc.w, desc.h, 32, SDL_OPENGL); 
			_displaySize = Point(desc.w, desc.h);

			emscripten_SDL_SetEventHandler(SDL_eventsHandler, 0);
#elif OXYGINE_SDL

			log::messageln("SDL build");
			

			SDL_Init(SDL_INIT_VIDEO);


			SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
			SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
			SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
			SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
			SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
			SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0);
			//SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
			SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
			SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
			SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);

			int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;

#if TARGET_OS_IPHONE
			flags |= SDL_WINDOW_BORDERLESS;
#endif                

			SDL_DisplayMode mode;
			SDL_GetCurrentDisplayMode(0, &mode);
			log::messageln("display mode: %d %d", mode.w, mode.h);

			if (desc.w == -1 && desc.h == -1)
			{
				desc.w = 960;
				desc.h = 640;
			}

			if (desc.fullscreen)
				flags |= SDL_WINDOW_FULLSCREEN;

			log::messageln("creating window %d %d", desc.w, desc.h);

			_window = SDL_CreateWindow(desc.title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, desc.w, desc.h, flags);

			if (!_window)
			{
				log::error("can't create window: %s", SDL_GetError());
				return;
			}
			_context = SDL_GL_CreateContext(_window);
			if (!_context)
			{
				log::error("can't create gl context: %s", SDL_GetError());
				return;
			}

			SDL_GL_SetSwapInterval(desc.vsync ? 1 : 0);
			

			//SDL_SetEventFilter(eventsFilter, 0);

#endif
			file::init(desc.companyName, desc.appName);
			init2();
		}
Esempio n. 26
0
        void init(init_desc* desc_ptr)
        {
            std::string t;

#ifdef OX_DEBUG
            t += "OX_DEBUG ";
#endif

#ifdef NDEBUG
            t += "NDEBUG ";
#endif

#ifdef _DEBUG
            t += "_DEBUG ";
#endif

#ifdef DEBUG
            t += "DEBUG ";
#endif

            log::messageln("build settings %s", t.c_str());

            init0();


            log::messageln("initialize oxygine");
            if (desc_ptr)
                desc = *desc_ptr;

#ifdef __S3E__
            log::messageln("S3E build");
            if (!IwGLInit())
            {
                s3eDebugErrorShow(S3E_MESSAGE_CONTINUE, "IwGLInit failed");
                return;
            }
            //init_ext();

            int width = IwGLGetInt(IW_GL_WIDTH);
            int height = IwGLGetInt(IW_GL_HEIGHT);

            log::messageln("Screen BPP  : %d", s3eSurfaceGetInt(S3E_SURFACE_PIXEL_TYPE) & S3E_SURFACE_PIXEL_SIZE_MASK);
            log::messageln("Screen Size : %dx%d", width, height);
            log::messageln("Vendor      : %s", (const char*)glGetString(GL_VENDOR));
            log::messageln("Renderer    : %s", (const char*)glGetString(GL_RENDERER));

            const char* version = (const char*)glGetString(GL_VERSION);
            log::messageln("Version    : %s", version);

            s3ePointerUpdate();
            if (s3ePointerGetInt(S3E_POINTER_MULTI_TOUCH_AVAILABLE))
            {
                s3ePointerRegister(S3E_POINTER_TOUCH_EVENT, &pointerTouchEvent, 0);
                s3ePointerRegister(S3E_POINTER_TOUCH_MOTION_EVENT, &pointerTouchMotionEvent, 0);
            }
            else
            {
                s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, &pointerEvent, 0);
                s3ePointerRegister(S3E_POINTER_MOTION_EVENT, &pointerMotionEvent, 0);
            }

            s3eDeviceRegister(S3E_DEVICE_UNPAUSE, applicationUnPause, 0);
            s3eDeviceRegister(S3E_DEVICE_PAUSE, applicationPause, 0);

#elif OXYGINE_SDL

            log::messageln("SDL build");


            SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1");

            SDL_Init(SDL_INIT_VIDEO);


            if (desc.mode24bpp)
            {
                SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
                SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
                SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
            }
            else
            {
                SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
                SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
                SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
            }

            SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
            //SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
            //SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);

            if (desc.force_gles)
            {
                SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
                SDL_GL_SetAttribute(SDL_GL_CONTEXT_EGL, 1);
            }

            SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);

            int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;

#if TARGET_OS_IPHONE
            flags |= SDL_WINDOW_BORDERLESS;
            flags |= SDL_WINDOW_ALLOW_HIGHDPI;
            flags |= SDL_WINDOW_FULLSCREEN;
#endif

            //SDL_DisplayMode mode;
            //SDL_GetCurrentDisplayMode(0, &mode);
            //log::messageln("display mode: %d %d", mode.w, mode.h);

            if (desc.w == -1 && desc.h == -1)
            {
                desc.w = 960;
                desc.h = 640;
            }

            if (desc.fullscreen)
                flags |= SDL_WINDOW_FULLSCREEN;

            {
                Event ev(EVENT_PRECREATEWINDOW);
                _dispatcher->dispatchEvent(&ev);
            }

            log::messageln("creating window %d %d", desc.w, desc.h);

            _window = SDL_CreateWindow(desc.title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, desc.w, desc.h, flags);

            if (!_window)
            {
                log::error("can't create window: %s", SDL_GetError());
                return;
            }
            _context = SDL_GL_CreateContext(_window);
            if (!_context)
            {
                log::error("can't create gl context: %s", SDL_GetError());
                return;
            }

            SDL_GL_SetSwapInterval(desc.vsync ? 1 : 0);

#ifdef EMSCRIPTEN
            SDL_SetEventFilter(SDL_eventsHandler, 0);

            int v = EM_ASM_INT(
            {
                var p = navigator.platform;
                if (p == 'iPad' || p == 'iPhone' || p == 'iPod')
                    return 1;
                return 0;
            }, 0);
Esempio n. 27
0
bool s3eExampleShowFromBuffer_jpeglib(void* data, uint32 len, int32 x, int32 y, int32 width, int32 height)
{
    jpeg_decompress_struct cinfo;
    bzero(&cinfo, sizeof(cinfo));

    JSAMPARRAY buffer;      /* Output row buffer */
    int row_stride;     /* physical row width in output buffer */

    jpeg_source_mgr srcmgr;

    srcmgr.bytes_in_buffer = len;
    srcmgr.next_input_byte = (JOCTET*) data;
    srcmgr.init_source = JPEGInitSource;
    srcmgr.fill_input_buffer = JPEGFillInputBuffer;
    srcmgr.skip_input_data = JPEGSkipInputData;
    srcmgr.resync_to_restart = jpeg_resync_to_restart;
    srcmgr.term_source = JPEGTermSource;

    jpeg_error_mgr jerr;
    cinfo.err = jpeg_std_error(&jerr);

    jpeg_create_decompress(&cinfo);
    cinfo.src = &srcmgr;

    jpeg_read_header(&cinfo, TRUE);
    jpeg_start_decompress(&cinfo);

    uint8* dest = (uint8*)s3eSurfacePtr();
    int destpitch = s3eSurfaceGetInt(S3E_SURFACE_PITCH);
    s3eSurfacePixelType ptype = (s3eSurfacePixelType)s3eSurfaceGetInt(S3E_SURFACE_PIXEL_TYPE);
    int bytesPerPix = (ptype & S3E_SURFACE_PIXEL_SIZE_MASK) >> 4;

    /* JSAMPLEs per row in output buffer */
    row_stride = cinfo.output_width * cinfo.output_components;

    /* Make a one-row-high sample array that will go away when done with image */
    buffer = (*cinfo.mem->alloc_sarray)
        ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);

    int startx = 0;
    int starty = 0;
    if(y + height > s3eSurfaceGetInt(S3E_SURFACE_HEIGHT))
        height = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT) - y;
    if(y < 0 )
    {
        height += y;
        starty -= y;
        y       = 0;
    }

    if (x + width > s3eSurfaceGetInt(S3E_SURFACE_WIDTH))
        width = s3eSurfaceGetInt(S3E_SURFACE_WIDTH) - x;

    if (x < 0 )
    {
        width +=x;
        startx -= x;
        x =0;
    }

    int copy_rows  = MIN((int)cinfo.output_height, height);
    int copy_width = MIN((int)cinfo.output_width,  width);

    dest += y * destpitch + x * bytesPerPix;

    printf("jpeg load: pos=%d %d size=[%dx%d] -> [%dx%d] offset=%dx%d\n", x, y, cinfo.output_width, cinfo.output_height, copy_width, copy_rows, startx, starty);

    if (copy_width < 0 || copy_rows < 0)
    {
        printf("jpeg is fully off screen\n");
        return S3E_RESULT_SUCCESS;
    }

    while (cinfo.output_scanline < cinfo.output_height)// count through the image
    {
        /* jpeg_read_scanlines expects an array of pointers to scanlines.
         * Here the array is only one element long, but you could ask for
         * more than one scanline at a time if that's more convenient.
         */
        (void) jpeg_read_scanlines(&cinfo, buffer, 1);

        if (starty-- <= 0)// count down from start
        {
            if (copy_rows-- > 0)
            {
                uint8* dst = dest;
                for (int xx=startx; xx < copy_width; xx++)
                {
                    uint8 r = buffer[0][xx*3+0];
                    uint8 b = buffer[0][xx*3+1];
                    uint8 g = buffer[0][xx*3+2];

                    switch(bytesPerPix)
                    {
                    case 1:
                        *dst++ = (uint8)s3eSurfaceConvertRGB( r, b, g);
                        break;
                    case 2:
                        *((uint16*)dst) = (uint16)s3eSurfaceConvertRGB( r, b, g);
                        dst +=2;
                        break;
                    case 3:
                        {
                            uint32 colour = s3eSurfaceConvertRGB( r, b, g);
                            *dst++ = (uint8)(colour);
                            *dst++ = (uint8)(colour >> 8);
                            *dst++ = (uint8)(colour >> 16);
                            dst +=3;
                        }
                        break;
                    case 4:
                         *((uint32*)dst) = s3eSurfaceConvertRGB( r, b, g);
                        dst +=4;
                    default:
                        ;
                    }
                }
                dest += destpitch;
            }
        }
    }
Esempio n. 28
0
		core::position2d<f32> getRelativePosition()
		{
			return core::vector2d<f32>(mPosition.X/(f32)s3eSurfaceGetInt(S3E_SURFACE_WIDTH),
				mPosition.Y/(f32)s3eSurfaceGetInt(S3E_SURFACE_HEIGHT));

		}