Beispiel #1
0
static void
SDLTest_PrintEvent(SDL_Event * event)
{
    if (event->type == SDL_MOUSEMOTION) {
        /* Mouse motion is really spammy */
        //return;
    }

    fprintf(stderr, "SDL EVENT: ");
    switch (event->type) {
    case SDL_WINDOWEVENT:
        switch (event->window.event) {
        case SDL_WINDOWEVENT_SHOWN:
            fprintf(stderr, "Window %d shown", event->window.windowID);
            break;
        case SDL_WINDOWEVENT_HIDDEN:
            fprintf(stderr, "Window %d hidden", event->window.windowID);
            break;
        case SDL_WINDOWEVENT_EXPOSED:
            fprintf(stderr, "Window %d exposed", event->window.windowID);
            break;
        case SDL_WINDOWEVENT_MOVED:
            fprintf(stderr, "Window %d moved to %d,%d",
                    event->window.windowID, event->window.data1,
                    event->window.data2);
            break;
        case SDL_WINDOWEVENT_RESIZED:
            fprintf(stderr, "Window %d resized to %dx%d",
                    event->window.windowID, event->window.data1,
                    event->window.data2);
            break;
        case SDL_WINDOWEVENT_SIZE_CHANGED:
            fprintf(stderr, "Window %d changed size to %dx%d",
                    event->window.windowID, event->window.data1,
                    event->window.data2);
            break;
        case SDL_WINDOWEVENT_MINIMIZED:
            fprintf(stderr, "Window %d minimized", event->window.windowID);
            break;
        case SDL_WINDOWEVENT_MAXIMIZED:
            fprintf(stderr, "Window %d maximized", event->window.windowID);
            break;
        case SDL_WINDOWEVENT_RESTORED:
            fprintf(stderr, "Window %d restored", event->window.windowID);
            break;
        case SDL_WINDOWEVENT_ENTER:
            fprintf(stderr, "Mouse entered window %d",
                    event->window.windowID);
            break;
        case SDL_WINDOWEVENT_LEAVE:
            fprintf(stderr, "Mouse left window %d", event->window.windowID);
            break;
        case SDL_WINDOWEVENT_FOCUS_GAINED:
            fprintf(stderr, "Window %d gained keyboard focus",
                    event->window.windowID);
            break;
        case SDL_WINDOWEVENT_FOCUS_LOST:
            fprintf(stderr, "Window %d lost keyboard focus",
                    event->window.windowID);
            break;
        case SDL_WINDOWEVENT_CLOSE:
            fprintf(stderr, "Window %d closed", event->window.windowID);
            break;
        default:
            fprintf(stderr, "Window %d got unknown event %d",
                    event->window.windowID, event->window.event);
            break;
        }
        break;
    case SDL_KEYDOWN:
        fprintf(stderr,
                "Keyboard: key pressed  in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
                event->key.windowID,
                event->key.keysym.scancode,
                SDL_GetScancodeName(event->key.keysym.scancode),
                event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
        break;
    case SDL_KEYUP:
        fprintf(stderr,
                "Keyboard: key released in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
                event->key.windowID,
                event->key.keysym.scancode,
                SDL_GetScancodeName(event->key.keysym.scancode),
                event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
        break;
    case SDL_TEXTINPUT:
        fprintf(stderr, "Keyboard: text input \"%s\" in window %d",
                event->text.text, event->text.windowID);
        break;
    case SDL_MOUSEMOTION:
        fprintf(stderr, "Mouse: moved to %d,%d (%d,%d) in window %d",
                event->motion.x, event->motion.y,
                event->motion.xrel, event->motion.yrel,
                event->motion.windowID);
        break;
    case SDL_MOUSEBUTTONDOWN:
        fprintf(stderr, "Mouse: button %d pressed at %d,%d in window %d",
                event->button.button, event->button.x, event->button.y,
                event->button.windowID);
        break;
    case SDL_MOUSEBUTTONUP:
        fprintf(stderr, "Mouse: button %d released at %d,%d in window %d",
                event->button.button, event->button.x, event->button.y,
                event->button.windowID);
        break;
    case SDL_MOUSEWHEEL:
        fprintf(stderr,
                "Mouse: wheel scrolled %d in x and %d in y in window %d",
                event->wheel.x, event->wheel.y, event->wheel.windowID);
        break;
    case SDL_JOYBALLMOTION:
        fprintf(stderr, "Joystick %d: ball %d moved by %d,%d",
                event->jball.which, event->jball.ball, event->jball.xrel,
                event->jball.yrel);
        break;
    case SDL_JOYHATMOTION:
        fprintf(stderr, "Joystick %d: hat %d moved to ", event->jhat.which,
                event->jhat.hat);
        switch (event->jhat.value) {
        case SDL_HAT_CENTERED:
            fprintf(stderr, "CENTER");
            break;
        case SDL_HAT_UP:
            fprintf(stderr, "UP");
            break;
        case SDL_HAT_RIGHTUP:
            fprintf(stderr, "RIGHTUP");
            break;
        case SDL_HAT_RIGHT:
            fprintf(stderr, "RIGHT");
            break;
        case SDL_HAT_RIGHTDOWN:
            fprintf(stderr, "RIGHTDOWN");
            break;
        case SDL_HAT_DOWN:
            fprintf(stderr, "DOWN");
            break;
        case SDL_HAT_LEFTDOWN:
            fprintf(stderr, "LEFTDOWN");
            break;
        case SDL_HAT_LEFT:
            fprintf(stderr, "LEFT");
            break;
        case SDL_HAT_LEFTUP:
            fprintf(stderr, "LEFTUP");
            break;
        default:
            fprintf(stderr, "UNKNOWN");
            break;
        }
        break;
    case SDL_JOYBUTTONDOWN:
        fprintf(stderr, "Joystick %d: button %d pressed",
                event->jbutton.which, event->jbutton.button);
        break;
    case SDL_JOYBUTTONUP:
        fprintf(stderr, "Joystick %d: button %d released",
                event->jbutton.which, event->jbutton.button);
        break;
    case SDL_CLIPBOARDUPDATE:
        fprintf(stderr, "Clipboard updated");
        break;
    case SDL_QUIT:
        fprintf(stderr, "Quit requested");
        break;
    case SDL_USEREVENT:
        fprintf(stderr, "User event %d", event->user.code);
        break;
    default:
        fprintf(stderr, "Unknown event %d", event->type);
        break;
    }
    fprintf(stderr, "\n");
}
Beispiel #2
0
void mainmenu_draw(int width,int height)
{
	float lightpos2[4]={0,0,1000,0};
	float tmpls[4]={1.0F,1.0F,1.0F,1.0};
	float tmpld[4]={0.6F,0.6F,0.6F,1.0};
	float tmpla[4]={0.2F,0.2F,0.2F,1.0};
    float ratio;

	if (nethertittle==0) {
		nethertittle=new C3DObject("/usr/local/share/netherearth/models/tittle.asc","/usr/local/share/netherearth/textures/");
		nethertittle->normalize(7.0);
	} /* if */ 

	/* Enable Lights, etc.: */ 
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations
	glEnable(GL_LIGHT0);
	glLightfv(GL_LIGHT0,GL_AMBIENT,tmpla);
	glLightfv(GL_LIGHT0,GL_DIFFUSE,tmpld);
	glLightfv(GL_LIGHT0,GL_SPECULAR,tmpls);
	glEnable(GL_LIGHTING);
	glEnable(GL_COLOR_MATERIAL);
	glShadeModel( GL_SMOOTH );
	glCullFace( GL_BACK );
	glFrontFace( GL_CCW );
    glEnable( GL_CULL_FACE );
	glDisable( GL_SCISSOR_TEST );  
	glEnable( GL_DEPTH_TEST );
	
	glLightfv(GL_LIGHT0,GL_POSITION,lightpos2);
    glClearColor(0,0,0,0.0);
    glViewport(0,0,width,height);
	ratio=(float)width/float(height);
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity( );
    gluPerspective( 30.0, ratio, 1.0, 1024.0 );
	gluLookAt(0,0,30,0,0,0,0,1,0);

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

	switch(mainmenu_status) {
	case 0:
		glTranslatef(0,3,40-mainmenu_substatus);
		nethertittle->draw(1.0,1.0,1.0);
		break;
	case 1:
		glTranslatef(0,3,0);
		glPushMatrix();
		glRotatef(sin(mainmenu_substatus*0.02)*5.0f,0,1,0);
		nethertittle->draw(1.0,1.0,1.0);
		glPopMatrix();
		glColor3f(0.5,0.5,1.0);
		glTranslatef(-6,-6,0);
		scaledglprintf2(0.005,0.005,"1 - START NEW GAME   ");
		glTranslatef(0,-1,0);
		scaledglprintf2(0.005,0.005,"2 - REDEFINE KEYBOARD");
		glTranslatef(0,-1,0);
		scaledglprintf2(0.005,0.005,"3 - OPTIONS          ");
		glTranslatef(0,-1,0);
		scaledglprintf2(0.005,0.005,"4 - MAP: %s",mapname);
		glTranslatef(0,-1,0);
		scaledglprintf2(0.005,0.005,"5 - EXIT GAME        ");
		break;
	case 2:
	case 4:
	case 5:
	case 6:
		glTranslatef(0,3,mainmenu_substatus);
		nethertittle->draw(1.0,1.0,1.0);
		break;
	case 3:
		glColor3f(0.5,0.5,1.0);
		glTranslatef(0,3.5,0);
		if (SCREEN_X== 320) scaledglprintf(0.005,0.005,"1 - RESOLUTION:  320x240");
		if (SCREEN_X== 400) scaledglprintf(0.005,0.005,"1 - RESOLUTION:  400x300");
		if (SCREEN_X== 640) scaledglprintf(0.005,0.005,"1 - RESOLUTION:  640x480");
		if (SCREEN_X== 800) scaledglprintf(0.005,0.005,"1 - RESOLUTION:  800x600");
		if (SCREEN_X==1024) scaledglprintf(0.005,0.005,"1 - RESOLUTION: 1024x768");
		glTranslatef(0,-1,0);
		if (COLOUR_DEPTH== 8) scaledglprintf(0.005,0.005,"2 - COLOR DEPTH:  8bit  ");
		if (COLOUR_DEPTH==16) scaledglprintf(0.005,0.005,"2 - COLOR DEPTH: 16bit  ");
		if (COLOUR_DEPTH==24) scaledglprintf(0.005,0.005,"2 - COLOR DEPTH: 24bit  ");
		if (COLOUR_DEPTH==32) scaledglprintf(0.005,0.005,"2 - COLOR DEPTH: 32bit  ");
		glTranslatef(0,-1,0);
		if (fullscreen) scaledglprintf(0.005,0.005,"3 - FULLSCREEN          ");
				   else scaledglprintf(0.005,0.005,"3 - WINDOWED            ");
		glTranslatef(0,-1,0);
		if (shadows==0) scaledglprintf(0.005,0.005,"4 - SHADOWS: OFF        ");
		if (shadows==1) scaledglprintf(0.005,0.005,"4 - SHADOWS: ON - DIAG  ");
		if (shadows==2) scaledglprintf(0.005,0.005,"4 - SHADOWS: ON - VERT  ");
		glTranslatef(0,-1,0);
		if (detaillevel==0) scaledglprintf(0.005,0.005,"5 - DETAIL: LOWEST      ");
		if (detaillevel==1) scaledglprintf(0.005,0.005,"5 - DETAIL: LOW         ");
		if (detaillevel==2) scaledglprintf(0.005,0.005,"5 - DETAIL: MEDIUM      ");
		if (detaillevel==3) scaledglprintf(0.005,0.005,"5 - DETAIL: HIGH        ");
		if (detaillevel==4) scaledglprintf(0.005,0.005,"5 - DETAIL: HIGHEST     ");
		glTranslatef(0,-1,0);
		if (sound) scaledglprintf(0.005,0.005,"6 - SOUND: ON           ");
			  else scaledglprintf(0.005,0.005,"6 - SOUND: OFF          ");
		glTranslatef(0,-1,0);
		if (level==0) scaledglprintf(0.005,0.005,"7 - LEVEL: EASY         ");
		if (level==1) scaledglprintf(0.005,0.005,"7 - LEVEL: NORMAL       ");
		if (level==2) scaledglprintf(0.005,0.005,"7 - LEVEL: HARD         ");
		if (level==3) scaledglprintf(0.005,0.005,"7 - LEVEL: IMPOSSIBLE   ");
		glTranslatef(0,-1,0);
		if (show_radar) scaledglprintf(0.005,0.005,"8 - RADAR: ON           ");
				   else scaledglprintf(0.005,0.005,"8 - RADAR: OFF          ");
		glTranslatef(0,-1,0);
		scaledglprintf(0.005,0.005,"9 - BACK                ");
		break;
	case 7:
		{
			char tmp[256];

			glColor3f(0.5,0.5,1.0);
			glTranslatef(0,5,0);
			scaledglprintf(0.005,0.005,"REDEFINE KEYBOARD");
			glTranslatef(0,-2,0);
			if (mainmenu_substatus!=0) glColor3f(0.5,0.5,1.0);
								  else glColor3f(1.0,0.0,0.0);
			sprintf(tmp,"PRESS A KEY FOR UP: %s",strupr(SDL_GetKeyName((SDLKey)up_key)));
			scaledglprintf(0.005,0.005,tmp);
			glTranslatef(0,-1,0);
			if (mainmenu_substatus!=1) glColor3f(0.5,0.5,1.0);
						 	 	  else glColor3f(1.0,0.0,0.0);
			sprintf(tmp,"PRESS A KEY FOR DOWN: %s",strupr(SDL_GetKeyName((SDLKey)down_key)));
			scaledglprintf(0.005,0.005,tmp);
			glTranslatef(0,-1,0);
			if (mainmenu_substatus!=2) glColor3f(0.5,0.5,1.0);
								  else glColor3f(1.0,0.0,0.0);
			sprintf(tmp,"PRESS A KEY FOR LEFT: %s",strupr(SDL_GetKeyName((SDLKey)left_key)));
			scaledglprintf(0.005,0.005,tmp);
			glTranslatef(0,-1,0);
			if (mainmenu_substatus!=3) glColor3f(0.5,0.5,1.0);
								  else glColor3f(1.0,0.0,0.0);
			sprintf(tmp,"PRESS A KEY FOR RIGHT: %s",strupr(SDL_GetKeyName((SDLKey)right_key)));
			scaledglprintf(0.005,0.005,tmp);
			glTranslatef(0,-1,0);
			if (mainmenu_substatus!=4) glColor3f(0.5,0.5,1.0);
								  else glColor3f(1.0,0.0,0.0);
			sprintf(tmp,"PRESS A KEY FOR FIRE: %s",strupr(SDL_GetKeyName((SDLKey)fire_key)));
			scaledglprintf(0.005,0.005,tmp);

			glTranslatef(0,-1,0);
			if (mainmenu_substatus!=5) glColor3f(0.5,0.5,1.0);
								  else glColor3f(1.0,0.0,0.0);
			sprintf(tmp,"PRESS A KEY FOR PAUSE/MENU: %s",strupr(SDL_GetKeyName((SDLKey)pause_key)));
			scaledglprintf(0.005,0.005,tmp);

			glColor3f(0.5,0.5,1.0);
			glTranslatef(0,-2,0);
			scaledglprintf(0.005,0.005,"PG.UP/PG.DOWN CHANGE THE ZOOM");

			if (mainmenu_substatus>5) {
				glColor3f(1,1,1);
				glTranslatef(0,-2,0);
				scaledglprintf(0.005,0.005,"PRESS ANY KEY TO RETURN TO MAIN MENU");
			} /* if */ 
		}
		break;
	} /* switch */ 

	SDL_GL_SwapBuffers();
} /* NETHER::draw */ 
Beispiel #3
0
/*
 * @brief Prints keyboard identifiers in the console
 */
static void IN_PrintKey(const SDL_keysym *keysym, keyNum_t key, qboolean down)
{
	if (down)
	{
		Com_Printf("+ ");
	}
	else
	{
		Com_Printf("  ");
	}

	Com_Printf("0x%02x \"%s\"", keysym->scancode,
	           SDL_GetKeyName(keysym->sym));

	if (keysym->mod & KMOD_LSHIFT)
	{
		Com_Printf(" KMOD_LSHIFT");
	}
	if (keysym->mod & KMOD_RSHIFT)
	{
		Com_Printf(" KMOD_RSHIFT");
	}
	if (keysym->mod & KMOD_LCTRL)
	{
		Com_Printf(" KMOD_LCTRL");
	}
	if (keysym->mod & KMOD_RCTRL)
	{
		Com_Printf(" KMOD_RCTRL");
	}
	if (keysym->mod & KMOD_LALT)
	{
		Com_Printf(" KMOD_LALT");
	}
	if (keysym->mod & KMOD_RALT)
	{
		Com_Printf(" KMOD_RALT");
	}
	if (keysym->mod & KMOD_LMETA)
	{
		Com_Printf(" KMOD_LMETA");
	}
	if (keysym->mod & KMOD_RMETA)
	{
		Com_Printf(" KMOD_RMETA");
	}
	if (keysym->mod & KMOD_NUM)
	{
		Com_Printf(" KMOD_NUM");
	}
	if (keysym->mod & KMOD_CAPS)
	{
		Com_Printf(" KMOD_CAPS");
	}
	if (keysym->mod & KMOD_MODE)
	{
		Com_Printf(" KMOD_MODE");
	}
	if (keysym->mod & KMOD_RESERVED)
	{
		Com_Printf(" KMOD_RESERVED");
	}

	Com_Printf(" Q:0x%02x(%s)", key, Key_KeynumToString(key));

	if (keysym->unicode)
	{
		Com_Printf(" U:0x%02x", keysym->unicode);

		if (keysym->unicode > ' ' && keysym->unicode < '~')
		{
			Com_Printf("(%c)", (char)keysym->unicode);
		}
	}

	Com_Printf("\n");
}
void ItemShortcutContainer::draw(gcn::Graphics *graphics)
{
    if (config.getValue("guialpha", 0.8) != mAlpha)
    {
        mAlpha = config.getValue("guialpha", 0.8);
        mBackgroundImg->setAlpha(mAlpha);
    }

    Graphics *g = static_cast<Graphics*>(graphics);

    graphics->setFont(getFont());

    for (int i = 0; i < mMaxItems; i++)
    {
        const int itemX = (i % mGridWidth) * mBoxWidth;
        const int itemY = (i / mGridWidth) * mBoxHeight;

        g->drawImage(mBackgroundImg, itemX, itemY);

        // Draw item keyboard shortcut.
        const char *key = SDL_GetKeyName(
            (SDLKey) keyboard.getKeyValue(keyboard.KEY_SHORTCUT_1 + i));
        graphics->setColor(guiPalette->getColor(Palette::TEXT));
        g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT);

        if (itemShortcut->getItem(i) < 0)
            continue;

        Item *item =
            player_node->getInventory()->findItem(itemShortcut->getItem(i));

        if (item)
        {
            // Draw item icon.
            Image* image = item->getImage();

            if (image)
            {
                std::string caption;
                if (item->getQuantity() > 1)
                    caption = toString(item->getQuantity());
                else if (item->isEquipped())
                    caption = "Eq.";

                g->drawImage(image, itemX, itemY);
                if (item->isEquipped())
                    g->setColor(guiPalette->getColor(Palette::ITEM_EQUIPPED));
                g->drawText(caption, itemX + mBoxWidth / 2,
                            itemY + mBoxHeight - 14, gcn::Graphics::CENTER);
            }
        }
    }

    if (mItemMoved)
    {
        // Draw the item image being dragged by the cursor.
        Image* image = mItemMoved->getImage();
        if (image)
        {
            const int tPosX = mCursorPosX - (image->getWidth() / 2);
            const int tPosY = mCursorPosY - (image->getHeight() / 2);

            g->drawImage(image, tPosX, tPosY);
            g->drawText(toString(mItemMoved->getQuantity()),
                        tPosX + mBoxWidth / 2, tPosY + mBoxHeight - 14,
                        gcn::Graphics::CENTER);
        }
    }
}
Beispiel #5
0
void keyBoardTest(Video *keysVideoptr) //TODO rename keyBoardTest to something more meaningfull, like MainGameLoop or something.
{//starts the game.  

	Timer FallDownTimer(500);
	Timer BlockMover(125); //control speed of left right motion.
    Timer BlockMoverDown(50); // control speed of downward motion
	Timer GameLoopRate(20);

	SDL_Rect TextLocation;
	SDL_Rect loc_MouseTest;
	std::string sMouseText = "";
	
	std::string KeyPress = "";

	char* c_string = new char[100];
	unsigned int fontCounter = 0;
	bool quit=false;
	
	TextLocation.y = 0;
	TextLocation.x = 0;
	loc_MouseTest.y = 375;
	loc_MouseTest.x = 50;

	int image_x = 0;
	int image_y = 0;
	bool image_direction = true;
	int image_speed = 10;

	int block_speed = 5;
	
	int orientation = 0;

	std::string BlockMove = "";

	while(quit==false)
	{	
		if(!GameLoopRate.TimeToMove())
		{
			continue;
		}

		if (FallDownTimer.TimeToMove())
		{
		    printf("TimeToMoveDown: \n");
	//		Block1.FallDown();
			
		}
		if (BlockMover.TimeToMove() && BlockMove != "")
		{
			printf("TimeToMoveLeftRight: %s \n", BlockMove.c_str());
			if (BlockMove == "left")
			{
				if(!WillCollideWithBlocksInPlay(BlockMove))
				{
					Block1.MoveLeft();
				}
				//if key is not currently suppressed.
				
			}
			if (BlockMove == "right")
			{
				if(!WillCollideWithBlocksInPlay(BlockMove))
				{
					Block1.MoveRight();
				}
				
			}
		}
		if (BlockMoverDown.TimeToMove() && BlockMove == "down")
		{
			if(!WillCollideWithBlocksInPlay(BlockMove))
			{
				Block1.MoveDown();
			}
		}

		while(SDL_PollEvent(&event))
		{
			switch(event.type)//set the proper text
			{
				case SDL_KEYDOWN:  // Key was pressed
				
					KeyPress = SDL_GetKeyName(event.key.keysym.sym);
					
					printf("The %s key was pressed!\n",KeyPress.c_str());
					
					TextLocation.x+=10;

					if(KeyPress == "up")
					{
						if(orientation == 3)
						{
							orientation = 0;
						}
						else
						{
							orientation++;
						}

						printf("orientation: %d", orientation);
					}
					
					if(KeyPress == "down" && !BlockMoverDown.TimeToMove())
					{
						if(!Block1.getBorder().empty() && !WillCollideWithBlocksInPlay(KeyPress))
						{
							Block1.MoveDown();
						}
						BlockMove = "down";
						BlockMoverDown.Reset();
					}
					
					if(KeyPress == "left")
					{
						//Block1.MoveLeft();
						BlockMove = "left";
					}
					
					if(KeyPress == "right")
					{
						//Block1.MoveRight();
						BlockMove = "right";
					}
					
					if(KeyPress == "q" || KeyPress == "escape")
					{
						quit=true;
					}
					if (KeyPress == "z")
					{
						Block1.SetPos(1,0);
					}

					break;

				
				case SDL_KEYUP:  // Key was DEpressed
						
					break;
				
				case SDL_MOUSEMOTION:
					printf("Mouse Position %d , %d, %d, %d", event.motion.xrel, event.motion.yrel, event.motion.x, event.motion.y);
					sprintf(c_string, "mouse position %d , %d, %d, %d", event.motion.xrel, event.motion.yrel, event.motion.x, event.motion.y);
					KeyPress = c_string;
					Video1->ApplySurface(300, 577, ScreenFont1.DrawFontString(KeyPress));
					fontCounter += 28;
					break;

				case SDL_MOUSEBUTTONDOWN:
					printf("Mouse button %d pressed at (%d,%d)\n", event.button.button, event.button.x, event.button.y);
					
					break;

				case SDL_QUIT: quit=true;
					break;
			}
		}

		//DrawAll the pieces.
		Floor.Draw(Video1, 0);

		Block1.Draw(Video1, orientation);
		Block2.Draw(Video1, 0);
		Block3.Draw(Video1, 0);

		Video1->Flip();
		SDL_FillRect(SDL_GetVideoSurface(), NULL, g_black);
	}

	c_string = NULL;
	delete c_string;
}
Beispiel #6
0
/* Process pending events. Call with ->lock held */
static void
gst_sdlv_process_events (GstSDLVideoSink * sdlvideosink)
{
  SDL_Event event;
  int numevents;
  char *keysym = NULL;

  do {
    SDL_PumpEvents ();
    numevents = SDL_PeepEvents (&event, 1, SDL_GETEVENT,
        SDL_KEYDOWNMASK | SDL_KEYUPMASK |
        SDL_MOUSEMOTIONMASK | SDL_MOUSEBUTTONDOWNMASK |
        SDL_MOUSEBUTTONUPMASK | SDL_QUITMASK | SDL_VIDEORESIZEMASK);

    if (numevents > 0 && (event.type == SDL_KEYUP || event.type == SDL_KEYDOWN)) {
      keysym = SDL_GetKeyName (event.key.keysym.sym);
    }

    if (numevents > 0) {
      g_mutex_unlock (sdlvideosink->lock);
      switch (event.type) {
        case SDL_MOUSEMOTION:
          gst_navigation_send_mouse_event (GST_NAVIGATION (sdlvideosink),
              "mouse-move", 0, event.motion.x, event.motion.y);
          break;
        case SDL_MOUSEBUTTONDOWN:
          gst_navigation_send_mouse_event (GST_NAVIGATION (sdlvideosink),
              "mouse-button-press",
              event.button.button, event.button.x, event.button.y);
          break;
        case SDL_MOUSEBUTTONUP:
          gst_navigation_send_mouse_event (GST_NAVIGATION (sdlvideosink),
              "mouse-button-release",
              event.button.button, event.button.x, event.button.y);
          break;
        case SDL_KEYUP:
          GST_DEBUG ("key press event %s !",
              SDL_GetKeyName (event.key.keysym.sym));
          gst_navigation_send_key_event (GST_NAVIGATION (sdlvideosink),
              "key-release", keysym);
          break;
        case SDL_KEYDOWN:
          if (SDLK_ESCAPE != event.key.keysym.sym) {
            GST_DEBUG ("key press event %s !",
                SDL_GetKeyName (event.key.keysym.sym));
            gst_navigation_send_key_event (GST_NAVIGATION (sdlvideosink),
                "key-press", keysym);
            break;
          } else {
            /* fall through */
          }
        case SDL_QUIT:
          sdlvideosink->running = FALSE;
          GST_ELEMENT_ERROR (sdlvideosink, RESOURCE, OPEN_WRITE,
              ("Video output device is gone."),
              ("We were running fullscreen and user "
                  "pressed the ESC key, stopping playback."));
          break;
        case SDL_VIDEORESIZE:
          /* create a SDL window of the size requested by the user */
          g_mutex_lock (sdlvideosink->lock);
          GST_VIDEO_SINK_WIDTH (sdlvideosink) = event.resize.w;
          GST_VIDEO_SINK_HEIGHT (sdlvideosink) = event.resize.h;
          gst_sdlvideosink_create (sdlvideosink);
          g_mutex_unlock (sdlvideosink->lock);
          break;
      }
      g_mutex_lock (sdlvideosink->lock);
    }
  } while (numevents > 0);
}
Beispiel #7
0
static int l_mainloop(lua_State *L)
{
    luaL_checktype(L, 1, LUA_TTHREAD);
    lua_State *dispatcher = lua_tothread(L, 1);

    fps_ctrl *fps_control = (fps_ctrl*)lua_touserdata(L, luaT_upvalueindex(1));
    SDL_TimerID timer = SDL_AddTimer(30, timer_frame_callback, nullptr);
    SDL_Event e;

    while(SDL_WaitEvent(&e) != 0)
    {
        bool do_frame = false;
        bool do_timer = false;
        do
        {
            int nargs;
            switch(e.type)
            {
            case SDL_QUIT:
                goto leave_loop;
            case SDL_KEYDOWN:
                lua_pushliteral(dispatcher, "keydown");
                lua_pushstring(dispatcher, SDL_GetKeyName(e.key.keysym.sym));
                l_push_modifiers_table(dispatcher, e.key.keysym.mod);
                lua_pushboolean(dispatcher, e.key.repeat != 0);
                nargs = 4;
                break;
            case SDL_KEYUP:
                lua_pushliteral(dispatcher, "keyup");
                lua_pushstring(dispatcher, SDL_GetKeyName(e.key.keysym.sym));
                nargs = 2;
                break;
            case SDL_TEXTINPUT:
                lua_pushliteral(dispatcher, "textinput");
                lua_pushstring(dispatcher, e.text.text);
                nargs = 2;
                break;
            case SDL_TEXTEDITING:
                lua_pushliteral(dispatcher, "textediting");
                lua_pushstring(dispatcher, e.edit.text);
                lua_pushinteger(dispatcher, e.edit.start);
                lua_pushinteger(dispatcher, e.edit.length);
                nargs = 4;
                break;
            case SDL_MOUSEBUTTONDOWN:
                lua_pushliteral(dispatcher, "buttondown");
                lua_pushinteger(dispatcher, e.button.button);
                lua_pushinteger(dispatcher, e.button.x);
                lua_pushinteger(dispatcher, e.button.y);
                nargs = 4;
                break;
            case SDL_MOUSEBUTTONUP:
                lua_pushliteral(dispatcher, "buttonup");
                lua_pushinteger(dispatcher, e.button.button);
                lua_pushinteger(dispatcher, e.button.x);
                lua_pushinteger(dispatcher, e.button.y);
                nargs = 4;
                break;
            case SDL_MOUSEWHEEL:
                lua_pushliteral(dispatcher, "mousewheel");
                lua_pushinteger(dispatcher, e.wheel.x);
                lua_pushinteger(dispatcher, e.wheel.y);
                nargs = 3;
                break;
            case SDL_MOUSEMOTION:
                lua_pushliteral(dispatcher, "motion");
                lua_pushinteger(dispatcher, e.motion.x);
                lua_pushinteger(dispatcher, e.motion.y);
                lua_pushinteger(dispatcher, e.motion.xrel);
                lua_pushinteger(dispatcher, e.motion.yrel);
                nargs = 5;
                break;
            case SDL_WINDOWEVENT:
                switch (e.window.event) {
                    case SDL_WINDOWEVENT_FOCUS_GAINED:
                        lua_pushliteral(dispatcher, "active");
                        lua_pushinteger(dispatcher, 1);
                        nargs = 2;
                        break;
                    case SDL_WINDOWEVENT_FOCUS_LOST:
                        lua_pushliteral(dispatcher, "active");
                        lua_pushinteger(dispatcher, 0);
                        nargs = 2;
                        break;
                    default:
                        nargs = 0;
                        break;
                }
                break;
            case SDL_USEREVENT_MUSIC_OVER:
                lua_pushliteral(dispatcher, "music_over");
                nargs = 1;
                break;
            case SDL_USEREVENT_MUSIC_LOADED:
                if(luaT_cpcall(L, (lua_CFunction)l_load_music_async_callback, e.user.data1))
                {
                    SDL_RemoveTimer(timer);
                    lua_pushliteral(L, "callback");
                    return 2;
                }
                nargs = 0;
                break;
            case SDL_USEREVENT_TICK:
                do_timer = true;
                nargs = 0;
                break;
            case SDL_USEREVENT_MOVIE_OVER:
                lua_pushliteral(dispatcher, "movie_over");
                nargs = 1;
                break;
            case SDL_USEREVENT_SOUND_OVER:
                lua_pushliteral(dispatcher, "sound_over");
                lua_pushinteger(dispatcher, *(static_cast<int*>(e.user.data1)));
                nargs = 2;
                break;
            default:
                nargs = 0;
                break;
            }
            if(nargs != 0)
            {
                if(luaT_resume(dispatcher, dispatcher, nargs) != LUA_YIELD)
                {
                    goto leave_loop;
                }
                do_frame = do_frame || (lua_toboolean(dispatcher, 1) != 0);
                lua_settop(dispatcher, 0);
            }
        } while(SDL_PollEvent(&e) != 0);
        if(do_timer)
        {
            lua_pushliteral(dispatcher, "timer");
            if(luaT_resume(dispatcher, dispatcher, 1) != LUA_YIELD)
            {
                break;
            }
            do_frame = do_frame || (lua_toboolean(dispatcher, 1) != 0);
            lua_settop(dispatcher, 0);
        }
        if(do_frame || !fps_control->limit_fps)
        {
            do
            {
                if(fps_control->track_fps)
                {
                    fps_control->count_frame();
                }
                lua_pushliteral(dispatcher, "frame");
                if(luaT_resume(dispatcher, dispatcher, 1) != LUA_YIELD)
                {
                    goto leave_loop;
                }
                lua_settop(dispatcher, 0);
            } while(fps_control->limit_fps == false && SDL_PollEvent(nullptr) == 0);
        }

        // No events pending - a good time to do a bit of garbage collection
        lua_gc(L, LUA_GCSTEP, 2);
    }

leave_loop:
    SDL_RemoveTimer(timer);
    int n = lua_gettop(dispatcher);
    if(lua_status(dispatcher) >= LUA_ERRRUN)
    {
        n = 1;
    }
    lua_checkstack(L, n);
    lua_xmove(dispatcher, L, n);
    return n;
}
Beispiel #8
0
inline std::string to_string(int32_t key_code) noexcept {
    return SDL_GetKeyName(key_code);
}
Beispiel #9
0
/**
 * @brief Prints keyboard identifiers in the console
 */
static void IN_PrintKey(const SDL_Keysym *keysym, keyNum_t key, qboolean down)
{
	if (down)
	{
		Com_Printf("+ ");
	}
	else
	{
		Com_Printf("  ");
	}

	Com_Printf("Scancode: 0x%02x(%s) Sym: 0x%02x(%s)",
	           keysym->scancode, SDL_GetScancodeName(keysym->scancode),
	           keysym->sym, SDL_GetKeyName(keysym->sym));

	if (keysym->mod & KMOD_LSHIFT)
	{
		Com_Printf(" KMOD_LSHIFT");
	}
	if (keysym->mod & KMOD_RSHIFT)
	{
		Com_Printf(" KMOD_RSHIFT");
	}
	if (keysym->mod & KMOD_LCTRL)
	{
		Com_Printf(" KMOD_LCTRL");
	}
	if (keysym->mod & KMOD_RCTRL)
	{
		Com_Printf(" KMOD_RCTRL");
	}
	if (keysym->mod & KMOD_LALT)
	{
		Com_Printf(" KMOD_LALT");
	}
	if (keysym->mod & KMOD_RALT)
	{
		Com_Printf(" KMOD_RALT");
	}
	if (keysym->mod & KMOD_LGUI)
	{
		Com_Printf(" KMOD_LGUI");
	}
	if (keysym->mod & KMOD_RGUI)
	{
		Com_Printf(" KMOD_RGUI");
	}
	if (keysym->mod & KMOD_NUM)
	{
		Com_Printf(" KMOD_NUM");
	}
	if (keysym->mod & KMOD_CAPS)
	{
		Com_Printf(" KMOD_CAPS");
	}
	if (keysym->mod & KMOD_MODE)
	{
		Com_Printf(" KMOD_MODE");
	}
	if (keysym->mod & KMOD_RESERVED)
	{
		Com_Printf(" KMOD_RESERVED");
	}

	Com_Printf(" Q:0x%02x(%s)\n", key, Key_KeynumToString(key));
}
Beispiel #10
0
const char *tpw_key_name_get(int sym) {
	return SDL_GetKeyName(sym);
}
Beispiel #11
0
int confirm( StkFont *font, char *str, int type )
{
    SDL_Event event;
    int go_on = 1;
    int ret = 0;
    SDL_Surface *buffer = 
        stk_surface_create( SDL_SWSURFACE, stk_display->w, stk_display->h );
    SDL_SetColorKey(buffer, 0, 0);

#ifdef AUDIO_ENABLED
    stk_sound_play( wav_click );
#endif

    event_clear_sdl_queue();

    stk_surface_blit( stk_display, 0,0,-1,-1, buffer, 0,0 );
    if ( type == CONFIRM_PAUSE )
        stk_surface_gray( stk_display, 0,0,-1,-1,0 );
    else
        draw_confirm_screen( font, buffer, str );
    stk_display_update( STK_UPDATE_ALL );

    while (go_on && !stk_quit_request) {
        SDL_WaitEvent(&event);
        /* TEST */
        switch ( event.type ) {
            case SDL_QUIT: stk_quit_request = 1; break;
            case SDL_MOUSEBUTTONUP:
                if ( type == CONFIRM_ANY_KEY ) {
                    ret = 1; go_on = 0;
                }
/*                else
                if ( type == CONFIRM_YES_NO ) {
                    if ( event.button.button == LEFT_BUTTON )
                        ret = 1;
                    else
                        ret = 0;
                    go_on = 0;
                }*/
                break;
            case SDL_KEYDOWN:
                if ( type == CONFIRM_ANY_KEY ) {
                    ret = 1; go_on = 0;
                    break;
                }
                else
                if ( type == CONFIRM_PAUSE ) {
                    if ( event.key.keysym.sym == SDLK_p ) {
                        ret = 1; go_on = 0;
                        break;
                    }
					else
					if ( event.key.keysym.sym == SDLK_f ) {
						config.fullscreen = !config.fullscreen;
                        stk_display_apply_fullscreen( config.fullscreen );
						draw_confirm_screen( font, buffer, str );
						stk_display_update( STK_UPDATE_ALL );
					}
                }
                else
                {
                    char *keyName = SDL_GetKeyName(event.key.keysym.sym);
                    char *yesLetter = _("y");
                    char *noLetter = _("n");
                    if (strcmp(keyName, yesLetter) == 0) {
                        go_on = 0;
                        ret = 1;
                    }
                    else
                    if (event.key.keysym.sym==SDLK_ESCAPE || strcmp(keyName, noLetter) == 0 ) {
                        go_on = 0;
                        ret = 0;
                    }
                    default:
                        break;
                }
                break;
        }
    }
#ifdef AUDIO_ENABLED
    stk_sound_play( wav_click );
#endif
    stk_surface_blit( buffer, 0,0,-1,-1, stk_display, 0,0 );
    stk_display_update( STK_UPDATE_ALL );
    SDL_FreeSurface(buffer);

    /* reset the relative position so paddle wont jump */
    SDL_GetRelativeMouseState(0,0);

    return ret;
}
Beispiel #12
0
int main(int argc, char *argv[])
{
    // initialize sdl
    int init_flags = SDL_INIT_VIDEO | SDL_INIT_TIMER;
    int sdl_flags = SDL_OPENGL;// | SDL_FULLSCREEN;
    if (SDL_Init(init_flags) != 0)
    {
        fprintf(stderr, "Error initializing SDL: %s\n", SDL_GetError());
        return 1;
    }
    atexit(SDL_Quit);
    SDL_EnableKeyRepeat(0, 0);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_Surface *screen = SDL_SetVideoMode(640, 480, 16, sdl_flags);

    // initialize opengl
    glEnable(GL_TEXTURE_2D);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glEnable (GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glViewport(0, 0, 640, 480);
    glClear(GL_COLOR_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0f, 1.0f, 1.0f, 0.0f, -1.0f, 1.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // load images
    const char * img_file = "vw_topview.png";
    const char * bg_file = "400px-Trollface.jpg";
    GLuint car = safeImgLoad(img_file);
    GLuint bg = safeImgLoad(bg_file);

    //create world
    Car a;

    // start main loop
    SDL_Event event;
    char * keyname;
    int i = 0;
    while(true)
    {
        glClear(GL_COLOR_BUFFER_BIT);
        //printf("%lf, %lf, %lf\n", a.location.x, a.location.y, a.direction);
        drawScene(a, car, bg);
        SDL_GL_SwapBuffers();
        SDL_Delay(50);
        while(SDL_PollEvent(&event) == 1)
        {
            switch(event.type)
            {
                case SDL_KEYDOWN:
                    switch(event.key.keysym.sym)
                    {
                        case SDLK_q:
                            exit(0);
                            break;
                        case SDLK_a:
                            a.wheel(-1.5);
                            break;
                        case SDLK_d:
                            a.wheel(1.5);
                            break;
                        default:
                            keyname = SDL_GetKeyName(event.key.keysym.sym);
                            printf("key pressed: %s\n", keyname);
                    }
                    break;
                case SDL_KEYUP:
                    switch(event.key.keysym.sym)
                    {
                        case SDLK_a:
                            a.wheel(0.0);
                            break;
                        case SDLK_d:
                            a.wheel(0.0);
                            break;
                        default:
                            keyname = SDL_GetKeyName(event.key.keysym.sym);
                            printf("key released: %s\n", keyname);
                    }
                    break;
                default:
                    printf("other event\n");
            }
        }
        for (int n = 0; n < 10; n++)
            a.move(.005);
        i++;
    }
}
Beispiel #13
0
int F1SpiritApp::gameoptions_cycle(KEYBOARDSTATE *k)
{
	if (state_cycle == 0) {

		menu_fading = -1;
		menu_fading_ctnt = MENU_CONSTANT;
		menu_current_menu = 5;

		/* ... */

	} 

	if (menu_fading == 0) {} else {
		if (menu_fading > 0)
			menu_fading_ctnt++;
		else
			menu_fading_ctnt--;

		if (menu_fading_ctnt <= 0 && menu_fading == -1) {
			menu_fading = 0;
		} 

		if (menu_fading_ctnt >= MENU_CONSTANT && menu_fading == 1) {
			menu_fading = 0;
			race_game->race_state = 3;
			race_game->race_state_timmer = 0;
			race_desired_action = 0;
			Sound_unpause_music();
			race_game->resumeSFX();
			race_game->rain_channel = 0;
			return APP_STATE_RACE;
		} 

		if (menu_fading_ctnt >= MENU_CONSTANT && menu_fading == 2) {
			menu_fading = 0;
			Sound_unpause_music();
			race_game->resumeSFX();
			race_game->rain_channel = 0;
			return APP_STATE_RACE;
		} 

		if (menu_fading_ctnt >= MENU_CONSTANT && menu_fading == 3) {
			menu_fading = 0;
			race_game->race_state = 3;
			race_game->race_state_timmer = 0;
			race_desired_action = 1;
			Sound_unpause_music();
			race_game->resumeSFX();
			race_game->rain_channel = 0;
			return APP_STATE_RACE;
		} 
	} 

	if (state_cycle == 0 || menu_state == MENU_CONSTANT*2 || menu_redefining_key || menu_force_rebuild_menu) {
		int browsing = 0;

		if (menu_options[1] != 0)
			browsing = 1;

		if (state_cycle != 0) {

#ifdef F1SPIRIT_DEBUG_MESSAGES
			output_debug_message("Executing gameoptions action: %i(%i)\n", menu_option_type[browsing][menu_selected[browsing]], menu_option_parameter[browsing][menu_selected[browsing]]);
#endif

			switch (menu_option_type[browsing][menu_selected[browsing]]) {

				case 0:  /* QUIT RACE: */
					menu_fading = 1;
					menu_fading_ctnt = 0;
					break;

				case 1:  /* MENU CHANGE: */
					menu_current_menu = menu_option_parameter[browsing][menu_selected[browsing]];

					if (menu_current_menu == 23) {
						menu_readme_start_y = 0;
						menu_readme_move_y = 0;
					} 

					break;

				case 7:  /* SET A KEY: */
					break;

				case 8:  /* SET A JOYSTICK: */
					menu_current_menu = menu_option_parameter[browsing][menu_selected[browsing]];

					{
						int i;
						FILE *fp;
						PlayerCCar *v;
						current_player->set_joystick(menu_selected[0] - 7, menu_selected[1] - 1);
						i = menu_selected[0] - 7;
						v = race_game->player_cars[i];

						if (menu_selected[1] - 1 == -1) {
							v->up = current_player->get_key(i, 0);
							v->down = current_player->get_key(i, 1);
							v->left = current_player->get_key(i, 2);
							v->right = current_player->get_key(i, 3);
							v->accelerate = current_player->get_key(i, 4);
							v->brake = current_player->get_key(i, 5);
						} else {
							int j = menu_selected[1] - 1;
							v->up = k->joystick_0_pos + j * k->joystick_size + 2;
							v->down = k->joystick_0_pos + j * k->joystick_size + 3;
							v->left = k->joystick_0_pos + j * k->joystick_size;
							v->right = k->joystick_0_pos + j * k->joystick_size + 1;
							v->accelerate = k->joystick_0_pos + j * k->joystick_size + 4;
							v->brake = k->joystick_0_pos + j * k->joystick_size + 5;
						} 

						if (v->up < 0)
							v->up = 0;

						if (v->up >= k->k_size)
							v->up = 0;

						if (v->down < 0)
							v->down = 0;

						if (v->down >= k->k_size)
							v->down = 0;

						if (v->left < 0)
							v->left = 0;

						if (v->left >= k->k_size)
							v->left = 0;

						if (v->up < 0)
							v->up = 0;

						if (v->right >= k->k_size)
							v->right = 0;

						if (v->up < 0)
							v->up = 0;

						if (v->accelerate >= k->k_size)
							v->accelerate = 0;

						if (v->up < 0)
							v->up = 0;

						if (v->brake >= k->k_size)
							v->brake = 0;

						v = 0;

						fp = f1open(player_filename, "wb", USERDATA);

						if (fp != 0) {
							current_player->save(fp);
							fclose(fp);
						} 
					}

					break;

				case 11:  /* MENU CHANGE TO SUBMENU: */
					menu_current_menu = menu_option_parameter[browsing][menu_selected[browsing]];
					break;

				case 13: { /* CONTINUE RACE: */
						menu_selecting_player++;
						menu_fading = 2;
						menu_fading_ctnt = 0;
					}

					break;

				case 15: { /* CHANGE MUSIC VOLUME: */
					}

					break;

				case 16: { /* CHANGE SFX VOLUME: */
					}

					break;

				case 24: { /* RESTART RACE: */
						menu_selecting_player++;
						menu_fading = 3;
						menu_fading_ctnt = 0;

						// also stop music/sfx on restart
						Mix_HaltChannel(SFX_RAIN);
						Sound_pause_music();
					}

					break;

			} 
		} 

		delete []menu_title[0];

		menu_title[0] = 0;

		delete []menu_options[0];

		menu_options[0] = 0;

		delete []menu_title[1];

		menu_title[1] = 0;

		delete []menu_options[1];

		menu_options[1] = 0;

#ifdef F1SPIRIT_DEBUG_MESSAGES

		output_debug_message("Generating a new gameoptions menu: %i\n", menu_current_menu);

#endif

		switch (menu_current_menu) {

			case 5:

			case 6:

			case 7:

			case 8:

			case 19:

			case 20:

			case 22:

			case 24: {
					int i, l, pos;
					char *volumes[5] = {"NONE", "LOW ", "MED.", "HIGH", "MAX."};

					l = strlen("PLAYER 000\n") * current_player->get_nplayers() + strlen("CONTINUE\nQUIT\nRESTART\n\nMUSIC VOL: MAX.\nSFX VOL: MAX.\nPLAYER 1\nPLAYER 2\nPLAYER 3\nPLAYER 4\n") + 1;
					if (arcade)
						l = strlen("CONTINUE\nQUIT\n\nMUSIC VOL: MAX.\nSFX VOL: MAX.\nPLAYER 1\n")+1;
					menu_options[0] = new char[l];
					pos = 0;
					{
						int v1 = 0, v2 = 0;
						v1 = current_player->get_music_volume() / 32;
						v2 = current_player->get_sfx_volume() / 32;

						if (arcade)
							sprintf(menu_options[0], "CONTINUE\nQUIT\n\nMUSIC VOL: %s\nSFX VOL: %s\n", volumes[v1], volumes[v2]);
						else
							sprintf(menu_options[0], "CONTINUE\nQUIT\nRESTART\n\nMUSIC VOL: %s\nSFX VOL: %s\n", volumes[v1], volumes[v2]);
					}

					pos = strlen(menu_options[0]);

					if(arcade) {
						for (i = 0;i < 1;i++) {
							sprintf(menu_options[0] + pos, "PLAYER %i\n", i + 1);
							pos = strlen(menu_options[0]);
						} 
					} else 
					{
						for (i = 0;i < current_player->get_nplayers();i++) {
							sprintf(menu_options[0] + pos, "PLAYER %i\n", i + 1);
							pos = strlen(menu_options[0]);
						} 
					}

					menu_title[0] = new char[strlen("PAUSE") + 1];

					strcpy(menu_title[0], "PAUSE");

					if (arcade)
						menu_noptions[0] = 5+1;
					else
						menu_noptions[0] = current_player->get_nplayers() + 7;

					menu_option_type[0][0] = 13;
					menu_option_type[0][1] = 0;

					if (arcade) {
						menu_option_type[0][2] = -1;
						menu_option_type[0][3] = 15;
						menu_option_type[0][4] = 16;
						menu_option_type[0][5] = 11;
						menu_option_parameter[0][5] = 22;
					} else 
					{
						menu_option_type[0][2] = 24;
						menu_option_type[0][3] = -1;
						menu_option_type[0][4] = 15;
						menu_option_type[0][5] = 16;
						menu_option_type[0][6] = 11;
						menu_option_parameter[0][6] = 22;

						for (i = 0;i < current_player->get_nplayers();i++) {
							menu_option_type[0][i + 7] = 11;
							menu_option_parameter[0][i + 7] = 22;
						} 
					}

					menu_first_option[0] = 0;
				}

				if (menu_current_menu == 22) {
					menu_title[1] = 0;
					menu_options[1] = new char[strlen("KEYBOARD CFG.\nJOYSTICK/KEYS\nBACK\n") + 1];
					strcpy(menu_options[1], "KEYBOARD CFG.\nJOYSTICK/KEYS\nBACK\n");
					menu_noptions[1] = 3;
					menu_option_type[1][0] = 1;
					menu_option_type[1][1] = 1;
					menu_option_type[1][2] = 1;
					menu_option_parameter[1][0] = 7;
					menu_option_parameter[1][1] = 8;
					menu_option_parameter[1][2] = 5;
					menu_first_option[1] = 0;
				} 

				if (menu_current_menu == 7) {
					char tmp[256];
					menu_title[1] = 0;
					sprintf(tmp, "GEAR UP: %s\nGEAR DOWN: %s\nLEFT: %s\nRIGHT: %s\nACCEL.: %s\nBRAKE: %s\nBACK\n",
					        SDL_GetKeyName(SDLKey(current_player->get_key(menu_selected[0] - 6, 0))),
					        SDL_GetKeyName(SDLKey(current_player->get_key(menu_selected[0] - 6, 1))),
					        SDL_GetKeyName(SDLKey(current_player->get_key(menu_selected[0] - 6, 2))),
					        SDL_GetKeyName(SDLKey(current_player->get_key(menu_selected[0] - 6, 3))),
					        SDL_GetKeyName(SDLKey(current_player->get_key(menu_selected[0] - 6, 4))),
					        SDL_GetKeyName(SDLKey(current_player->get_key(menu_selected[0] - 6, 5))));
					//    strupr(tmp);
					menu_options[1] = new char[strlen(tmp) + 1];
					strcpy(menu_options[1], tmp);
					menu_noptions[1] = 7;
					menu_option_type[1][0] = 7;
					menu_option_type[1][1] = 7;
					menu_option_type[1][2] = 7;
					menu_option_type[1][3] = 7;
					menu_option_type[1][4] = 7;
					menu_option_type[1][5] = 7;
					menu_option_type[1][6] = 1;
					menu_option_parameter[1][0] = 7;
					menu_option_parameter[1][1] = 7;
					menu_option_parameter[1][2] = 7;
					menu_option_parameter[1][3] = 7;
					menu_option_parameter[1][4] = 7;
					menu_option_parameter[1][5] = 7;
					menu_option_parameter[1][6] = 6;
					menu_first_option[1] = 0;

					if (current_player->get_joystick(menu_selected[0]) != -1) {
						current_player->set_joystick(menu_selected[0], -1);
						{
							FILE *fp;

							fp = f1open(player_filename, "wb", USERDATA);

							if (fp != 0) {
								current_player->save(fp);
								fclose(fp);
							} 
						}
					} 
				} 

				if (menu_current_menu == 8) {
					int nj = SDL_NumJoysticks();
					int i, pos;

					menu_options[1] = new char[nj * strlen("JOYSTICK 000\n") + strlen("KEYBOARD\nBACK\n") + 1];
					pos = 0;
					sprintf(menu_options[1] + pos, "KEYBOARD\n");
					pos = strlen(menu_options[1]);

					for (i = 0;i < nj;i++) {
						sprintf(menu_options[1] + pos, "JOYSTICK %i\n", i);
						pos = strlen(menu_options[1]);
					} 

					sprintf(menu_options[1] + pos, "BACK\n");

					menu_noptions[1] = nj + 2;

					for (i = 0;i < nj + 1;i++) {
						menu_option_type[1][i] = 8;
						menu_option_parameter[1][i] = 6;
					} 

					menu_option_type[1][nj + 1] = 1;

					menu_option_parameter[1][nj + 1] = 6;

					menu_first_option[1] = 0;
				} 
		} 


		if ((menu_options[1] == 0 && menu_prev_nmenus != 2 && !menu_force_rebuild_menu)) {
			menu_selected[0] = 0;
			menu_selected_timmer[0] = 0;
		} 

		if (!menu_redefining_key && !menu_force_rebuild_menu)
			menu_selected[1] = 0;

		if (!menu_redefining_key && !menu_force_rebuild_menu)
			menu_selected_timmer[1] = 0;

		if (!menu_redefining_key && !menu_force_rebuild_menu)
			menu_state = 0;

		menu_force_rebuild_menu = false;
	} else {
		if (menu_fading == 0) {
			if (menu_state < MENU_CONSTANT)
				menu_state++;

			if (menu_state == MENU_CONSTANT) {
				menu_prev_nmenus = 0;

				if (menu_options[0] != 0)
					menu_prev_nmenus++;

				if (menu_options[1] != 0)
					menu_prev_nmenus++;
			} 

			if (menu_state > MENU_CONSTANT)
				menu_state++;
		} 
	} 


	if (menu_readme_move_y != 0) {
		menu_readme_start_y += menu_readme_move_y;

		if (menu_readme_move_y > 0)
			menu_readme_move_y--;

		if (menu_readme_move_y < 0)
			menu_readme_move_y++;

		if (menu_readme_start_y < 0)
			menu_readme_start_y = 0;
	} 

	if (menu_state == MENU_CONSTANT) {
		int browsing = 0;

		if (menu_options[1] != 0)
			browsing = 1;

		if (!menu_redefining_key) {
			if ((k->keyboard[SDLK_DOWN] && !k->old_keyboard[SDLK_DOWN]) ||
			        (k->keyboard[SDLK_RIGHT] && !k->old_keyboard[SDLK_RIGHT])) {
				if ((k->keyboard[SDLK_RIGHT] && !k->old_keyboard[SDLK_RIGHT]) &&
				        (menu_option_type[browsing][menu_selected[browsing]] == 15 ||
				         menu_option_type[browsing][menu_selected[browsing]] == 16)) {
					if (menu_option_type[browsing][menu_selected[browsing]] == 15) {
						int v = current_player->get_music_volume();

						if (v == 128)
							current_player->set_music_volume(0);

						if (v == 96)
							current_player->set_music_volume(128);

						if (v == 64)
							current_player->set_music_volume(96);

						if (v == 32)
							current_player->set_music_volume(64);

						if (v == 0)
							current_player->set_music_volume(32);
					} else {
						int v = current_player->get_sfx_volume();

						if (v == 128)
							current_player->set_sfx_volume(0);

						if (v == 96)
							current_player->set_sfx_volume(128);

						if (v == 64)
							current_player->set_sfx_volume(96);

						if (v == 32)
							current_player->set_sfx_volume(64);

						if (v == 0)
							current_player->set_sfx_volume(32);
					} 

					menu_force_rebuild_menu = true;

					Sound_play(S_menu_move, 128);

					{
						FILE *fp;

						fp = f1open(player_filename, "wb", USERDATA);

						if (fp != 0) {
							current_player->save(fp);
							fclose(fp);
						} 
					}
				} else {
					menu_selected[browsing]++;

					if (menu_option_type[browsing][menu_selected[browsing]] == -1)
						menu_selected[browsing]++;

					Sound_play(S_menu_move, 128);

					if (menu_selected[browsing] >= menu_noptions[browsing])
						menu_selected[browsing] -= menu_noptions[browsing];

					menu_selected_timmer[browsing] = 0;
				} 
			} 

			if ((k->keyboard[SDLK_UP] && !k->old_keyboard[SDLK_UP]) ||
			        (k->keyboard[SDLK_LEFT] && !k->old_keyboard[SDLK_LEFT])) {

				if ((k->keyboard[SDLK_LEFT] && !k->old_keyboard[SDLK_LEFT]) &&
				        (menu_option_type[browsing][menu_selected[browsing]] == 15 ||
				         menu_option_type[browsing][menu_selected[browsing]] == 16)) {
					if (menu_option_type[browsing][menu_selected[browsing]] == 15) {
						int v = current_player->get_music_volume();

						if (v == 128)
							current_player->set_music_volume(96);

						if (v == 96)
							current_player->set_music_volume(64);

						if (v == 64)
							current_player->set_music_volume(32);

						if (v == 32)
							current_player->set_music_volume(0);

						if (v == 0)
							current_player->set_music_volume(128);
					} else {
						int v = current_player->get_sfx_volume();

						if (v == 128)
							current_player->set_sfx_volume(96);

						if (v == 96)
							current_player->set_sfx_volume(64);

						if (v == 64)
							current_player->set_sfx_volume(32);

						if (v == 32)
							current_player->set_sfx_volume(0);

						if (v == 0)
							current_player->set_sfx_volume(128);
					} 

					menu_force_rebuild_menu = true;

					Sound_play(S_menu_move, 128);

					{
						FILE *fp;

						fp = f1open(player_filename, "wb", USERDATA);

						if (fp != 0) {
							current_player->save(fp);
							fclose(fp);
						} 
					}
				} else {
					menu_selected[browsing]--;

					if (menu_option_type[browsing][menu_selected[browsing]] == -1)
						menu_selected[browsing]--;

					Sound_play(S_menu_move, 128);

					if (menu_selected[browsing] < 0)
						menu_selected[browsing] += menu_noptions[browsing];

					menu_selected_timmer[browsing] = 0;
				} 
			} 

			if (k->keyboard[SDLK_ESCAPE] && !k->old_keyboard[SDLK_ESCAPE]) {
				if (menu_current_menu == 5)
					menu_selected[browsing] = 0;
				else
					menu_selected[browsing] = menu_noptions[browsing] - 1;

				Sound_play(S_menu_select, 128);

				menu_state++;
			} 

			if (menu_option_type[browsing][menu_selected[browsing]] != 2 &&
			        ((k->keyboard[SDLK_SPACE] && !k->old_keyboard[SDLK_SPACE])
#ifdef PANDORA
					||  (k->keyboard[SDLK_PAGEDOWN] && !k->old_keyboard[SDLK_PAGEDOWN])
#endif
				))
				{
				if (menu_option_type[browsing][menu_selected[browsing]] != 19 &&
				        menu_option_type[browsing][menu_selected[browsing]] != 20)
					Sound_play(S_menu_select, 128);

				if (menu_option_type[browsing][menu_selected[browsing]] == 7) {
					/* redefining a key: */
					menu_redefining_key = true;
				} else {
					if (menu_option_type[browsing][menu_selected[browsing]] == 15 ||
					        menu_option_type[browsing][menu_selected[browsing]] == 16 ||
					        menu_option_type[browsing][menu_selected[browsing]] == 19 ||
					        menu_option_type[browsing][menu_selected[browsing]] == 20) {
						if (menu_option_type[browsing][menu_selected[browsing]] == 15) {
							int v = current_player->get_music_volume();

							if (v == 128)
								current_player->set_music_volume(0);

							if (v == 96)
								current_player->set_music_volume(128);

							if (v == 64)
								current_player->set_music_volume(96);

							if (v == 32)
								current_player->set_music_volume(64);

							if (v == 0)
								current_player->set_music_volume(32);
						} 

						if (menu_option_type[browsing][menu_selected[browsing]] == 16) {
							int v = current_player->get_sfx_volume();

							if (v == 128)
								current_player->set_sfx_volume(0);

							if (v == 96)
								current_player->set_sfx_volume(128);

							if (v == 64)
								current_player->set_sfx_volume(96);

							if (v == 32)
								current_player->set_sfx_volume(64);

							if (v == 0)
								current_player->set_sfx_volume(32);
						} 

						menu_force_rebuild_menu = true;
					} else {
						menu_state++;
					} 
				} 
			} 


		} else {
			int i, np;
			np = menu_selected[0] - 6;
			PlayerCCar *v = race_game->player_cars[np];

			for (i = 0;i < SDLK_LAST;i++) {
				if (k->keyboard[i] && !k->old_keyboard[i]) {
					current_player->set_key(np, menu_selected[1], i);

					if (current_player->get_joystick(np) == -1) {
						v->up = current_player->get_key(np, 0);
						v->down = current_player->get_key(np, 1);
						v->left = current_player->get_key(np, 2);
						v->right = current_player->get_key(np, 3);
						v->accelerate = current_player->get_key(np, 4);
						v->brake = current_player->get_key(np, 5);
					} 

					if (v->up < 0)
						v->up = 0;

					if (v->up >= k->k_size)
						v->up = 0;

					if (v->down < 0)
						v->down = 0;

					if (v->down >= k->k_size)
						v->down = 0;

					if (v->left < 0)
						v->left = 0;

					if (v->left >= k->k_size)
						v->left = 0;

					if (v->up < 0)
						v->up = 0;

					if (v->right >= k->k_size)
						v->right = 0;

					if (v->up < 0)
						v->up = 0;

					if (v->accelerate >= k->k_size)
						v->accelerate = 0;

					if (v->up < 0)
						v->up = 0;

					if (v->brake >= k->k_size)
						v->brake = 0;

					v = 0;

					menu_redefining_key = false;

					menu_force_rebuild_menu = true;

					Sound_play(S_menu_select, 128);

					{
						FILE *fp;

						fp = f1open(player_filename, "wb", USERDATA);

						if (fp != 0) {
							current_player->save(fp);
							fclose(fp);
						} 
					}
				} 
			} 
		} 
	} 

	menu_selected_timmer[0]++;

	menu_selected_timmer[1]++;

	return APP_STATE_GAMEOPTIONS;
} 
Beispiel #14
0
    SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey);
#if 0
    SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode);
    SDL_Log("key down, handled=%s, ext?=%s, released?=%s, menu key down?=%s, repeat count=%d, native scan code=%d, was down?=%s, vkey=%d, sdl scan code=%d (%s), sdl key code=%d (%s)\n",
        (args->Handled ? "1" : "0"),
        (args->KeyStatus.IsExtendedKey ? "1" : "0"),
        (args->KeyStatus.IsKeyReleased ? "1" : "0"),
        (args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
        args->KeyStatus.RepeatCount,
        args->KeyStatus.ScanCode,
        (args->KeyStatus.WasKeyDown ? "1" : "0"),
        args->VirtualKey,
        sdlScancode,
        SDL_GetScancodeName(sdlScancode),
        keycode,
        SDL_GetKeyName(keycode));
    //args->Handled = true;
    //VirtualKey vkey = args->VirtualKey;
#endif
    SDL_SendKeyboardKey(SDL_PRESSED, sdlScancode);
}

void
WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args)
{
    SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey);
#if 0
    SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode);
    SDL_Log("key up, handled=%s, ext?=%s, released?=%s, menu key down?=%s, repeat count=%d, native scan code=%d, was down?=%s, vkey=%d, sdl scan code=%d (%s), sdl key code=%d (%s)\n",
        (args->Handled ? "1" : "0"),
        (args->KeyStatus.IsExtendedKey ? "1" : "0"),
Beispiel #15
0
std::string SDLInputState::getKeyName(int key) {
	return std::string(SDL_GetKeyName((SDL_Keycode)key));
}
void Camera::keyboard(const SDL_KeyboardEvent &eventKey) {
	switch(eventKey.keysym.sym) {
	case SDLK_UP:
	case SDLK_DOWN:
	case SDLK_LEFT:
	case SDLK_RIGHT:
	case SDLK_PAGEUP:
	case SDLK_PAGEDOWN:
		if (moveSensitivity == 0) moveSensitivity = 300;
		break;
	default:
		break;
	}
	switch(eventKey.keysym.sym) {
	case SDLK_UP:
		up = (eventKey.type == SDL_KEYDOWN);
		break;
	case SDLK_DOWN:
		down = (eventKey.type == SDL_KEYDOWN);
		break;
	case SDLK_LEFT:
		left = (eventKey.type == SDL_KEYDOWN);
		break;
	case SDLK_RIGHT:
		right = (eventKey.type == SDL_KEYDOWN);
		break;
	case SDLK_PAGEUP:
		pageUp = (eventKey.type == SDL_KEYDOWN);
		break;
	case SDLK_PAGEDOWN:
		pageDown = (eventKey.type == SDL_KEYDOWN);
		break;
	case SDLK_ESCAPE:
		std::cout << std::endl;
		exit(0);
		break;
    case SDLK_KP0:
        moveSensitivity = 0;
        break;
    case SDLK_KP1:
        moveSensitivity = 300;
        break;
    case SDLK_KP2:
        moveSensitivity = 1000;
        break;
    case SDLK_KP3:
        moveSensitivity = 6000;
        break;
	default :
		switch(SDL_GetKeyName(eventKey.keysym.sym)[0]) {
			case 'q':
				std::cout << std::endl;
				exit(0);
				break;
            case 'a' :
            	if (moveSensitivity == 0) moveSensitivity = 300;
                up = true;
                break;
            case 'e' :
        		moveSensitivity = 1500;
                autoPilot = true;
                break;
            case 'z' :
            	autoPilot = false;
                up = false;
                break;
			case 's':
				if (eventKey.type != SDL_KEYDOWN) break;
				moveSensitivity = std::min(50000,std::max(moveSensitivity+1, moveSensitivity*10/9));
				break;
			case 'x':
				if (eventKey.type != SDL_KEYDOWN) break;
				moveSensitivity = std::max(10, moveSensitivity*9/10);
				break;
			case 'p': // _Print _Position
				if (eventKey.type != SDL_KEYDOWN) break;
				std::cout << *this << std::endl;
				break;
			case 't': {
                char* file = new char[256];
                memset(file,'\n',256);
                sprintf(file,"city-builder_%d_%d.bmp",Chose::initialSeed,(int)time(NULL));
				takeScreenshot(file);
				break;
				}
			case 'c':
		        moveSensitivity = 0;
		        break;
		    case 'v':
		        moveSensitivity = 300;
		        break;
		    case 'b':
		        moveSensitivity = 1000;
		        break;
		    case 'n':
		        moveSensitivity = 6000;
		        break;
			default:
				break;
		}
		break;
	}
}
Beispiel #17
0
int
main(int argc, char *argv[])
{
		initSDL();
		initGL();

		std::vector<Sprite> sprites;
		sprites.push_back(Sprite("test.png"));
		sprites.push_back(Sprite("element0.png"));
		sprites.push_back(Sprite("element1.png"));
		sprites.push_back(Sprite("element2.png"));
		sprites.push_back(Sprite("element3.png"));

		int coords[][2] = { {0, 0},
							{200, 0},
							{300, 200},
							{400, 300} };

		float pulse = 1.0f, pulseChange = 0.01f;
		int anim = 1;

		while ( ! SDL_GetKeyState(NULL)[SDLK_ESCAPE] ) // Exit by pressing Back button
		{
		clearScreen();
		int mouseX = 0, mouseY = 0, buttons = 0;
		buttons = SDL_GetMouseState(&mouseX, &mouseY);

		sprites[0].draw(mouseX - sprites[0].w/2, mouseY - sprites[0].h/2, sprites[0].w, sprites[0].h, buttons ? 0 : 1, 1, 1, pulse);

		sprites[1].draw(coords[0][0], coords[0][1]);
		sprites[2].draw(coords[1][0], coords[1][1], sprites[2].w * pulse * 4, sprites[2].h * pulse * 4);
		sprites[3].draw(coords[2][0], coords[2][1], sprites[3].w * pulse * 4, sprites[3].h * 2);
		sprites[4].draw(coords[3][0], coords[3][1], sprites[4].w, sprites[4].h * pulse * 2);

		SDL_GL_SwapBuffers();
		SDL_Event event;
		while( SDL_PollEvent(&event) )
		{
			if(event.type == SDL_VIDEORESIZE)
			{
			// Reload textures to OpenGL
			initGL();
			for(int i = 0; i < sprites.size(); i++)
				sprites[i].loadTexture();
			}
			if(event.type == SDL_KEYUP || event.type == SDL_KEYDOWN)
			{
				__android_log_print(ANDROID_LOG_INFO, "Hello", "SDL key event: evt %s state %s key %4d %12s scancode %4d mod %2d unicode %d", event.type == SDL_KEYUP ? "UP	 " : "DOWN" , event.key.state == SDL_PRESSED ? "PRESSED " : "RELEASED", (int)event.key.keysym.sym, SDL_GetKeyName(event.key.keysym.sym), (int)event.key.keysym.scancode, (int)event.key.keysym.mod, (int)event.key.keysym.unicode);
				if(event.key.keysym.sym == SDLK_ESCAPE)
					return 0;
			}
		}

		// Some kinda animation

		pulse += pulseChange;
		if(pulse > 1.0f)
			pulseChange = -0.01f;
		if(pulse < 0)
			pulseChange = 0.01f;

		for(int i = 0; i < 4; i++)
		{
			coords[i][0] += anim;
			coords[i][1] += anim;
		}
		if( coords[0][0] < 0 )
			anim = 1;
		if( coords[3][1] > screenHeight )
			anim = -1;
		}

		SDL_Quit();
		return 0;
}
void displayKey(SDL_KeyboardEvent *key)
{
	printf( "%s (%d)\n", SDL_GetKeyName(key->keysym.sym), key->keysym.sym);
}
Beispiel #19
0
void KrEventManager::HandleEvent( const SDL_Event& event, KrEngine* engine )
{
    if ( event.type == SDL_KEYDOWN && keyFocus >= 0) //maks
    {
        //	- the tab key changes key focus.
        //	- accelerators are checked
        //	- keys passed through to the handler.

#ifdef DEBUG
        GLOUTPUT( "KeyDown mod=%d sym=%d, unicode=%d, name=%s\n", event.key.keysym.mod, event.key.keysym.sym, event.key.keysym.unicode, SDL_GetKeyName(event.key.keysym.sym)); //maks
#endif

        if (    event.key.keysym.sym == SDLK_TAB
                && keyListeners.Count() > 1 )
        {
            if ( event.key.keysym.mod & KMOD_SHIFT )
                ChangeKeyFocus( keyFocus + keyListeners.Count() - 1 );
            else
                ChangeKeyFocus( keyFocus + 1 );
            return;
        }

        for( int i=0; i<accelListeners.Count(); ++i )
        {
            int sym = accelListeners[i].keysym;
            int mod = accelListeners[i].keymod;

            if (    event.key.keysym.sym == sym &&
                    event.key.keysym.mod & mod &&
                    keyListeners.Count() &&
                    accelListeners[i].target == keyListeners[ keyFocus ]) //maks: send accelerators for key focus owners
            {
                accelListeners[i].target->Accelerate( true, mod, sym ); //maks
                return;
            }
        }

        if ( keyListeners.Count() > 0 )
        {
            keyFocus = GlClamp( keyFocus, 0, int( keyListeners.Count()-1 ) );
            KrWidget* widget = keyListeners[ keyFocus ];

            // Go up the chain until handled.
            while( widget && !widget->KeyEvent( event ) )
            {
                widget = widget->ParentWidget();
            }
        }
    }
    else if ( event.type == SDL_KEYUP )
    {
        // - only accelerates key up
        for( int i=0; i<accelListeners.Count(); ++i )
        {
            if (    event.key.keysym.sym == accelListeners[i].keysym &&
                    event.key.keysym.mod & accelListeners[i].keymod &&
                    keyFocus >= 0 &&
                    keyListeners.Count() &&
                    accelListeners[i].target == keyListeners[ keyFocus ]) //maks
            {
                accelListeners[i].target->Accelerate( false, event.key.keysym.mod, event.key.keysym.sym ); //maks
                return;
            }
        }

        //Send shift key up
        if ( keyListeners.Count() > 0 && (event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT))
        {
            keyFocus = GlClamp( keyFocus, 0, int( keyListeners.Count()-1 ) );
            KrWidget* widget = keyListeners[ keyFocus ];

            // Go up the chain until handled.
            while( widget && !widget->KeyEvent( event ) )
            {
                widget = widget->ParentWidget();
            }
        }
    }
    else if ( event.type == SDL_MOUSEMOTION )
    {
        GlDynArray<KrImage*> hitArray;
        KrWidget* hit = 0;
        //int window = engine->GetWindowFromPoint( event.motion.x, event.motion.y );

        KrVector2T< GlFixed > object;

#ifndef _WIN32_WCE
        if(mouseDown && mouseFocus) //maks
        {
            //Don't change the focus if mouse button is down
            //Don't works on Pocket PC. In input.ged don't close the SIP keyboard (only send keyFocus = true)

            hit = mouseFocus;
            hit->ScreenToObject( event.motion.x, event.motion.y, &object/*, window*/ );
        }
        else
#endif
        {
            engine->Tree()->HitTest( event.motion.x, event.motion.y,
                                     KrImageTree::ALWAYS_INSIDE_BOX, //| GET_ALL_HITS,
                                     &hitArray/*,
				&window*/ );


            for( int i=0; i<hitArray.Count(); ++i )
            {
                KrImNode* parent = hitArray[i]->Parent();
                while( parent )
                {
                    if ( parent->ToWidget() )
                    {
                        hit = parent->ToWidget();
                        hit->ScreenToObject( event.motion.x, event.motion.y, &object/*, window*/ );
                        break;
                    }
                    parent = parent->Parent();
                }
            }
        }

        // 1) Something has the focus. Nothing had it before.
        // 2) Something has the focus, something else had it before.
        // 3) Something loses the focus.
        // 5) The thing with focus gets a move.
        if ( hit && !mouseFocus )
        {
            mouseFocus = hit;
            mouseFocus->MouseIn( mouseDown, true );
            mouseFocus->MouseMove( mouseDown, object.x.ToIntRound(), object.y.ToIntRound() );
        }
        else if ( hit && mouseFocus && mouseFocus != hit )
        {
            mouseFocus->MouseIn( mouseDown, false );
            mouseFocus = hit;
            mouseFocus->MouseIn( mouseDown, true );
            mouseFocus->MouseMove( mouseDown, object.x.ToIntRound(), object.y.ToIntRound() );
        }
        else if ( !hit && mouseFocus )
        {
            mouseFocus->MouseIn( mouseDown, false );
            mouseFocus = hit;
        }
        else if ( hit && hit == mouseFocus )
        {
            GLASSERT( hit == mouseFocus );
            mouseFocus->MouseMove( mouseDown, object.x.ToIntRound(), object.y.ToIntRound() );
        }
        else if ( !hit && !mouseFocus )
        {
            // nothing to do
        }
        else
        {
            GLASSERT( 0 );
        }

    }
    else if ( event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP )
    {
        if ( event.button.button == SDL_BUTTON_LEFT )
        {
            bool down = event.button.state != 0;	// & SDL_BUTTON_LMASK;
            if ( down != mouseDown )
            {
                mouseDown = down;
                if ( mouseFocus )
                {
                    int window = engine->GetWindowFromPoint( event.motion.x, event.motion.y );
                    KrVector2T< GlFixed > object;
                    mouseFocus->ScreenToObject( event.motion.x, event.motion.y, &object/*, window*/ );

                    mouseFocus->MouseClick( mouseDown ? KrWidget::LEFT_DOWN : KrWidget::LEFT_UP,
                                            object.x.ToIntRound(),
                                            object.y.ToIntRound() );
                }
                else //maks
                {
                    if(
                        keyFocus >= 0 && keyFocus < keyListeners.Count() &&
                        !newListnerFocus //maks: Only remove the focus if the widget don't has changed the focus in this cycle (solve focus bug in Math for Kids.ged)
                    )
                    {
                        keyListeners[ keyFocus ]->KeyFocus( false );
                        keyFocus = -1;
                        FocusState(false);
                    }
                }
            }
        }
        else if ( event.button.button == SDL_BUTTON_RIGHT ) //maks
        {
            bool down = event.button.state != 0;
            if ( down != mouseDown )
            {
                mouseDown = down;
                if ( mouseFocus )
                {
                    int window = engine->GetWindowFromPoint( event.motion.x, event.motion.y );
                    KrVector2T< GlFixed > object;
                    mouseFocus->ScreenToObject( event.motion.x, event.motion.y, &object/*, window*/ );

                    mouseFocus->MouseClick( mouseDown ? KrWidget::RIGHT_DOWN : KrWidget::RIGHT_UP,
                                            object.x.ToIntRound(),
                                            object.y.ToIntRound() );
                }
            }
        }
    }

    newListnerFocus = false; //maks
}
Beispiel #20
0
char BEE::append_input(std::string& output, SDL_KeyboardEvent* k) {
	std::string s = "";
	switch (k->keysym.sym) {
		case SDLK_a:
		case SDLK_b:
		case SDLK_c:
		case SDLK_d:
		case SDLK_e:
		case SDLK_f:
		case SDLK_g:
		case SDLK_h:
		case SDLK_i:
		case SDLK_j:
		case SDLK_k:
		case SDLK_l:
		case SDLK_m:
		case SDLK_n:
		case SDLK_o:
		case SDLK_p:
		case SDLK_q:
		case SDLK_r:
		case SDLK_s:
		case SDLK_t:
		case SDLK_u:
		case SDLK_v:
		case SDLK_w:
		case SDLK_x:
		case SDLK_y:
		case SDLK_z: {
			s = SDL_GetKeyName(k->keysym.sym);

			bool should_capitalize = false;
			if (k->keysym.mod & KMOD_SHIFT) {
				should_capitalize = true;
			}
			if (k->keysym.mod & KMOD_CAPS) {
				should_capitalize = !should_capitalize;
			}
			if (!should_capitalize) {
				s = string_lower(s);
			}

			break;
		}

		case SDLK_BACKSLASH: {
			s = "\\";
			if (k->keysym.mod & KMOD_SHIFT) {
				s = "|";
			}
			break;
		}
		case SDLK_BACKSPACE: {
			if (!output.empty()) {
				output.pop_back();
			}
			break;
		}
		case SDLK_BACKQUOTE: {
			s = "`";
			if (k->keysym.mod & KMOD_SHIFT) {
				s = "~";
			}
			break;
		}
		case SDLK_SPACE: {
			s = " ";
			break;
		}
		case SDLK_TAB: {
			s = "	";
			break;
		}

		case SDLK_KP_DIVIDE: {
			s = "/";
			break;
		}
		case SDLK_KP_MULTIPLY: {
			s = "*";
			break;
		}
		case SDLK_KP_MINUS: {
			s = "-";
			break;
		}
		case SDLK_KP_PLUS: {
			s = "+";
			break;
		}
	}

	if (s.empty()) {
		switch(k->keysym.sym) {
			case SDLK_0: {
				s = "0";
				if (k->keysym.mod & KMOD_SHIFT) {
					s = ")";
				}
				break;
			}
			case SDLK_1: {
				s = "1";
				if (k->keysym.mod & KMOD_SHIFT) {
					s = "!";
				}
				break;
			}
			case SDLK_2: {
				s = "2";
				if (k->keysym.mod & KMOD_SHIFT) {
					s = "@";
				}
				break;
			}
			case SDLK_3: {
				s = "3";
				if (k->keysym.mod & KMOD_SHIFT) {
					s = "#";
				}
				break;
			}
			case SDLK_4: {
				s = "4";
				if (k->keysym.mod & KMOD_SHIFT) {
					s = "$";
				}
				break;
			}
			case SDLK_5: {
				s = "5";
				if (k->keysym.mod & KMOD_SHIFT) {
					s = "%";
				}
				break;
			}
			case SDLK_6: {
				s = "6";
				if (k->keysym.mod & KMOD_SHIFT) {
					s = "^";
				}
				break;
			}
			case SDLK_7: {
				s = "7";
				if (k->keysym.mod & KMOD_SHIFT) {
					s = "&";
				}
				break;
			}
			case SDLK_8: {
				s = "8";
				if (k->keysym.mod & KMOD_SHIFT) {
					s = "*";
				}
				break;
			}
			case SDLK_9: {
				s = "9";
				if (k->keysym.mod & KMOD_SHIFT) {
					s = "(";
				}
				break;
			}
			case SDLK_QUOTE: {
				s = "'";
				if (k->keysym.mod & KMOD_SHIFT) {
					s = "\"";
				}
				break;
			}
			case SDLK_COMMA: {
				s = ",";
				if (k->keysym.mod & KMOD_SHIFT) {
					s = "<";
				}
				break;
			}
			case SDLK_EQUALS: {
				s = "=";
				if (k->keysym.mod & KMOD_SHIFT) {
					s = "+";
				}
				break;
			}
			case SDLK_LEFTBRACKET: {
				s = "[";
				if (k->keysym.mod & KMOD_SHIFT) {
					s = "{";
				}
				break;
			}
			case SDLK_MINUS: {
				s = "-";
				if (k->keysym.mod & KMOD_SHIFT) {
					s = "_";
				}
				break;
			}
			case SDLK_PERIOD: {
				s = ".";
				if (k->keysym.mod & KMOD_SHIFT) {
					s = ">";
				}
				break;
			}
			case SDLK_RIGHTBRACKET: {
				s = "]";
				if (k->keysym.mod & KMOD_SHIFT) {
					s = "}";
				}
				break;
			}
			case SDLK_SEMICOLON: {
				s = ";";
				if (k->keysym.mod & KMOD_SHIFT) {
					s = ":";
				}
				break;
			}
			case SDLK_SLASH: {
				s = "/";
				if (k->keysym.mod & KMOD_SHIFT) {
					s = "?";
				}
				break;
			}
		}
	}

	if ((s.empty())&&(k->keysym.mod & KMOD_NUM)) {
		switch(k->keysym.sym) {
			case SDLK_KP_0:
			case SDLK_KP_00:
			case SDLK_KP_000: {
				s = "0";
				break;
			}
			case SDLK_KP_1: {
				s = "1";
				break;
			}
			case SDLK_KP_2: {
				s = "2";
				break;
			}
			case SDLK_KP_3: {
				s = "3";
				break;
			}
			case SDLK_KP_4: {
				s = "4";
				break;
			}
			case SDLK_KP_5: {
				s = "5";
				break;
			}
			case SDLK_KP_6: {
				s = "6";
				break;
			}
			case SDLK_KP_7: {
				s = "7";
				break;
			}
			case SDLK_KP_8: {
				s = "8";
				break;
			}
			case SDLK_KP_9: {
				s = "9";
				break;
			}
			case SDLK_KP_PERIOD: {
				s = ".";
				break;
			}
		}
	}

	output += s;
	return s.c_str()[0];
}
Beispiel #21
0
	void SetKeyButton::DisplayKeyAssignment() {
		Text(*Font, wX+(SCREEN_WIDTH/2.0f) + (wWidth*1.5f),wY+(SCREEN_HEIGHT/2.0f)+(wHeight/2.0f), 0,1,1,1, 1,1,1, "%s",SDL_GetKeyName(*btnkey));
	}
Beispiel #22
0
void draw_options_menu(MenuData *menu) {
	draw_options_menu_bg(menu);
	
	draw_text(AL_Right, 140*(1-menu->fade), 30, "Options", _fonts.mainmenu);
	
	glPushMatrix();
	glTranslatef(100, 100, 0);
	
	/*
	glPushMatrix();
	glTranslatef(SCREEN_W/2 - 100, menu->drawdata[2], 0);
	glScalef(SCREEN_W - 200, 20, 1);
	glColor4f(0,0,0,0.5);
	draw_quad();
	glPopMatrix();
	*/
	
	Texture *bg = get_tex("part/smoke");
	glPushMatrix();
	glTranslatef(menu->drawdata[0], menu->drawdata[2], 0);
	glScalef(menu->drawdata[1]/100.0, 0.2, 1);
	glRotatef(menu->frames*2,0,0,1);
	glColor4f(0,0,0,0.5);
	draw_texture_p(0,0,bg);
	glPopMatrix();
	
	OptionBinding *binds = (OptionBinding*)menu->context;
	OptionBinding *bind;
	
	menu->drawdata[0] += ((SCREEN_W/2 - 100) - menu->drawdata[0])/10.0;
	menu->drawdata[1] += ((SCREEN_W - 200) - menu->drawdata[1])/10.0;
	menu->drawdata[2] += (20*menu->cursor - menu->drawdata[2])/10.0;
	
	int i, caption_drawn = 0;
	
	for(i = 0; i < menu->ecount; i++) {
		if(!menu->entries[i].name)
			continue;
		
		menu->entries[i].drawdata += 0.2 * (10*(i == menu->cursor) - menu->entries[i].drawdata);
		float a = menu->entries[i].drawdata * 0.1;
		
		bind = &(binds[i]);
		int hasbind = bind->enabled;
		float alpha = (!hasbind || bind_isactive(bind))? 1 : 0.5;
		
		if(menu->entries[i].action == NULL) {
			glColor4f(0.5, 0.5, 0.5, 0.7 * alpha);
		} else {
			//glColor4f(0.7 + 0.3 * (1-a), 1, 1, (0.7 + 0.3 * a) * alpha);
			float ia = 1-a;
			glColor4f(0.9 + ia * 0.1, 0.6 + ia * 0.4, 0.2 + ia * 0.8, (0.7 + 0.3 * a) * alpha);
		}
		
		draw_text(AL_Left,
					((hasbind && bind->dependence)? 20 : 0)	// hack hack hack
					+ 20 - menu->entries[i].drawdata, 20*i, menu->entries[i].name, _fonts.standard);
		
		if(hasbind)
		{
			int j, origin = SCREEN_W - 220;
			
			switch(bind->type)
			{
				case BT_IntValue:
					if(bind->valrange_max) {
						char tmp[16];	// who'd use a 16-digit number here anyway?
						snprintf(tmp, 16, "%d", bind_getvalue(bind));
						draw_text(AL_Right, origin, 20*i, tmp, _fonts.standard);
					} else for(j = bind->valcount-1; j+1; --j) {
						if(j != bind->valcount-1)
							origin -= strlen(bind->values[j+1])/2.0 * 20;
						
						if(bind_getvalue(bind) == j) {
							glColor4f(0.9, 0.6, 0.2, alpha);
						} else {
							glColor4f(0.5,0.5,0.5,0.7 * alpha);
						}
							
						draw_text(AL_Right, origin, 20*i, bind->values[j], _fonts.standard);
					}
					break;
				
				case BT_KeyBinding:
					if(bind->blockinput) {
						glColor4f(0.5, 1, 0.5, 1);
						draw_text(AL_Right, origin, 20*i, "Press a key to assign, ESC to cancel", _fonts.standard);
					} else
						draw_text(AL_Right, origin, 20*i, SDL_GetKeyName(tconfig.intval[bind->configentry]), _fonts.standard);
					
					if(!caption_drawn) {
						glColor4f(1,1,1,0.7);
						draw_text(AL_Center, (SCREEN_W - 200)/2, 20*(i-1), "Controls", _fonts.standard);
						caption_drawn = 1;
					}
					break;
				
				case BT_StrValue:
					if(bind->blockinput) {
						glColor4f(0.5, 1, 0.5, 1.0);
						if(strlen(*bind->values))
							draw_text(AL_Right, origin, 20*i, *bind->values, _fonts.standard);
					} else
						draw_text(AL_Right, origin, 20*i, tconfig.strval[bind->configentry], _fonts.standard);
					break;
				
				case BT_Resolution: {
					char tmp[16];
					int w, h;
					
					if(bind->selected == -1) {
						w = video.intended.width;
						h = video.intended.height;
					} else {
						VideoMode *m = &(video.modes[bind->selected]);
						w = m->width;
						h = m->height;
					}
					
					snprintf(tmp, 16, "%dx%d", w, h);
					draw_text(AL_Right, origin, 20*i, tmp, _fonts.standard);
					break;
				}
			}
		}
	}
	
	
	glPopMatrix();
	
	fade_out(menu->fade);
}