예제 #1
0
/**
 * Handles mouse clicks on the minimap. Will change the camera center to the clicked point.
 * @param action Pointer to an action.
 * @param state State that the action handlers belong to.
 */
void MiniMapView::mouseClick(Action *action, State *state)
{
	InteractiveSurface::mouseClick(action, state);

	// The following is the workaround for a rare problem where sometimes
	// the mouse-release event is missed for any reason.
	// However if the SDL is also missed the release event, then it is to no avail :(
	// (this part handles the release if it is missed and now an other button is used)
	if (_isMouseScrolling) {
		if (action->getDetails()->button.button != Options::battleDragScrollButton
		&& 0==(SDL_GetMouseState(0,0)&SDL_BUTTON(Options::battleDragScrollButton))) { // so we missed again the mouse-release :(
			// Check if we have to revoke the scrolling, because it was too short in time, so it was a click
			if ((!_mouseMovedOverThreshold) && ((int)(SDL_GetTicks() - _mouseScrollingStartTime) <= (Options::dragScrollTimeTolerance)))
				{ _camera->centerOnPosition(_posBeforeMouseScrolling); _redraw = true; }
			_isMouseScrolled = _isMouseScrolling = false;
			stopScrolling(action);
		}
	}

	// Drag-Scroll release: release mouse-scroll-mode
	if (_isMouseScrolling)
	{
		// While scrolling, other buttons are ineffective
		if (action->getDetails()->button.button == Options::battleDragScrollButton)
		{
			_isMouseScrolling = false;
			stopScrolling(action);
		}
		else
		{
			return;
		}
		// Check if we have to revoke the scrolling, because it was too short in time, so it was a click
		if ((!_mouseMovedOverThreshold) && ((int)(SDL_GetTicks() - _mouseScrollingStartTime) <= (Options::dragScrollTimeTolerance)))
		{
			_isMouseScrolled = false;
			stopScrolling(action);
			_camera->centerOnPosition(_posBeforeMouseScrolling);
			_redraw = true;
		}
		if (_isMouseScrolled) return;
	}

	if (action->getDetails()->button.button == SDL_BUTTON_RIGHT)
	{
		((MiniMapState*)(state))->btnOkClick(action);
	}

	if (action->getDetails()->button.button == SDL_BUTTON_LEFT)
	{
		int origX = action->getRelativeXMouse() / action->getXScale();
		int origY = action->getRelativeYMouse() / action->getYScale();
		// get offset (in cells) of the click relative to center of screen
		int xOff = (origX / CELL_WIDTH) - ((getWidth() / 2) / CELL_WIDTH);
		int yOff = (origY / CELL_HEIGHT) - ((getHeight() / 2) / CELL_HEIGHT);
		// center the camera on this new position
		int newX = _camera->getCenterPosition().x + xOff;
		int newY = _camera->getCenterPosition().y + yOff;
		_camera->centerOnPosition(Position(newX,newY,_camera->getViewLevel()));
		_redraw = true;
	}
}
예제 #2
0
파일: i_video.c 프로젝트: jezze/doom
static int getmouse(Uint8 buttonstate)
{

    return 0 | (buttonstate & SDL_BUTTON(1) ? 1 : 0) | (buttonstate & SDL_BUTTON(2) ? 2 : 0) | (buttonstate & SDL_BUTTON(3) ? 4 : 0);

}
예제 #3
0
int main(int argc, char* argv[]) {
    char* b3dFilePath;

    /* camera variables */
    float angleX = 0.f, angleY = 0.f;
    float positionX = 0.f, positionY = 0.f, positionZ = 0.f;

    /* camera movement variables */
    float forwardX = 0.f, forwardY = 0.f, forwardZ = 1.f;
    float rightX = 1.f, rightY = 0.f, rightZ = 0.f;

    /* memory to store only the rotation transform of the view matrix */
    float viewRotation[16];

    if (argc < 2) b3dFilePath = "test1/test1.b3d";
    else b3dFilePath = argv[1];

    b3dTest = loadB3DFile(b3dFilePath);
/*
    printf("textures:\n");
    printf("directory: %s\n", getDirectoryFromFile(b3dTest));
    printf("texture count: %d\n", getNumberOfTexturesFromBRUSChunk(getBRUSChunkFromBB3DChunk(getBB3DChunkFromFile(b3dTest))));
*/
    SDL_Init(SDL_INIT_VIDEO);

    glWindow = SDL_CreateWindow("B3D Lightmap Viewer", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
        SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL);

    glContext = SDL_GL_CreateContext(glWindow);

    glActiveTextureARB = SDL_GL_GetProcAddress("glActiveTextureARB");
    glClientActiveTextureARB = SDL_GL_GetProcAddress("glClientActiveTextureARB");

    keyPress = SDL_GetKeyboardState(NULL);

    /* multitexture setup */

    /* commentary: possible support for more than 2 texture layers? if necessary. */

    textures = loadTextures(b3dTest);

    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    glActiveTextureARB(GL_TEXTURE0_ARB);
    glEnable(GL_TEXTURE_2D);

    glActiveTextureARB(GL_TEXTURE1_ARB);
    glEnable(GL_TEXTURE_2D);

    /* OpenGL initial setup */

    glClearColor(0.f, 0.f, 0.5f, 1.f);

    glEnable(GL_DEPTH_TEST);

    glMatrixMode(GL_PROJECTION);
    gluPerspective(70.0, 1.333, 10, 10000);

    glMatrixMode(GL_MODELVIEW);

    /* main loop */

    while (!quit) {
        int differentialX = 0, differentialY = 0;
        int mouseStates = 0;

        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT) quit = 1;
        }

        if (keyPress[SDL_SCANCODE_ESCAPE]) quit = 1;

        mouseStates = SDL_GetRelativeMouseState(&differentialX, &differentialY);

        /* change camera orientation when mouse dragged */
        if (mouseStates & SDL_BUTTON(SDL_BUTTON_LEFT)) {
            angleX -= MOUSE_VERTICAL_SENSITIVITY * differentialY;
            angleY -= MOUSE_HORIZONTAL_SENSITIVITY * differentialX;
        }

        /* use existing base vectors in view rotation matrix for movement */
        forwardX = viewRotation[2];
        forwardY = viewRotation[6];
        forwardZ = viewRotation[10];

        rightX = viewRotation[0];
        rightY = viewRotation[4];
        rightZ = viewRotation[8];

        /* move camera forward when W pressed */
        if (keyPress[SDL_SCANCODE_W]) {
            positionX -= CAMERA_SPEED * forwardX;
            positionY -= CAMERA_SPEED * forwardY;
            positionZ -= CAMERA_SPEED * forwardZ;
        }

        /* move camera left when A pressed */
        if (keyPress[SDL_SCANCODE_A]) {
            positionX -= CAMERA_SPEED * rightX;
            positionY -= CAMERA_SPEED * rightY;
            positionZ -= CAMERA_SPEED * rightZ;
        }

        /* move camera backward when S pressed */
        if (keyPress[SDL_SCANCODE_S]) {
            positionX += CAMERA_SPEED * forwardX;
            positionY += CAMERA_SPEED * forwardY;
            positionZ += CAMERA_SPEED * forwardZ;
        }

        /* move camera right when D pressed */
        if (keyPress[SDL_SCANCODE_D]) {
            positionX += CAMERA_SPEED * rightX;
            positionY += CAMERA_SPEED * rightY;
            positionZ += CAMERA_SPEED * rightZ;
        }

        /* reset camera position and orientation when R pressed */
        if (keyPress[SDL_SCANCODE_R]) {
            positionX = 0.f;
            positionY = 0.f;
            positionZ = 0.f;
            angleX = 0.f;
            angleY = 0.f;
        }

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        /* construct the view matrix */
        glLoadIdentity();
        glRotatef(-angleX, 1.f, 0.f, 0.f);
        glRotatef(-angleY, 0.f, 1.f, 0.f);
        glGetFloatv(GL_MODELVIEW_MATRIX, viewRotation);
        glTranslatef(-positionX, -positionY, -positionZ);
        glScalef(1.f, 1.f, -1.f);

        drawB3D(b3dTest);

        SDL_GL_SwapWindow(glWindow);
        SDL_Delay(16);
    }

    /* commentary: still need to clear the loaded data from memory */

    SDL_DestroyWindow(glWindow);
    SDL_Quit();

    return 0;
}
예제 #4
0
static int
SDL_PrivateSendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
{
    SDL_Mouse *mouse = SDL_GetMouse();
    int posted;
    Uint32 type;
    Uint32 buttonstate = mouse->buttonstate;

    /* SDL_HINT_MOUSE_TOUCH_EVENTS: controlling whether mouse events should generate synthetic touch events */
    if (mouse->mouse_touch_events) {
        if (mouseID != SDL_TOUCH_MOUSEID && button == SDL_BUTTON_LEFT) {
            if (state == SDL_PRESSED) {
                track_mouse_down = SDL_TRUE;
            } else {
                track_mouse_down = SDL_FALSE;
            }
            if (window) {
                float fx = (float)mouse->x / (float)window->w;
                float fy = (float)mouse->y / (float)window->h;
                SDL_SendTouch(SDL_MOUSE_TOUCHID, 0, track_mouse_down, fx, fy, 1.0f);
            }
        }
    }

    /* Figure out which event to perform */
    switch (state) {
    case SDL_PRESSED:
        type = SDL_MOUSEBUTTONDOWN;
        buttonstate |= SDL_BUTTON(button);
        break;
    case SDL_RELEASED:
        type = SDL_MOUSEBUTTONUP;
        buttonstate &= ~SDL_BUTTON(button);
        break;
    default:
        /* Invalid state -- bail */
        return 0;
    }

    /* We do this after calculating buttonstate so button presses gain focus */
    if (window && state == SDL_PRESSED) {
        SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
    }

    if (buttonstate == mouse->buttonstate) {
        /* Ignore this event, no state change */
        return 0;
    }
    mouse->buttonstate = buttonstate;

    if (clicks < 0) {
        SDL_MouseClickState *clickstate = GetMouseClickState(mouse, button);
        if (clickstate) {
            if (state == SDL_PRESSED) {
                Uint32 now = SDL_GetTicks();

                if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + mouse->double_click_time) ||
                    SDL_abs(mouse->x - clickstate->last_x) > mouse->double_click_radius ||
                    SDL_abs(mouse->y - clickstate->last_y) > mouse->double_click_radius) {
                    clickstate->click_count = 0;
                }
                clickstate->last_timestamp = now;
                clickstate->last_x = mouse->x;
                clickstate->last_y = mouse->y;
                if (clickstate->click_count < 255) {
                    ++clickstate->click_count;
                }
            }
            clicks = clickstate->click_count;
        } else {
            clicks = 1;
        }
    }

    /* Post the event, if desired */
    posted = 0;
    if (SDL_GetEventState(type) == SDL_ENABLE) {
        SDL_Event event;
        event.type = type;
        event.button.windowID = mouse->focus ? mouse->focus->id : 0;
        event.button.which = mouseID;
        event.button.state = state;
        event.button.button = button;
        event.button.clicks = (Uint8) SDL_min(clicks, 255);
        event.button.x = mouse->x;
        event.button.y = mouse->y;
        posted = (SDL_PushEvent(&event) > 0);
    }

    /* We do this after dispatching event so button releases can lose focus */
    if (window && state == SDL_RELEASED) {
        SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
    }

    return posted;
}
예제 #5
0
파일: main.cpp 프로젝트: akrutsinger/Cards
void HandleMouseMoveEvent(SDL_Event &event)
{
	if(event.motion.state == SDL_BUTTON(1) && startdrag){
		Scorpion.DoDrag(event.motion.x, event.motion.y);
	}
}
예제 #6
0
int GP2X_Events::thread() {
    static int l_x = 0;
    static int l_y = 0;
    static int l_button = 0;

    while(m_running) {

	    m_dx = 0;
	    m_dy = 0;
	    m_button = 0;

	    // UP	    
	    if(SDL_JoystickGetButton(m_joy, 0)) {
		    m_dy = -1;
	    }
	    
	    // DOWN
	    if(SDL_JoystickGetButton(m_joy, 4)) {
		    m_dy = 1;
	    }

	    // LEFT
	    if(SDL_JoystickGetButton(m_joy, 2)) {
		    m_dx = -1;
	    }

	    // RIGHT
	    if(SDL_JoystickGetButton(m_joy, 6)) {
		    m_dx = 1;
	    }

	    // UP - LEFT
	    if(SDL_JoystickGetButton(m_joy, 1)) {
		    m_dy = -1;
		    m_dx = -1;
	    }

	    // UP - RIGHT
	    if(SDL_JoystickGetButton(m_joy, 7)) {
		    m_dy = -1;
		    m_dx = 1;
	    }

	    // DOWN - LEFT
	    if(SDL_JoystickGetButton(m_joy, 3)) {
		    m_dy = 1;
		    m_dx = -1;
	    }

	    // DOWN - RIGHT
	    if(SDL_JoystickGetButton(m_joy, 5)) {
		    m_dy = 1;
		    m_dx = 1;
	    }

	    // CLICK
	    if(SDL_JoystickGetButton(m_joy, 18)) {
		    m_button |= SDL_BUTTON(1);
	    }

	    // A
	    if(SDL_JoystickGetButton(m_joy, 12)) {
		    m_button |= SDL_BUTTON(2);
	    }

	    // B
	    if(SDL_JoystickGetButton(m_joy, 13)) {
		    m_button |= SDL_BUTTON(3);
	    }

	    // X
	    if(SDL_JoystickGetButton(m_joy, 14)) {
		    m_button |= SDL_BUTTON(1);
	    }

	    m_x += m_dx * 2;
	    m_y += m_dy * 2;

	    if(l_x != m_x || l_y != m_y) {
		    SDL_WarpMouse(m_x, m_y);
		    SDL_Event event;
		    
		    event.type = SDL_MOUSEMOTION;
		    event.motion.type = SDL_MOUSEMOTION;
		    event.motion.state = (m_button & SDL_BUTTON(1)) ? SDL_PRESSED : SDL_RELEASED;
		    event.motion.x = m_x;
		    event.motion.y = m_y;
		    event.motion.xrel = 0;
		    event.motion.yrel = 0;
		    
		    SDL_PushEvent(&event);
	    }
	    
	    if(l_button != m_button) {
		bool l_1 = (l_button & SDL_BUTTON(1)) == SDL_BUTTON(1);
		bool m_1 = (m_button & SDL_BUTTON(1)) == SDL_BUTTON(1);
		bool l_2 = (l_button & SDL_BUTTON(2)) == SDL_BUTTON(2);
		bool m_2 = (m_button & SDL_BUTTON(2)) == SDL_BUTTON(2);
		bool l_3 = (l_button & SDL_BUTTON(3)) == SDL_BUTTON(3);
		bool m_3 = (m_button & SDL_BUTTON(3)) == SDL_BUTTON(3);
		
		SDL_Event event;
		if(l_1 != m_1) {
			event.type = m_1 ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP;
			event.button.type = event.type;
			event.button.button = SDL_BUTTON_LEFT;
			event.button.state = m_1 ? SDL_PRESSED : SDL_RELEASED;
			event.button.x = m_x;
			event.button.y = m_y;

			SDL_PushEvent(&event);
		}

		if(l_2 != m_2) {
			event.type = m_2 ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP;
			event.button.type = event.type;
			event.button.button = SDL_BUTTON_MIDDLE;
			event.button.state = m_2 ? SDL_PRESSED : SDL_RELEASED;
			event.button.x = m_x;
			event.button.y = m_y;

			SDL_PushEvent(&event);
		}

		if(l_3 != m_3) {
			event.type = m_3 ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP;
			event.button.type = event.type;
			event.button.button = SDL_BUTTON_RIGHT;
			event.button.state = m_3 ? SDL_PRESSED : SDL_RELEASED;
			event.button.x = m_x;
			event.button.y = m_y;

			SDL_PushEvent(&event);
		}

	    }

	    l_x = m_x;
	    l_y = m_y;
	    l_button = m_button;

	    SDL_Delay(10);
    }

    return 0;
}
예제 #7
0
파일: sdl.cpp 프로젝트: Timo6/vdrift-art
void sdl_mouseUpdate()
{
    displayAspectRatio = (float)displayWidth / (float)displayHeight;


    int mouse_x, mouse_y;
    unsigned int mouseButtonState;



    mouseButtonState = SDL_GetMouseState(&mouse_x, &mouse_y);

    //printf("%u,%u -> ", mouse_x, mouse_y);

    // uint to float position;
    mousePos.a[0] = (float)mouse_x / (float)displayWidth;
    mousePos.a[1] = (float)mouse_y / (float)displayHeight;

    // correct to center of screen
    mousePos.a[0] -= 0.5;
    mousePos.a[1] -= 0.5;

    // mutliply by 2
    mousePos.a[0] *= 2.0;
    mousePos.a[1] *= 2.0;

    // correct aspect ratio
    mousePos.a[0] *= displayAspectRatio;

    // mouse y is inverted
    mousePos.a[1] *= -1;



	if (mouseButtonState&SDL_BUTTON(1))			// normally the left button
	{
		if (mouseButtons[1].pressed)
			mouseButtons[1].pressedLf = true;
		else
			mouseButtons[1].pressed = true;

	}
	else
	{
		mouseButtons[1].pressed = false;
		mouseButtons[1].pressedLf = false;
	}


	if (mouseButtonState&SDL_BUTTON(3))
	{
		if (mouseButtons[3].pressed)
			mouseButtons[3].pressedLf = true;
		else
			mouseButtons[3].pressed = true;
	}
	else
	{
		mouseButtons[3].pressed = false;
		mouseButtons[3].pressedLf = false;
	}



}
예제 #8
0
파일: vgs2l.c 프로젝트: suzukiplan/vgs2
int main(int argc,char* argv[])
{
	SDL_Surface* surface;
	SDL_Event event;
	FILE* fp;
	int i,j;
	unsigned char s[4];
	char path[16];
	int cn,pn,bn;
	unsigned short* ptr;
	int vx,vy,vp,pp;
	unsigned int n;
	unsigned int ticks;
	int mx;
	int my;
	pthread_t tid;

	puts("Start VGS mk-II SR for Linux.");

	/* Load ROMDATA.BIN */
	fp=fopen("ROMDATA.BIN","rb");
	if(NULL==fp) {
		fprintf(stderr,"ROMDATA.BIN was not found.\n");
		return 1;
	}

	/* allocate table */
	BN=0;
	BR=NULL;
	fread(&BN,sizeof(BN),1,fp);
	if(BN<1) {
		fprintf(stderr,"Inalid ROMDATA.BIN: record number\n");
		fclose(fp);
		return 1;
	}
	if(NULL==(BR=(struct _BINREC*)malloc(BN * sizeof(struct _BINREC)))) {
		fprintf(stderr,"No memory.\n");
		fclose(fp);
		return 1;
	}
	memset(BR,0,BN * sizeof(struct _BINREC));

	/* read filename */
	for(i=0;i<BN;i++) {
		memset(BR[i].name,0,16);
		fread(&BR[i].name,16,1,fp);
		for(j=0;'\0'!=BR[i].name[j];j++) {
			if(15==j) {
				fprintf(stderr,"ROM data is broken.\n");
				fclose(fp);
				return 1;
			}
			BR[i].name[j]^=0xAA;
		}
	}

	/* read data */
	for(i=0;i<BN;i++) {
		fread(s,4,1,fp);
		BR[i].size=s[0];
		BR[i].size<<=8;
		BR[i].size|=s[1];
		BR[i].size<<=8;
		BR[i].size|=s[2];
		BR[i].size<<=8;
		BR[i].size|=s[3];
		if(NULL==(BR[i].data=(char*)malloc(BR[i].size))) {
			fprintf(stderr,"Could not allocate ROM data area: errno=%d (size=%d)\n",errno,BR[i].size);
			fclose(fp);
			return 1;
		}
		fread(BR[i].data,BR[i].size,1,fp);
	}

	fclose(fp);

	/* Extract data */
	cn=0;
	pn=0;
	bn=0;
	for(i=0;i<256;i++) {
		sprintf(path,"GSLOT%03d.CHR",i);
		if(0==gload(i,path)) cn++;
		sprintf(path,"ESLOT%03d.PCM",i);
		if(0==eload(i,path)) pn++;
		sprintf(path,"BSLOT%03d.BGM",i);
		if(0==bload(i,path)) bn++;
	}

	printf("Extracted ROM data: CHR=%d PCM=%d BGM=%d\n",cn,pn,bn);

	/* Initialize SDL */
	if(SDL_Init(SDL_INIT_VIDEO)) {
		fprintf(stderr,"Failed: SDL_Init(SDL_INIT_VIDEO)\n");
		return 1;
	}
	SDL_WM_SetCaption("VGS mk-II SR for Linux",NULL);

	/* Initialize Surface */
	surface=SDL_SetVideoMode(XSIZE*2,YSIZE*2,16,SDL_SWSURFACE);
	if(NULL==surface) {
		fprintf(stderr,"Could not create the surface.\n");
		return 1;
	}
	if(2!=surface->format->BytesPerPixel) {
		fprintf(stderr,"This display does not support 16bit color.\n");
		return 1;
	}
	printf("Created surface: %dx%d\n",surface->w,surface->h);

	/* Initialize sound system */
	if(init_sound()) {
		fprintf(stderr,"Could not create the sound thread.\n");
		return 1;
	}

	/* Initialize user program */
	if(vgs2_init()) {
		fprintf(stderr,"Initialization of the app has failed.\n");
		return 2;
	}
	make_pallet();

	n=0;
	while(1) {
		ticks=SDL_GetTicks();
		SDL_PollEvent(&event);
		if(event.type==SDL_QUIT) break;
		if(SDL_GetMouseState(&mx,&my)&SDL_BUTTON(1)) {
			mx/=2;
			my/=2;
			if(!_touch.s) {
				_touch.dx=0;
				_touch.dy=0;
				_touch.px=mx;
				_touch.py=my;
				_touch.cx=mx;
				_touch.cy=my;
			} else {
				_touch.dx=mx-_touch.px;
				_touch.dy=my-_touch.py;
				_touch.px=_touch.cx;
				_touch.py=_touch.cy;
				_touch.cx=mx;
				_touch.cy=my;
			}
			_touch.s=1;
			_touch.t++;
		} else {
			_touch.s=0;
			_touch.t=0;
		}
		if(_pause) {
			if(vgs2_pause()) break;
		} else {
			if(vgs2_loop()) break;
		}
		if(SDL_MUSTLOCK(surface) && SDL_LockSurface(surface)<0) {
			fprintf(stderr,"Skip frame: could not locked surface.\n");
			usleep(100000);
			continue;
		}
		ptr=(unsigned short*)surface->pixels;
		vp=0;
		pp=0;
		if(_interlace) {
			for(vy=0;vy<YSIZE;vy++) {
				for(vx=0;vx<XSIZE;vx++) {
					if(_vram.sp[vp]) {
						ptr[pp]=ADPAL[_vram.sp[vp]];
						ptr[pp+1]=ADPAL[_vram.sp[vp]];
						ptr[pp+320]=0;
						ptr[pp+321]=0;
						_vram.sp[vp]=0;
					} else {
						ptr[pp]=ADPAL[_vram.bg[vp]];
						ptr[pp+1]=ADPAL[_vram.bg[vp]];
						ptr[pp+320]=0;
						ptr[pp+321]=0;
					}
					vp++;
					pp+=2;
				}
				pp+=320;
			}
		} else {
			for(vy=0;vy<YSIZE;vy++) {
				for(vx=0;vx<XSIZE;vx++) {
					if(_vram.sp[vp]) {
						ptr[pp]=ADPAL[_vram.sp[vp]];
						ptr[pp+1]=ADPAL[_vram.sp[vp]];
						ptr[pp+320]=ADPAL[_vram.sp[vp]];
						ptr[pp+321]=ADPAL[_vram.sp[vp]];
						_vram.sp[vp]=0;
					} else {
						ptr[pp]=ADPAL[_vram.bg[vp]];
						ptr[pp+1]=ADPAL[_vram.bg[vp]];
						ptr[pp+320]=ADPAL[_vram.bg[vp]];
						ptr[pp+321]=ADPAL[_vram.bg[vp]];
					}
					vp++;
					pp+=2;
				}
				pp+=320;
			}
		}
		if(SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface);
		SDL_UpdateRect(surface,0,0,320,400);
		n++;
		ticks=SDL_GetTicks()-ticks;
		switch(n%3) {
			case 0:
			case 1:
				if(ticks<17) {
					msleep(17-ticks);
				}
				break;
			case 2:
				if(ticks<16) {
					msleep(16-ticks);
				}
				break;
		}
	}
	vgs2_term();
	SDL_Quit();
	term_sound();
	puts("End.");
	return 0;
}
예제 #9
0
bool gui_message_loop(void)
{
    SDL_Event event;
    static int x,y,xybutton = 0;

    while (SDL_WaitEvent(&event))
    {
        sim_enter_irq_handler();
        switch(event.type)
        {
            case SDL_KEYDOWN:
            case SDL_KEYUP:
                button_event(event.key.keysym.sym, event.type == SDL_KEYDOWN);
                break;
#ifdef HAVE_TOUCHSCREEN
            case SDL_MOUSEMOTION:
                if (event.motion.state & SDL_BUTTON(1))
                    touchscreen_event(event.motion.x, event.motion.y);
                break;
#endif
            case SDL_MOUSEBUTTONDOWN:
                switch ( event.button.button ) {
#ifdef HAVE_SCROLLWHEEL
                    case SDL_BUTTON_WHEELUP:
                        button_event( SDLK_UP, true );
                        break;
                    case SDL_BUTTON_WHEELDOWN:
                        button_event( SDLK_DOWN, true );
                        break;
#endif
                    case SDL_BUTTON_LEFT:
                    case SDL_BUTTON_MIDDLE:
                        if ( mapping && background ) {
                            x = event.button.x;
                            y = event.button.y;
                        }
                        if ( background ) {
                            xybutton = xy2button( event.button.x, event.button.y );
                            if( xybutton ) {
                                button_event( xybutton, true );
                                break;
                            }
                        }
#ifdef HAVE_TOUCHSCREEN
                        touchscreen_event(event.button.x, event.button.y);
#endif
                        break;

                    default:
                        break;
                }

                if (debug_wps && event.button.button == 1)
                {
                    if ( background ) 
#ifdef HAVE_REMOTE
                        if ( event.button.y < UI_REMOTE_POSY ) /* Main Screen */
                            printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 );
                        else 
                            printf("Mouse at: (%d, %d)\n", event.button.x - UI_REMOTE_POSX -1 , event.button.y - UI_REMOTE_POSY - 1 );
#else
                        printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 );
#endif
                    else 
                        if ( event.button.y/display_zoom < LCD_HEIGHT ) /* Main Screen */
                            printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom );
#ifdef HAVE_REMOTE
                        else
                            printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom - LCD_HEIGHT );
#endif
                }
                break;
            case SDL_MOUSEBUTTONUP:
                switch ( event.button.button ) {
                    /* The scrollwheel button up events are ignored as they are queued immediately */
                    case SDL_BUTTON_LEFT:
                    case SDL_BUTTON_MIDDLE:
                        if ( mapping && background ) {
                            printf("    { SDLK_,     %d, %d, %d, \"\" },\n", x,
#define SQUARE(x) ((x)*(x))
                            y, (int)sqrt( SQUARE(x-(int)event.button.x)
                                    + SQUARE(y-(int)event.button.y))  );
                        }
                        if ( background && xybutton ) {
                                button_event( xybutton, false );
                                xybutton = 0;
                            }
#ifdef HAVE_TOUCHSCREEN
                            else
                                button_event(BUTTON_TOUCHSCREEN, false);
#endif
                        break;
                    default:
                        break;
                }
                break;
                

            case SDL_QUIT:
            {
                sim_exit_irq_handler();
                return false;
            }
            default:
                /*printf("Unhandled event\n"); */
                break;
        }
        sim_exit_irq_handler();
    }
예제 #10
0
파일: sdl.c 프로젝트: andrewbird/dosemu2
static void SDL_handle_events(void)
{
  SDL_Event event;

  assert(pthread_equal(pthread_self(), dosemu_pthread_self));
  if (render_is_updating())
    return;
  while (SDL_PollEvent(&event)) {
    switch (event.type) {

    case SDL_WINDOWEVENT:
      switch (event.window.event) {
      case SDL_WINDOWEVENT_FOCUS_GAINED:
	v_printf("SDL: focus in\n");
	render_gain_focus();
	if (config.X_background_pause && !dosemu_user_froze)
	  unfreeze_dosemu();
	break;
      case SDL_WINDOWEVENT_FOCUS_LOST:
	v_printf("SDL: focus out\n");
	render_lose_focus();
	if (config.X_background_pause && !dosemu_user_froze)
	  freeze_dosemu();
	break;
      case SDL_WINDOWEVENT_RESIZED:
	/* very strange things happen: if renderer size was explicitly
	 * set, SDL reports mouse coords relative to that. Otherwise
	 * it reports mouse coords relative to the window. */
	SDL_RenderGetLogicalSize(renderer, &m_x_res, &m_y_res);
	if (!m_x_res || !m_y_res) {
	  m_x_res = event.window.data1;
	  m_y_res = event.window.data2;
	}
	update_mouse_coords();
	SDL_redraw();
	break;
      case SDL_WINDOWEVENT_EXPOSED:
	SDL_redraw();
	break;
      case SDL_WINDOWEVENT_ENTER:
        /* ignore fake enter events */
        if (config.X_fullscreen)
          break;
        mouse_drag_to_corner(m_x_res, m_y_res);
        break;
      }
      break;

    case SDL_KEYDOWN:
      {
	if (wait_kup)
	  break;
	SDL_Keysym keysym = event.key.keysym;
	if ((keysym.mod & KMOD_CTRL) && (keysym.mod & KMOD_ALT)) {
	  if (keysym.sym == SDLK_HOME || keysym.sym == SDLK_k) {
	    force_grab = 0;
	    toggle_grab(keysym.sym == SDLK_k);
	    break;
	  } else if (keysym.sym == SDLK_f) {
	    toggle_fullscreen_mode();
	    /* some versions of SDL re-send the keydown events after the
	     * full-screen switch. We need to filter them out to prevent
	     * the infinite switching loop. */
	    wait_kup = 1;
	    break;
	  }
	}
	if (vga.mode_class == TEXT &&
	    (keysym.sym == SDLK_LSHIFT || keysym.sym == SDLK_RSHIFT)) {
	  copypaste = 1;
	  /* enable cursor for copy/paste */
	  if (!m_cursor_visible)
	    SDL_ShowCursor(SDL_ENABLE);
	}
      }
#if CONFIG_SDL_SELECTION
      clear_if_in_selection();
#endif
#ifdef X_SUPPORT
#if HAVE_XKB
      if (x11_display && config.X_keycode)
	SDL_process_key_xkb(x11_display, event.key);
      else
#endif
#endif
	SDL_process_key(event.key);
      break;
    case SDL_KEYUP: {
      SDL_Keysym keysym = event.key.keysym;
      wait_kup = 0;
      if (copypaste && (keysym.sym == SDLK_LSHIFT ||
              keysym.sym == SDLK_RSHIFT)) {
        copypaste = 0;
        if (!m_cursor_visible)
	    SDL_ShowCursor(SDL_DISABLE);
      }
#ifdef X_SUPPORT
#if HAVE_XKB
      if (x11_display && config.X_keycode)
	SDL_process_key_xkb(x11_display, event.key);
      else
#endif
#endif
	SDL_process_key(event.key);
      break;
    }

    case SDL_MOUSEBUTTONDOWN:
      {
	int buttons = SDL_GetMouseState(NULL, NULL);
#if CONFIG_SDL_SELECTION
	if (window_has_focus() && !shift_pressed()) {
	  clear_selection_data();
	} else if (vga.mode_class == TEXT && !grab_active) {
	  if (event.button.button == SDL_BUTTON_LEFT)
	    start_selection(x_to_col(event.button.x, m_x_res),
			    y_to_row(event.button.y, m_y_res));
	  else if (event.button.button == SDL_BUTTON_RIGHT)
	    start_extend_selection(x_to_col(event.button.x, m_x_res),
				   y_to_row(event.button.y, m_y_res));
	  else if (event.button.button == SDL_BUTTON_MIDDLE) {
	    char *paste = SDL_GetClipboardText();
	    if (paste)
	      paste_text(paste, strlen(paste), "utf8");
	  }
	  break;
	}
#endif				/* CONFIG_SDL_SELECTION */
	mouse_move_buttons(buttons & SDL_BUTTON(1),
			   buttons & SDL_BUTTON(2),
			   buttons & SDL_BUTTON(3));
	break;
      }
    case SDL_MOUSEBUTTONUP:
      {
	int buttons = SDL_GetMouseState(NULL, NULL);
#if CONFIG_SDL_SELECTION
	if (vga.mode_class == TEXT && !grab_active) {
	    t_unicode *sel = end_selection();
	    if (sel) {
		char *send_text = get_selection_string(sel, "utf8");
		SDL_SetClipboardText(send_text);
		free(send_text);
	    }
	}
#endif				/* CONFIG_SDL_SELECTION */
	mouse_move_buttons(buttons & SDL_BUTTON(1),
			   buttons & SDL_BUTTON(2),
			   buttons & SDL_BUTTON(3));
	break;
      }

    case SDL_MOUSEMOTION:
#if CONFIG_SDL_SELECTION
      extend_selection(x_to_col(event.motion.x, m_x_res),
			 y_to_row(event.motion.y, m_y_res));
#endif				/* CONFIG_SDL_SELECTION */
      if (grab_active)
	mouse_move_relative(event.motion.xrel, event.motion.yrel,
			    m_x_res, m_y_res);
      else
	mouse_move_absolute(event.motion.x, event.motion.y, m_x_res,
			    m_y_res);
      break;
    case SDL_MOUSEWHEEL:
      mouse_move_wheel(-event.wheel.y);
      break;
    case SDL_QUIT:
      leavedos(0);
      break;
    default:
      v_printf("PAS ENCORE TRAITE %x\n", event.type);
      /* TODO */
      break;
    }
  }

#ifdef X_SUPPORT
  if (x11_display && !use_bitmap_font && vga.mode_class == TEXT &&
      X_handle_text_expose()) {
    /* need to check separately because SDL_VIDEOEXPOSE is eaten by SDL */
    redraw_text_screen();
  }
#endif
}
예제 #11
0
void GameWorldPanel::handleMouse(double dt)
{
	static_cast<void>(dt);

	const auto &renderer = this->getGameState()->getRenderer();

	const uint32_t mouse = SDL_GetRelativeMouseState(nullptr, nullptr);
	const bool leftClick = (mouse & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0;

	if (leftClick)
	{
		// Horizontal camera movement rough draft. The original camera controls for 
		// Arena are bad, but I am simulating them before thinking of adding modern 
		// 3D camera support (like Daggerfall) as an option.
		const Int2 screenDimensions = renderer.getWindowDimensions();
		const Int2 mousePosition = this->getMousePosition();

		// Strength of turning is determined by proximity of the mouse cursor to
		// the left or right screen edge.
		const double dx = [this, &mousePosition, &screenDimensions]()
		{
			const int mouseX = mousePosition.getX();

			// Native cursor regions (scaled to the current window).
			const Rect &middleLeft = *this->nativeCursorRegions.at(3).get();
			const Rect &middleRight = *this->nativeCursorRegions.at(5).get();

			// Measure the magnitude of rotation. -1.0 is left, 1.0 is right.
			double percent = 0.0;
			if (middleLeft.contains(mousePosition))
			{
				percent = -1.0 + (static_cast<double>(mouseX) / middleLeft.getWidth());
			}
			else if (middleRight.contains(mousePosition))
			{
				percent = static_cast<double>(mouseX - middleRight.getLeft()) /
					middleRight.getWidth();
			}

			// Reduce the magnitude by a lot as a baseline. Sensitivity can be 
			// tweaked in the options.
			percent *= 0.010;

			// No NaNs or infinities allowed.
			return std::isfinite(percent) ? percent : 0.0;
		}();

		auto &player = this->getGameState()->getGameData()->getPlayer();
		const auto &options = this->getGameState()->getOptions();

		// Yaw the camera left or right. No vertical movement in classic camera mode.
		player.rotate(dx, 0.0, options.getHorizontalSensitivity(),
			options.getVerticalSensitivity(), options.getVerticalFOV());
	}

	// Later in development, a 3D camera would be fun (more like Daggerfall), but 
	// for now the objective is to more closely resemble the original game, so the
	// rough draft 3D camera code below is commented out as a result.

	// Make the camera look around.
	/*int dx, dy;
	const auto mouse = SDL_GetRelativeMouseState(&dx, &dy);

	bool leftClick = (mouse & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0;
	bool rightClick = (mouse & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
	bool turning = ((dx != 0) || (dy != 0)) && leftClick;

	if (turning)
	{
		auto dimensions = this->getGameState()->getRenderer().getWindowDimensions();
		double dxx = static_cast<double>(dx) / static_cast<double>(dimensions.getX());
		double dyy = static_cast<double>(dy) / static_cast<double>(dimensions.getY());

		// Pitch and/or yaw the camera.
		const auto &options = this->getGameState()->getOptions();
		this->getGameState()->getGameData()->getPlayer().rotate(dxx, -dyy,
			options.getHorizontalSensitivity(), options.getVerticalSensitivity(),
			options.getVerticalFOV());
	}*/
}
예제 #12
0
///sprawdza sygnały z myszy i klawiatury i wykonuje odpowiednie rzeczy
bool checkInputs()
{
	bool quit = false;
	
	auto effectInstanceList=getEffectInstanceList();
	
	auto controllerInstanceList=getControllerInstanceList();

	while (SDL_PollEvent(&event))
	{
		const Uint8 *state = SDL_GetKeyboardState(NULL);
		switch(event.type)
		{
			case SDL_QUIT:
				quit = true;
			break;
			case SDL_MOUSEBUTTONDOWN:
				{
					int x=event.button.x;
					int y=event.button.y;
					if(event.button.button==SDL_BUTTON_LEFT && !(state[SDL_SCANCODE_LALT] || state[SDL_SCANCODE_RALT]) && !(state[SDL_SCANCODE_LCTRL] || state[SDL_SCANCODE_RCTRL]))
					{
						for(auto it=effectInstanceList->rbegin();it!=effectInstanceList->rend();++it)
						{
							if(it->second->receiveClick(x, y, ME_PRESS))break;
						}
						
						for(auto it=controllerInstanceList->rbegin();it!=controllerInstanceList->rend();++it)
						{
							if(it->second->receiveClick(x, y, ME_PRESS))break;
						}
					}
					else
					if(event.button.button==SDL_BUTTON_RIGHT || (event.button.button==SDL_BUTTON_LEFT && (state[SDL_SCANCODE_LALT] || state[SDL_SCANCODE_RALT])))
					{
						for(auto it=effectInstanceList->rbegin();it!=effectInstanceList->rend();++it)
						{
							if(it->second->receiveSecondClick(x, y, ME_PRESS))break;
						}
						
						for(auto it=controllerInstanceList->rbegin();it!=controllerInstanceList->rend();++it)
						{
							if(it->second->receiveSecondClick(x, y, ME_PRESS))break;
						}
					}
					else
					if(event.button.button==SDL_BUTTON_MIDDLE || (event.button.button==SDL_BUTTON_LEFT && (state[SDL_SCANCODE_LCTRL] || state[SDL_SCANCODE_RCTRL])))
					{
						for(auto it=effectInstanceList->rbegin();it!=effectInstanceList->rend();)
						{
							auto it2=it;
							++it;
							if(it2->second->receiveThridClick(x, y, ME_PRESS))break;
						}
						
						for(auto it=controllerInstanceList->rbegin();it!=controllerInstanceList->rend();++it)
						{
							auto it2=it;
							++it;
							if(it2->second->receiveThridClick(x, y, ME_PRESS))break;
						}
					}
				}
			break;
			case SDL_MOUSEBUTTONUP:
				{
					int x=event.button.x;
					int y=event.button.y;
					if(event.button.button==SDL_BUTTON_LEFT && !(state[SDL_SCANCODE_LALT] || state[SDL_SCANCODE_RALT]) && !(state[SDL_SCANCODE_LCTRL] || state[SDL_SCANCODE_RCTRL]))
					{
						for(auto it=effectInstanceList->rbegin();it!=effectInstanceList->rend();++it)
						{
							it->second->receiveClick(x, y, ME_RELEASE);
						}
						for(auto it=controllerInstanceList->rbegin();it!=controllerInstanceList->rend();++it)
						{
							it->second->receiveClick(x, y, ME_RELEASE);
						}
					}
					else
					if(event.button.button==SDL_BUTTON_RIGHT || (event.button.button==SDL_BUTTON_LEFT && (state[SDL_SCANCODE_LALT] || state[SDL_SCANCODE_RALT])))
					{
						for(auto it=effectInstanceList->rbegin();it!=effectInstanceList->rend();++it)
						{
							it->second->receiveSecondClick(x, y, ME_RELEASE);
						}
						for(auto it=controllerInstanceList->rbegin();it!=controllerInstanceList->rend();++it)
						{
							it->second->receiveSecondClick(x, y, ME_RELEASE);
						}
					}
					else
					if(event.button.button==SDL_BUTTON_MIDDLE || (event.button.button==SDL_BUTTON_LEFT && (state[SDL_SCANCODE_LCTRL] || state[SDL_SCANCODE_RCTRL])))
					{
						for(auto it=effectInstanceList->rbegin();it!=effectInstanceList->rend();)
						{
							auto it2=it;
							++it;
							it2->second->receiveThridClick(x, y, ME_RELEASE);
						}
						for(auto it=controllerInstanceList->rbegin();it!=controllerInstanceList->rend();++it)
						{
							auto it2=it;
							++it;
							it2->second->receiveThridClick(x, y, ME_RELEASE);
						}
					}
				}
			break;
			case SDL_MOUSEMOTION:
				{
					int x=event.button.x;
					int y=event.button.y;
					if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT) && !(state[SDL_SCANCODE_LALT] || state[SDL_SCANCODE_RALT]) && !(state[SDL_SCANCODE_LCTRL] || state[SDL_SCANCODE_RCTRL]))
					{
						for(auto it=effectInstanceList->rbegin();it!=effectInstanceList->rend();++it)
						{
							if(it->second->receiveClick(x, y, ME_REPEAT))break;
						}
						for(auto it=controllerInstanceList->rbegin();it!=controllerInstanceList->rend();++it)
						{
							if(it->second->receiveClick(x, y, ME_REPEAT))break;
						}
					}
					else
					if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT) || (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT) && (state[SDL_SCANCODE_LALT] || state[SDL_SCANCODE_RALT])))
					{
						for(auto it=effectInstanceList->rbegin();it!=effectInstanceList->rend();++it)
						{
							if(it->second->receiveSecondClick(x, y, ME_REPEAT))break;
						}
						for(auto it=controllerInstanceList->rbegin();it!=controllerInstanceList->rend();++it)
						{
							if(it->second->receiveSecondClick(x, y, ME_REPEAT))break;
						}
					}
					else
					if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_MIDDLE) || (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT) && (state[SDL_SCANCODE_LCTRL] || state[SDL_SCANCODE_RCTRL])))
					{
						for(auto it=effectInstanceList->rbegin();it!=effectInstanceList->rend();)
						{
							auto it2=it;
							++it;
							if(it2->second->receiveThridClick(x, y, ME_REPEAT))break;
						}
						for(auto it=controllerInstanceList->rbegin();it!=controllerInstanceList->rend();++it)
						{
							auto it2=it;
							++it;
							if(it2->second->receiveThridClick(x, y, ME_REPEAT))break;
						}
					}
				}
			break;
			case SDL_KEYDOWN:
				
				auto it=effectInstanceList->begin();
				for(;it!=effectInstanceList->end();++it)
				{
					if(it->second->receiveKeyboardEvent(event.key.keysym.scancode))break;
				}
				
				if(it==effectInstanceList->end())
				effectCreator.receiveKeyboardEvent(event.key.keysym.scancode);
			
				if((state[SDL_SCANCODE_LCTRL] || state[SDL_SCANCODE_RCTRL]) && state[SDL_SCANCODE_S])
				{
					getSaveFile(fileStr, MAX_PATH);
					Effect::saveToFile(fileStr);
				}
				else if((state[SDL_SCANCODE_LCTRL] || state[SDL_SCANCODE_RCTRL]) && state[SDL_SCANCODE_L])
				{
					Effect::saveToFile("session_before_load.cello");
					Effect::clearAll();
					getOpenFile(fileStr, MAX_PATH);
					Effect::loadFromFile(fileStr);
				}
				else if((state[SDL_SCANCODE_LCTRL] || state[SDL_SCANCODE_RCTRL]) && (state[SDL_SCANCODE_LALT] || state[SDL_SCANCODE_RALT]) && state[SDL_SCANCODE_E])
				{
					Effect::saveToFile("session_before_erase.cello");
					Effect::clearAll();
				}
				else if((state[SDL_SCANCODE_LALT] || state[SDL_SCANCODE_RALT]) && state[SDL_SCANCODE_R])
				{
					OSCConn::recordToFile();
				}
				else if(!(state[SDL_SCANCODE_LSHIFT] || state[SDL_SCANCODE_RSHIFT]) && (state[SDL_SCANCODE_LCTRL] || state[SDL_SCANCODE_RCTRL]) && state[SDL_SCANCODE_R])
				{
					OSCConn::startRecord();
				}
				else if((state[SDL_SCANCODE_LSHIFT] || state[SDL_SCANCODE_RSHIFT]) && state[SDL_SCANCODE_R])
				{
					OSCConn::stopRecord();
				}
				
			break;
		}
	}
	
	return quit;
}
예제 #13
0
/**
 * Handles moving over the minimap.
 * Will change the camera center when the mouse is moved in mouse-moving mode.
 * @param action Pointer to an action.
 * @param state State that the action handlers belong to.
 */
void MiniMapView::mouseOver(Action *action, State *state)
{
	InteractiveSurface::mouseOver(action, state);

	if (_isMouseScrolling && action->getDetails()->type == SDL_MOUSEMOTION)
	{
		// The following is the workaround for a rare problem where sometimes
		// the mouse-release event is missed for any reason.
		// However if the SDL is also missed the release event, then it is to no avail :(
		// (checking: is the dragScroll-mouse-button still pressed?)
		if (0==(SDL_GetMouseState(0,0)&SDL_BUTTON(Options::battleDragScrollButton))) { // so we missed again the mouse-release :(
			// Check if we have to revoke the scrolling, because it was too short in time, so it was a click
			if ((!_mouseMovedOverThreshold) && ((int)(SDL_GetTicks() - _mouseScrollingStartTime) <= (Options::dragScrollTimeTolerance)))
			{
					_camera->centerOnPosition(_posBeforeMouseScrolling);
					_redraw = true;
			}
			_isMouseScrolled = _isMouseScrolling = false;
			stopScrolling(action);
			return;
		}

		_isMouseScrolled = true;

		if (Options::touchEnabled == false)
		{
			// Set the mouse cursor back
			SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
			SDL_WarpMouse(_xBeforeMouseScrolling, _yBeforeMouseScrolling);
			SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
		}

		// Check the threshold
		_totalMouseMoveX += action->getDetails()->motion.xrel;
		_totalMouseMoveY += action->getDetails()->motion.yrel;
		if (!_mouseMovedOverThreshold)
			_mouseMovedOverThreshold = ((std::abs(_totalMouseMoveX) > Options::dragScrollPixelTolerance) || (std::abs(_totalMouseMoveY) > Options::dragScrollPixelTolerance));

		// Calculate the move
		int newX, newY;
		int scrollX, scrollY;

		if (Options::battleDragScrollInvert)
		{
			scrollX = action->getDetails()->motion.xrel;
			scrollY = action->getDetails()->motion.yrel;
		}
		else
		{
			scrollX = -action->getDetails()->motion.xrel;
			scrollY = -action->getDetails()->motion.yrel;
		}
		_mouseScrollX += scrollX;
		_mouseScrollY += scrollY;
		newX = _posBeforeMouseScrolling.x + _mouseScrollX / action->getXScale() / 4;
		newY = _posBeforeMouseScrolling.y + _mouseScrollY / action->getYScale() / 4;

		// Keep the limits...
		if (newX < -1 || _camera->getMapSizeX() < newX)
		{
			_mouseScrollX -= scrollX;
			newX = _posBeforeMouseScrolling.x + _mouseScrollX / 4;
		}
		if (newY < -1 || _camera->getMapSizeY() < newY)
		{
			_mouseScrollY -= scrollY;
			newY = _posBeforeMouseScrolling.y + _mouseScrollY / 4;
		}

		// Scrolling
		_camera->centerOnPosition(Position(newX,newY,_camera->getViewLevel()));
		_redraw = true;

		if (Options::touchEnabled == false)
		{
			// We don't want to see the mouse-cursor jumping :)
			if (Options::battleDragScrollInvert)
			{
				action->getDetails()->motion.x = _xBeforeMouseScrolling;
				action->getDetails()->motion.y = _yBeforeMouseScrolling;
			}
			else
			{
				Position delta(-scrollX, -scrollY, 0);
				int barWidth = _game->getScreen()->getCursorLeftBlackBand();
				int barHeight = _game->getScreen()->getCursorTopBlackBand();
				int cursorX = _cursorPosition.x + delta.x;
				int cursorY =_cursorPosition.y + delta.y;
				_cursorPosition.x = std::min((int)Round((getX() + getWidth()) * action->getXScale()) + barWidth, std::max((int)Round(getX() * action->getXScale()) + barWidth, cursorX));
				_cursorPosition.y = std::min((int)Round((getY() + getHeight()) * action->getYScale()) + barHeight, std::max((int)Round(getY() * action->getYScale()) + barHeight, cursorY));
				action->getDetails()->motion.x = _cursorPosition.x;
				action->getDetails()->motion.y = _cursorPosition.y;
			}
		}
		_game->getCursor()->handle(action);
	}
}
예제 #14
0
int Button(void)
{
	return (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(1));
}
예제 #15
0
void update_camera()
{
	const float c_delta = 0.1f;

	static int last_update = 0;
	int time_diff = cur_time - last_update;

	static float old_camera_x = 0;
	static float old_camera_y = 0;
	static float old_camera_z = 0;
	float adjust;
	actor *me = get_our_actor();

	old_rx=rx;
	old_rz=rz;
	new_zoom_level=old_zoom_level=zoom_level;
	
	//printf("kludge: %f, hold: %f, rx: %f, rz %f, zoom: %f\n",camera_kludge, hold_camera,rx,rz,zoom_level);
	
	if (fol_cam && !fol_cam_behind)
		rz = hold_camera;
	if (me)
		camera_kludge = -me->z_rot;

	/* This is a BIG hack to not polluate the code but if this feature
	 * is accepted and the flag is removed, all the code that
	 * follows will have to be changed in order to get rid of
	 * camera_rotation_duration and camera_tilt_duration. */
	camera_rotation_duration = camera_rotation_speed != 0.0 ? time_diff : 0.0;
	camera_tilt_duration = camera_tilt_speed != 0.0 ? time_diff : 0.0;

	if(camera_rotation_duration > 0){
		if (time_diff <= camera_rotation_duration)
			rz+=camera_rotation_speed*time_diff;
		else
			rz+=camera_rotation_speed*camera_rotation_duration;
		camera_rotation_duration-=time_diff;
		adjust_view++;
	}
	if(camera_x_duration > 0){
		if(camera_x_speed>1E-4 || camera_x_speed<-1E-4){
			if (time_diff <= camera_x_duration)
				camera_x-=camera_x_speed*time_diff;
			else
				camera_x-=camera_x_speed*camera_x_duration;
			if(fabs(camera_x-old_camera_x) >= c_delta){
				adjust_view++;
			}
		}
		camera_x_duration-=time_diff;
	}
	if(camera_y_duration > 0){
		if(camera_y_speed>1E-4 || camera_y_speed<-1E-4){
			if (time_diff <= camera_y_duration)
				camera_y-=camera_y_speed*time_diff;
			else
				camera_y-=camera_y_speed*camera_y_duration;
			if(fabs(camera_y-old_camera_y) >= c_delta){
				adjust_view++;
			}
		}
		camera_y_duration-=time_diff;
	}
	if(camera_z_duration > 0){
		if(camera_z_speed>1E-4 || camera_z_speed<-1E-4){
			if (time_diff <= camera_z_duration)
				camera_z-=camera_z_speed*time_diff;
			else
				camera_z-=camera_z_speed*camera_z_duration;
			if(fabs(camera_z-old_camera_z) >= c_delta){
				adjust_view++;
			}
		}
		camera_z_duration-=time_diff;
	}

	if(camera_tilt_duration > 0) {
		if (time_diff <= camera_tilt_duration)
			rx+=camera_tilt_speed*time_diff;
		else
			rx+=camera_tilt_speed*camera_tilt_duration;
		camera_tilt_duration-=time_diff;
		adjust_view++;
	}
	if(camera_zoom_duration > 0) {
		if (time_diff <= camera_zoom_duration)
			new_zoom_level += camera_zoom_speed*(camera_zoom_dir==1?0.003f:-0.003f)*time_diff;
		else
			new_zoom_level += camera_zoom_speed*(camera_zoom_dir==1?0.003f:-0.003f)*camera_zoom_duration;
		camera_zoom_duration-=time_diff;
		adjust_view++;
	}
	else
		camera_zoom_speed = 1;


	if (camera_rotation_speed > 0.0)
	{
		camera_rotation_speed -= time_diff * camera_rotation_deceleration;
		if (camera_rotation_speed < 0.0)
			camera_rotation_speed = 0.0;
	}
	else if (camera_rotation_speed < 0.0)
	{
		camera_rotation_speed += time_diff * camera_rotation_deceleration;
		if (camera_rotation_speed > 0.0)
			camera_rotation_speed = 0.0;
	}
	if (camera_tilt_speed > 0.0)
	{
		camera_tilt_speed -= time_diff * camera_tilt_deceleration;
		if (camera_tilt_speed < 0.0)
			camera_tilt_speed = 0.0;
	}
	else if (camera_tilt_speed < 0.0)
	{
		camera_tilt_speed += time_diff * camera_tilt_deceleration;
		if (camera_tilt_speed > 0.0)
			camera_tilt_speed = 0.0;
	}

	clamp_camera();

	if (ext_cam && !first_person && me &&
		rx <= -min_tilt_angle && rx >= -max_tilt_angle)
	{
		float rot_x[9], rot_z[9], rot[9], dir[3];
		float vect[3] = {0.0, 0.0, new_zoom_level*camera_distance};
		int tx, ty;
		float tz;

		// we compute the camera position
		MAT3_ROT_X(rot_x, -rx*M_PI/180.0);
		MAT3_ROT_Z(rot_z, -rz*M_PI/180.0);
		MAT3_MULT(rot, rot_z, rot_x);
		MAT3_VECT3_MULT(dir, rot, vect);

		// we take the tile where the camera is
		tx = (int)((dir[0] - camera_x)*2);
		ty = (int)((dir[1] - camera_y)*2);

		if (get_tile_walkable(tx, ty))
		{
			tz = get_tile_height(tx, ty);
		}
		else
		{
			// if the tile is outside the map, we take the height at the actor position
			tz = get_tile_height(me->x_tile_pos, me->y_tile_pos);
		}
		// here we use a shift of 0.2 to avoid to be too close to the ground
		if (tz + 0.2 > dir[2] - camera_z)
		{
			if (ext_cam_auto_zoom) // new behaviour
			{
				// if the camera is under the ground, we change the zoom level
				if (fabsf(dir[2]) > 1E-4)
					new_zoom_level *= (tz + camera_z + 0.2) / dir[2];
				else
					new_zoom_level = 0.0;

				if (new_zoom_level < 1.0)
				{
					new_zoom_level = 1.0;
					camera_tilt_duration = camera_zoom_duration = 0;
					camera_tilt_speed = 0.0;
					if (fabsf(tz + camera_z + 0.2f) < fabsf(vect[2]) - 0.01)
						rx = -90.0 + 180.0 * asinf((tz + camera_z + 0.2) / vect[2]) / M_PI;
				}
				else if (new_zoom_level > old_zoom_level)
				{
					new_zoom_level = old_zoom_level;
					camera_tilt_duration = camera_zoom_duration = 0;
					camera_tilt_speed = 0.0;
				}
			}
			else // old freecam behaviour
			{
				new_zoom_level = old_zoom_level;
				camera_tilt_duration = camera_zoom_duration = 0;
				camera_tilt_speed = 0.0;
				if (fabsf(tz + camera_z + 0.2f) < fabsf(vect[2]) - 0.01)
					rx = -90.0 + 180.0 * asinf((tz + camera_z + 0.2) / vect[2]) / M_PI;
			}
		}
	}

	if(adjust_view){
		set_all_intersect_update_needed(main_bbox_tree);
		old_camera_x= camera_x;
		old_camera_y= camera_y;
		old_camera_z= camera_z;
	}

	
	hold_camera = rz;
	if (fol_cam) {
		static int fol_cam_stop = 0;

		if ((SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(2)) || camera_rotation_speed != 0)
			fol_cam_stop = 1;
		else if (me && me->moving && fol_cam_stop)
			fol_cam_stop = 0;

		if (last_kludge != camera_kludge && !fol_cam_stop) {
			set_all_intersect_update_needed(main_bbox_tree);
			adjust = (camera_kludge-last_kludge);

			//without this the camera will zip the wrong way when camera_kludge
			//flips from 180 <-> -180
			if      (adjust >=  180) adjust -= 360.0;
			else if (adjust <= -180) adjust += 360.0;

			if (fabs(adjust) < fol_strn) {
				last_kludge=camera_kludge;
			}
			else {
				last_kludge += fol_strn*(
					adjust*(fol_quad*fol_strn + fol_lin)+
					fol_con*(adjust>0?1:-1))/
					(fol_quad+fol_lin+fol_con+.000001f);//cheap no/0
			}
		}
		if (fol_cam_behind)
        {
            if (!fol_cam_stop)
                rz = -last_kludge;
            else
                last_kludge = -rz;
        }
		else
			rz -= last_kludge;
	}

	//Make Character Turn with Camera
	if (have_mouse && !on_the_move (get_our_actor ()))
	{
		adjust = rz;
		//without this the character will turn the wrong way when camera_kludge
		//and character are in certain positions
		if      (adjust >=  180) adjust -= 360.0;
		else if (adjust <= -180) adjust += 360.0;
		adjust+=camera_kludge;
		if      (adjust >=  180) adjust -= 360.0;
		else if (adjust <= -180) adjust += 360.0;
		if (adjust > 35){
			Uint8 str[2];
			str[0] = TURN_LEFT;
			my_tcp_send (my_socket, str, 1);
		} else if (adjust < -35){
			Uint8 str[2];
			str[0] = TURN_RIGHT;
			my_tcp_send (my_socket, str, 1);
		}
	}
	adjust_view = 0;
	last_update = cur_time;
}
예제 #16
0
bool InputManager::mousePressed(int button) const {
    return (_mouseState & SDL_BUTTON(button))
        && !(_prevMouseState & SDL_BUTTON(button));
 }
예제 #17
0
파일: exa-base.cpp 프로젝트: exaexa/orthos
bool exaIsMouseButtonHit (unsigned char button)
{
	if (SDL_BUTTON (button) &mbuttonhit) return true;
	return false;
}
예제 #18
0
bool InputManager::mouseDown(int button) const {
    return _mouseState & SDL_BUTTON(button);
}
예제 #19
0
bool InputManager::mouseUp(int button) const {
    return !(_mouseState & SDL_BUTTON(button));
}
예제 #20
0
int main(int argc, char **argv)
{

	//Initializes console Position
	HWND hWnd = GetConsoleWindow();
	MoveWindow(hWnd, 1350, 0, 500, 1000, TRUE);
	std::cout << "GameArtsEngine" << std::endl;


	//Initializes SDL and gets everything set up 
	SDL_Init(SDL_INIT_VIDEO);
	SDL_Window *window = SDL_CreateWindow("GameArtsEngine", 40, 40, windowWidth, windowHeight, SDL_WINDOW_OPENGL);
	SDL_GLContext glcontext = SDL_GL_CreateContext(window);

	//Initializes our Glew
	glewInit();

	//Initializes our Engine
	iGAEngine->initGL(windowWidth, windowHeight);

	aiString list;
	Assimp::Importer imp;
	imp.GetExtensionList(list);
	std::cout << list.C_Str() << std::endl;




										/**************************************ALL THE ONE TIME SCENE SETUP GOES HERE*******************************************/

	
	//Creates a basic Light for our scene --> will eventually be moved to the Engine itself
	mainLight = new Light(LIGHT_POINT);
	mainLight->setDiffuse(2, 2, 2, 1);
	mainLight->setExponent(10);
	mainLight->setPosition(-5,25,5);

	
	//Load Textures
	defaultTexture = iGAEngine->loadTexture("Assets/Textures/ModelgridTexture.jpg");

	//Load Models->Primitives ------------------------ENABLE IF YOU NEED PRIMITIVES---------------------------------
	teapodModel = new meshLoader("Assets/Models/Primitives/teapod.dae");
	cylinderModel = new meshLoader("Assets/Models/Primitives/cylinder.dae");
	sphereModel = new meshLoader("Assets/Models/Primitives/sphere.dae");
	cubeModel = new meshLoader("Assets/Models/Primitives/cube.dae");
	

	//Load Models->GameModels

	//-----------------------------------------------------------------------------------------SHADERSETUP--------------------------------------------
	
	if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader){

		cout << endl << "SHADER LOG: -------------------------------------------------------- BEGIN" << endl;
		
		// Simple Normal Shader without SpecMap
		normalShader = new Shader("normal.vert", "normal.frag");
		normalShader->useShader();
		normalShader->setAttribute1i("diffuseMap0", 0);
		normalShader->setAttribute1i("normalMap1", 1);
		normalShader->setAttribute1f("SpecularPower", 2.0f);
		normalShader->setAttribute4f("Specular", 0.5, 0.5, 0.5, 1.0);
		normalShader->setAttribute4f("Ambient", 0.3, 0.3, 0.3, 1.0);
		normalShader->setAttribute4f("Diffuse", 1, 1, 1, 1.0);
		normalShader->setAttribute3f("fvLightPosition", 50.3f, 18.9f, 27.2f);

		// Normal Shader with SpecMap
		normalSpecShader = new Shader("normalSpec.vert", "normalSpec.frag");
		normalSpecShader->useShader();
		normalSpecShader->setAttribute1i("diffuseMap0", 0);
		normalSpecShader->setAttribute1i("normalMap1", 1);
		normalSpecShader->setAttribute1i("specularMap2", 2);
		normalSpecShader->setAttribute1f("SpecularPower", 2.0f);
		normalSpecShader->setAttribute4f("Specular", 0.5, 0.5, 0.5, 1.0);
		normalSpecShader->setAttribute4f("Ambient", 0.3, 0.3, 0.3, 1.0);
		normalSpecShader->setAttribute4f("Diffuse", 1, 1, 1, 1.0);
		normalSpecShader->setAttribute3f("fvLightPosition", 50.3f, 18.9f, 27.2f);

		// Simple LambertShader with DiffuseMap
		diffuseShader = new Shader("lambertDiffuse.vert", "lambertDiffuse.frag");
		diffuseShader->useShader();
		diffuseShader->setAttribute4f("Ambient", 0.3, 0.3, 0.3, 1.0);
		diffuseShader->setAttribute4f("Diffuse", 1, 1, 1, 1.0);
		diffuseShader->setAttribute3f("fvLightPosition", 50.3f, 18.9f, 27.2f);


		lambertShader_static = new Shader("lambert_static.vert", "lambert_static.frag");
		lambertShader_static->useShader();
		lambertShader_static->setAttribute4f("Ambient", 0.3, 0.3, 0.3, 1.0);
		lambertShader_static->setAttribute4f("Diffuse", 1, 1, 1, 1.0);
		lambertShader_static->setAttribute3f("fvLightPosition", 50.3f, 18.9f, 27.2f);
		
		cout << endl << "SHADER LOG: ---------------------------------------------------------- END" << endl;

	}
	else{
		cout << endl << "GLSL not supported" << endl;
	}

	//-----------------------------------------------------------------------------------------SHADERSETUP--------------------------------------------




										/**************************************ALL THE ONE TIME SCENE SETUP GOES HERE*******************************************/

	
	// Main Engine Loop
	bool isRunning = true;
	SDL_Event  event;

	while (isRunning )
	{
		//Gets states of the Mouse and stroes them in the struct
		SDL_GetMouseState(&mouseState.x, &mouseState.y);
		mouseState.LeftButtonDown = SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(1);
		mouseState.MiddleButtonDown = SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(2);
		mouseState.RightButtonDown = SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(3);

		drawMainScene(window); // calls stuff that needs to update every frame
		
		//Event loop
		while (SDL_PollEvent(&event)){

			if (event.type == SDL_QUIT)
				isRunning = false;
		}


		if (viewportNavigation())
			isRunning = false;
	}

	delete teapodModel;
	delete lambertShader_static;
	delete diffuseShader;
	delete normalShader;
	delete normalSpecShader;

	GAEngine::Unitialize();


	SDL_Quit();

	return 1;

}
예제 #21
0
static bool process_event(SDL_Event *event)
{
  struct buffered_status *status = store_status();
  enum keycode ckey;

  /* SDL's numlock keyboard modifier handling seems to be broken on X11,
   * and it will only get numlock's status right on application init. We
   * can trust this value once, and then toggle based on user presses of
   * the numlock key.
   *
   * On Windows, KEYDOWN/KEYUP seem to be sent separately, to indicate
   * enabling or disabling of numlock. But on X11, both KEYDOWN/KEYUP are
   * sent for each toggle, so this must be handled differently.
   *
   * What a mess!
   */
  if(!numlock_status_initialized)
  {
    status->numlock_status = !!(SDL_GetModState() & KMOD_NUM);
    numlock_status_initialized = true;
  }

  switch(event->type)
  {
    case SDL_QUIT:
    {
      // Stuff an escape
      status->key = IKEY_ESCAPE;
      status->keymap[IKEY_ESCAPE] = 1;
      status->keypress_time = get_ticks();
      break;
    }

#if SDL_VERSION_ATLEAST(2,0,0)
    case SDL_WINDOWEVENT:
    {
      switch(event->window.event)
      {
        case SDL_WINDOWEVENT_RESIZED:
        {
          resize_screen(event->window.data1, event->window.data2);
          break;
        }

        case SDL_WINDOWEVENT_FOCUS_LOST:
        {
          // Pause while minimized
          if(input.unfocus_pause)
          {
            while(1)
            {
              SDL_WaitEvent(event);

              if(event->type == SDL_WINDOWEVENT &&
                 event->window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
                break;
            }
          }
          break;
        }
      }

      break;
    }
#else // !SDL_VERSION_ATLEAST(2,0,0)
    case SDL_VIDEORESIZE:
    {
      resize_screen(event->resize.w, event->resize.h);
      break;
    }

    case SDL_ACTIVEEVENT:
    {
      if(input.unfocus_pause)
      {
        // Pause while minimized
        if(event->active.state & (SDL_APPACTIVE | SDL_APPINPUTFOCUS))
        {
          // Wait for SDL_APPACTIVE with gain of 1
          do
          {
            SDL_WaitEvent(event);
          } while((event->type != SDL_ACTIVEEVENT) ||
           (event->active.state & ~(SDL_APPACTIVE | SDL_APPINPUTFOCUS)));
        }
      }
      break;
    }
#endif // !SDL_VERSION_ATLEAST(2,0,0)

    case SDL_MOUSEMOTION:
    {
      SDL_Window *window = SDL_GetWindowFromID(sdl_window_id);
      int mx_real = event->motion.x;
      int my_real = event->motion.y;
      int mx, my, min_x, min_y, max_x, max_y;
      get_screen_coords(mx_real, my_real, &mx, &my, &min_x,
       &min_y, &max_x, &max_y);

      if(mx > 639)
        SDL_WarpMouseInWindow(window, max_x, my_real);

      if(mx < 0)
        SDL_WarpMouseInWindow(window, min_x, my_real);

      if(my > 349)
        SDL_WarpMouseInWindow(window, mx_real, max_y);

      if(my < 0)
        SDL_WarpMouseInWindow(window, mx_real, min_y);

      status->real_mouse_x = mx;
      status->real_mouse_y = my;
      status->mouse_x = mx / 8;
      status->mouse_y = my / 14;
      status->mouse_moved = true;
      break;
    }

    case SDL_MOUSEBUTTONDOWN:
    {
      status->mouse_button = event->button.button;
      status->mouse_repeat = event->button.button;
      status->mouse_button_state |= SDL_BUTTON(event->button.button);
      status->mouse_repeat_state = 1;
      status->mouse_drag_state = -1;
      status->mouse_time = SDL_GetTicks();
      break;
    }

    case SDL_MOUSEBUTTONUP:
    {
      status->mouse_button_state &= ~SDL_BUTTON(event->button.button);
      status->mouse_repeat = 0;
      status->mouse_drag_state = 0;
      status->mouse_repeat_state = 0;
      break;
    }

#if SDL_VERSION_ATLEAST(2,0,0)
    // emulate the X11-style "wheel is a button" that SDL 1.2 used
    case SDL_MOUSEWHEEL:
    {
      SDL_Event fake_event;

      fake_event.type = SDL_MOUSEBUTTONDOWN;
      fake_event.button.windowID = event->wheel.windowID;
      fake_event.button.which = event->wheel.which;
      fake_event.button.state = SDL_PRESSED;
      fake_event.button.x = 0;
      fake_event.button.y = 0;

      if(event->wheel.y < 0)
        fake_event.button.button = MOUSE_BUTTON_WHEELDOWN;
      else
        fake_event.button.button = MOUSE_BUTTON_WHEELUP;

      SDL_PushEvent(&fake_event);

      fake_event.type = SDL_MOUSEBUTTONUP;
      fake_event.button.state = SDL_RELEASED;

      SDL_PushEvent(&fake_event);
      break;
    }
#endif // SDL_VERSION_ATLEAST(2,0,0)

    case SDL_KEYDOWN:
    {
      Uint16 unicode = 0;

#if SDL_VERSION_ATLEAST(2,0,0)
      // FIXME: SDL 2.0 finally implements proper key repeat.
      // We should probably use it instead of our hand-rolled stuff.
      if(event->key.repeat)
        break;
#endif

      ckey = convert_SDL_internal(event->key.keysym.sym);
      if(!ckey)
      {
#if !SDL_VERSION_ATLEAST(2,0,0)
        if(!event->key.keysym.unicode)
          break;
#endif
        ckey = IKEY_UNICODE;
      }

#if SDL_VERSION_ATLEAST(2,0,0)
      // SDL 2.0 sends the raw key and translated 'text' as separate events.
      // There is no longer a UNICODE mode that sends both at once.
      // Because of the way the SDL 1.2 assumption is embedded deeply in
      // the MZX event queue processor, emulate the 1.2 behaviour by waiting
      // for a TEXTINPUT event after a KEYDOWN.
      if(SDL_WaitEventTimeout(event, 1))
      {
        if(event->type == SDL_TEXTINPUT)
          unicode = event->text.text[0] | event->text.text[1] << 8;
        else
          SDL_PushEvent(event);
      }
#else
      unicode = event->key.keysym.unicode;
#endif

      if((ckey == IKEY_RETURN) &&
       get_alt_status(keycode_internal) &&
       get_ctrl_status(keycode_internal))
      {
        toggle_fullscreen();
        break;
      }

      if(ckey == IKEY_CAPSLOCK)
      {
        status->caps_status = true;
      }

      if(ckey == IKEY_NUMLOCK)
      {
#if !SDL_VERSION_ATLEAST(2,0,0) && defined(__WIN32__)
        status->numlock_status = true;
#endif
        break;
      }

      if(ckey == IKEY_F12)
      {
        dump_screen();
        break;
      }

      // Ignore alt + tab
      if((ckey == IKEY_TAB) && get_alt_status(keycode_internal))
      {
        break;
      }

      if(status->key_repeat &&
       (status->key_repeat != IKEY_LSHIFT) &&
       (status->key_repeat != IKEY_RSHIFT) &&
       (status->key_repeat != IKEY_LALT) &&
       (status->key_repeat != IKEY_RALT) &&
       (status->key_repeat != IKEY_LCTRL) &&
       (status->key_repeat != IKEY_RCTRL))
      {
        // Stack current repeat key if it isn't shift, alt, or ctrl
        if(input.repeat_stack_pointer != KEY_REPEAT_STACK_SIZE)
        {
          input.key_repeat_stack[input.repeat_stack_pointer] =
           status->key_repeat;
          input.unicode_repeat_stack[input.repeat_stack_pointer] =
           status->unicode_repeat;
          input.repeat_stack_pointer++;
        }
      }

      key_press(status, ckey, unicode);
      break;
    }

    case SDL_KEYUP:
    {
#if SDL_VERSION_ATLEAST(2,0,0)
      // FIXME: SDL 2.0 finally implements proper key repeat.
      // We should probably use it instead of our hand-rolled stuff.
      if(event->key.repeat)
        break;
#endif

      ckey = convert_SDL_internal(event->key.keysym.sym);
      if(!ckey)
      {
#if !SDL_VERSION_ATLEAST(2,0,0)
        if(!status->keymap[IKEY_UNICODE])
          break;
#endif
        ckey = IKEY_UNICODE;
      }

      if(ckey == IKEY_NUMLOCK)
      {
#if !SDL_VERSION_ATLEAST(2,0,0) && defined(__WIN32__)
        status->numlock_status = false;
#else
        status->numlock_status = !status->numlock_status;
#endif
        break;
      }

      if(ckey == IKEY_CAPSLOCK)
      {
        status->caps_status = false;
      }

      status->keymap[ckey] = 0;
      if(status->key_repeat == ckey)
      {
        status->key_repeat = IKEY_UNKNOWN;
        status->unicode_repeat = 0;
      }
      status->key_release = ckey;
      break;
    }

    case SDL_JOYAXISMOTION:
    {
      int axis_value = event->jaxis.value;
      int digital_value = -1;
      int which = event->jaxis.which;
      int axis = event->jaxis.axis;
      Sint8 last_axis = status->axis[which][axis];
      enum keycode stuffed_key;

      if(axis_value > 10000)
        digital_value = 1;
      else

      if(axis_value < -10000)
        digital_value = 0;

      if(digital_value != -1)
      {
        stuffed_key =
          input.joystick_axis_map[which][axis][digital_value];

        if(stuffed_key)
        {
          joystick_key_press(status, stuffed_key, stuffed_key);

          if(last_axis == (digital_value ^ 1))
          {
            joystick_key_release(status,
             input.joystick_axis_map[which][axis][last_axis]);
          }
        }
      }
      else if(last_axis != -1)
      {
        joystick_key_release(status,
          input.joystick_axis_map[which][axis][last_axis]);
      }

      status->axis[which][axis] = digital_value;
      break;
    }

    case SDL_JOYBUTTONDOWN:
    {
      int which = event->jbutton.which;
      int button = event->jbutton.button;
      enum keycode stuffed_key = input.joystick_button_map[which][button];

      if(stuffed_key)
        joystick_key_press(status, stuffed_key, stuffed_key);

      break;
    }

    case SDL_JOYBUTTONUP:
    {
      int which = event->jbutton.which;
      int button = event->jbutton.button;
      enum keycode stuffed_key = input.joystick_button_map[which][button];

      if(stuffed_key)
        joystick_key_release(status, stuffed_key);

      break;
    }
    
    case SDL_JOYHATMOTION:
    {
      int which = event->jhat.which;
      int dir = event->jhat.value;
      enum keycode key_up = input.joystick_hat_map[which][0];
      enum keycode key_down = input.joystick_hat_map[which][1];
      enum keycode key_left = input.joystick_hat_map[which][2];
      enum keycode key_right = input.joystick_hat_map[which][3];
      
      //if(dir & SDL_HAT_CENTERED)
      {
        joystick_key_release(status, key_up);
        joystick_key_release(status, key_down);
        joystick_key_release(status, key_left);
        joystick_key_release(status, key_right);
      }
    
      if(dir & SDL_HAT_UP)
      {
        if (key_up)
          joystick_key_press(status, key_up, key_up);
      }
      
      if(dir & SDL_HAT_DOWN)
      {
        if (key_down)
          joystick_key_press(status, key_down, key_down);
      }
      
      if(dir & SDL_HAT_LEFT)
      {
        if (key_left)
          joystick_key_press(status, key_left, key_left);
      }
      
      if(dir & SDL_HAT_RIGHT)
      {
        if (key_right)
          joystick_key_press(status, key_right, key_right);
      }
      
      break;
    }

    default:
      return false;
  }

  return true;
}
예제 #22
0
bool controls::inputUpdate(SDL_Event* evt)
{
	const Uint8* keystate = SDL_GetKeyboardState(NULL);
	
	//KEY PRESSES
	if (keystate[SDL_SCANCODE_RETURN])
	{
		ENTER = true;
		cout << "ENTER PRESSED" << endl;
		return ENTER;	
	}

	if (keystate[SDL_SCANCODE_UP])
	{
		UP = true;
		cout << "UP PRESSED" << endl;
		return UP;
	}

	if (keystate[SDL_SCANCODE_DOWN])
	{
		DOWN = true;
		cout << "DOWN PRESSED" << endl;
		return DOWN;
	}

	if (keystate[SDL_SCANCODE_LEFT])
	{
		LEFT = true;
		cout << "LEFT PRESSED" << endl;
		return LEFT;
	}

	if (keystate[SDL_SCANCODE_RIGHT])
	{
		RIGHT = true;
		cout << "RIGHT PRESSED" << endl;
		return RIGHT;
	}

	Uint32 SDL_GetMouseState(int* x, int* y);
	SDL_PumpEvents();
	if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT))
	{
		MOUSELEFT = true;
		cout << "MOUSE LEFT PRESSED" << endl;
		return MOUSELEFT;
	}

	if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT))
	{
		MOUSERIGHT = true;
		cout << "MOUSE RIGHT PRESSED" << endl;
		return MOUSERIGHT;
	}

	//KEY RELEASES
	if (!keystate[SDL_SCANCODE_RETURN])
	{
		ENTER = false;
		return ENTER;
	}

	if (!keystate[SDL_SCANCODE_UP])
	{
		UP = false;
		return UP;
	}


	if (!keystate[SDL_SCANCODE_DOWN])
	{
		DOWN = false;
		return DOWN;
	}

	

	if (!keystate[SDL_SCANCODE_LEFT])
	{
		LEFT = false;
		return LEFT;
	}

	if (!keystate[SDL_SCANCODE_RIGHT])
	{
		RIGHT = false;
		return RIGHT;
	}
	return false;
}
예제 #23
0
bool SDLwindow::processEvents()
{
    SDL_Event event;
    while(SDL_PollEvent(&event)){
        switch(event.type){
        case SDL_QUIT:
            return false;
        case SDL_KEYDOWN:
        {
            //printf("%d\n", event.key.keysym.sym);
            int delta = isShiftPressed ? 10 : 1;
            switch(event.key.keysym.sym){
            case SDLK_h:
                if (showingHelp){
                    scene->setMessages(helpcommand);
                }else{
                    scene->setMessages(instructions);
                }
                showingHelp = !showingHelp;
                break;
            case SDLK_i:
                log->record(1);
                scene->capture();
                break;
            case SDLK_q:
                return false;
            case SDLK_p:
                if (throbj){
                    if (throbj->isPausing()){
                        throbj->resume();
                    }else{
                        throbj->pause();
                    }
                }
                break;
            case SDLK_SPACE:
                log->play(); 
                break;
            case SDLK_t:
                scene->toggleRobotState(); 
                break;
            case SDLK_f:
                log->faster();
                break;
            case SDLK_s:
                log->slower();
                break;
            case SDLK_r:
                log->record(20);
                break;
            case SDLK_d:
            {
                int drawMode = GLlink::drawMode()+1;
                if (drawMode == GLlink::DM_NUM) drawMode=0;
                GLlink::drawMode(drawMode);
                break;
            }
            case SDLK_n:
                scene->nextCamera();
                break;
            case SDLK_o:
                scene->nextObject();
                break;
            case SDLK_c:
                log->clear();
                scene->clear();
                break;
            case SDLK_g:
                scene->showFloorGrid(!scene->showFloorGrid());
                break;
            case SDLK_l:
                scene->defaultLights(!scene->defaultLights());
                break;
            case SDLK_v:
                {
                    hrp::Vector3 center = scene->center();
                    xCenter = center[0];
                    yCenter = center[1];
                    zCenter = center[2];
                }
                break;
            case SDLK_RIGHT:
                if (isControlPressed){
                    log->tail();
                }else{
                    log->next(delta);
                }
                break;
            case SDLK_LEFT:
                if (isControlPressed){
                    log->head();
                }else{
                    log->prev(delta);
                }
                break;
            case SDLK_LSHIFT:
            case SDLK_RSHIFT:
                isShiftPressed = true;
                break;
            case SDLK_LCTRL:
            case SDLK_RCTRL:
                isControlPressed = true;
                break;
            }
            break;
        }
        case SDL_KEYUP:
            switch(event.key.keysym.sym){
            case SDLK_LSHIFT:
            case SDLK_RSHIFT:
                    isShiftPressed = false;
                    break;
            case SDLK_LCTRL:
            case SDLK_RCTRL:
                isControlPressed = false;
                break;
            }
            break;
            
        case SDL_MOUSEBUTTONDOWN:
            switch(event.button.button){
            case SDL_BUTTON_LEFT:
                if (event.button.y > height-SLIDER_AREA_HEIGHT){
                    log->move(sliderRatio(event.button.x));
                    buttonPressedInSliderArea = true;
                }else{
                    buttonPressedInSliderArea = false;
                }
                break;
            case SDL_BUTTON_MIDDLE:
                break;
            case SDL_BUTTON_RIGHT:
                break;
            case SDL_BUTTON_WHEELUP:
                if (isShiftPressed){
                    xCenter -= 0.2*cos(tilt)*cos(pan);
                    yCenter -= 0.2*cos(tilt)*sin(pan);
                    zCenter -= 0.2*sin(tilt);
                }else{
                    radius *= 0.9;
                    if (radius < 0.1) radius = 0.1; 
                }
                break;
            case SDL_BUTTON_WHEELDOWN:
                if (isShiftPressed) {
                    xCenter += 0.2*cos(tilt)*cos(pan);
                    yCenter += 0.2*cos(tilt)*sin(pan);
                    zCenter += 0.2*sin(tilt);
                }else{
                    radius *= 1.1;
                }
                break;
            }
        case SDL_MOUSEBUTTONUP:
            switch(event.button.button){
            case SDL_BUTTON_LEFT:
                break;
            case SDL_BUTTON_MIDDLE:
                break;
            case SDL_BUTTON_RIGHT:
                break;
            case SDL_BUTTON_WHEELUP:
                break;
            case SDL_BUTTON_WHEELDOWN:
                break;
            }
            break;
        case SDL_MOUSEMOTION:
        {
            int dx = event.motion.xrel;
            int dy = event.motion.yrel;
            if (event.motion.state&SDL_BUTTON(SDL_BUTTON_LEFT)){
                if (isShiftPressed){
                    radius *= (1+ 0.1*dy);
                    if (radius < 0.1) radius = 0.1; 
                }else{
                    if (buttonPressedInSliderArea){
                        log->move(sliderRatio(event.motion.x));
                    }else{
                        pan  -= 0.05*dx;
                        tilt += 0.05*dy;
                        if (tilt >  M_PI/2) tilt =  M_PI/2;
                        if (tilt < -M_PI/2) tilt = -M_PI/2;
                    }
                }
            }else if (event.motion.state&SDL_BUTTON(SDL_BUTTON_RIGHT)){
                xCenter += sin(pan)*dx*0.01;
                yCenter -= cos(pan)*dx*0.01;
                zCenter += dy*0.01;
            }
            scene->showSlider(event.motion.y > height-SLIDER_AREA_HEIGHT);
        }
        break;
        case SDL_VIDEORESIZE:
            width = event.resize.w;
            height = event.resize.h;
            SDL_SetVideoMode(width,height,32,SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL | SDL_RESIZABLE);
            scene->setScreenSize(width, height);
            break;
        }
    }
    return true;
}
예제 #24
0
bool BaseAppInput::handleMouse(void)
{
	Uint8 buttons = SDL_GetMouseState(NULL, NULL);
	
	bool left = buttons & SDL_BUTTON(1);
	bool right = buttons & SDL_BUTTON(2);
	bool middle = buttons & SDL_BUTTON(3);
	
	//fire our own mouse up/down events
	if (left)
	{
		if (!mWasLeftDown)
		{
			if (! fireLeftMouseDown() )
			{
				return false;
			}
		}
	}
	else
	{
		if (mWasLeftDown)
		{
			if (! fireLeftMouseUp() )
			{
				return false;
			}
		}
	}
	
	if (right)
	{
		if (!mWasRightDown)
		{
			if (! fireRightMouseDown() )
			{
				return false;
			}
		}
	}
	else
	{
		if (mWasRightDown)
		{
			if (! fireRightMouseUp() )
			{
				return false;
			}
		}
	}
	
	if (middle)
	{
		if (!mWasMiddleDown)
		{
			if (! fireMiddleMouseDown() )
			{
				return false;
			}
		}
	}
	else
	{
		if (mWasMiddleDown)
		{
			if (! fireMiddleMouseUp() )
			{
				return false;
			}
		}
	}
	
	mWasLeftDown = left;
	mWasRightDown = right;
	mWasMiddleDown = middle;
	return true;
}
예제 #25
0
파일: button-sdl.c 프로젝트: IlVerz/rockbox
static bool event_handler(SDL_Event *event)
{
    SDLKey ev_key;

    switch(event->type)
    {
    case SDL_ACTIVEEVENT:
        if (event->active.state & SDL_APPINPUTFOCUS)
        {
            if (event->active.gain == 1)
                sdl_app_has_input_focus = 1;
            else
                sdl_app_has_input_focus = 0;
        }
        break;
    case SDL_KEYDOWN:
    case SDL_KEYUP:
        ev_key = event->key.keysym.sym;
#if (CONFIG_PLATFORM & PLATFORM_MAEMO5)
        /* N900 with shared up/down cursor mapping. Seen on the German,
           Finnish, Italian, French and Russian version. Probably more. */
        if (event->key.keysym.mod & KMOD_MODE || n900_updown_key_pressed)
        {
            /* Prevent stuck up/down keys: If you release the ALT key before the cursor key,
               rockbox will see a KEYUP event for left/right instead of up/down and
               the previously pressed up/down key would stay active. */
            if (ev_key == SDLK_LEFT || ev_key == SDLK_RIGHT)
            {
                if (event->type == SDL_KEYDOWN)
                    n900_updown_key_pressed = 1;
                else
                    n900_updown_key_pressed = 0;
            }

            if (ev_key == SDLK_LEFT)
                ev_key = SDLK_UP;
            else if (ev_key == SDLK_RIGHT)
                ev_key = SDLK_DOWN;
        }
#endif
        button_event(ev_key, event->type == SDL_KEYDOWN);
        break;
#ifdef HAVE_TOUCHSCREEN
    case SDL_MOUSEMOTION:
        if (event->motion.state & SDL_BUTTON(1))
        {
            int x = event->motion.x / display_zoom;
            int y = event->motion.y / display_zoom;
            touchscreen_event(x, y);
        }
        break;
#endif

    case SDL_MOUSEBUTTONUP:
    case SDL_MOUSEBUTTONDOWN:
    {
        SDL_MouseButtonEvent *mev = &event->button;
        mev->x /= display_zoom;
        mev->y /= display_zoom;
        mouse_event(mev, event->type == SDL_MOUSEBUTTONUP);
        break;
    }
    case SDL_QUIT:
        /* Will post SDL_USEREVENT in shutdown_hw() if successful. */
        sys_poweroff();
        break;
    case SDL_USEREVENT:
        return true;
        break;
    }

    return false;
}
예제 #26
0
파일: main.cpp 프로젝트: rafaelcor/thegame
int main(){
 init();

 SDL_Event event;
 const Uint8 *keystate;

 for(;;){
  int time = SDL_GetTicks();
  colision = false;
  SDL_PumpEvents();
  while(SDL_PollEvent(&event)){
   if(event.type == SDL_QUIT){
    SDL_Quit();
    return 0; }
   if(event.type == SDL_MOUSEMOTION and event.motion.state&SDL_BUTTON(1)){
    move = true;
    rad = angy*PI/180;
    angxz += event.motion.yrel;
    angy += event.motion.xrel;
    sx += (event.motion.xrel/((float) 100))*cos(rad);
    sz += (event.motion.xrel/((float) 100))*sin(rad); }
   if(event.type == SDL_MOUSEBUTTONUP){
    if(not move and is_selected){
     if(event.button.button == SDL_BUTTON_RIGHT){
      take_cube();
     }
     if(event.button.button == SDL_BUTTON_LEFT and id_inv[miniactual]){
      put_cube();
     }
    }
    else if(move){
     move = false;
    }
   }
  }

  movx = 0;
  movy = 0;
  movz = 0;
  keystate = SDL_GetKeyboardState(NULL);

  move_update(keystate);

  if(keystate[SDL_SCANCODE_1]){
   miniactual = 0;
  }
  if(keystate[SDL_SCANCODE_2]){
   miniactual = 1;
  }
  if(keystate[SDL_SCANCODE_3]){
   miniactual = 2;
  }
  if(keystate[SDL_SCANCODE_4]){
   miniactual = 3;
  }
  if(keystate[SDL_SCANCODE_5]){
   miniactual = 4;
  }
  if(keystate[SDL_SCANCODE_6]){
   miniactual = 5;
  }
  if(keystate[SDL_SCANCODE_7]){
   miniactual = 6;
  }
  if(keystate[SDL_SCANCODE_8]){
   miniactual = 7;
  }
  
  #if FLY
   caida += 0;
  #else
   caida += CUBE_SIZE*GRAVEDAD;
  #endif

  movy += caida;
  posy += caida;

  glLoadIdentity();
  glRotatef(angy, 0, 1, 0);
  glRotatef(angxz, cos(rad), 0, sin(rad));
  glTranslatef(-posx, posy-(CUBE_SIZE*1.5), posz);
  update();

  if(colision){
   glLoadIdentity();
   glRotatef(angy, 0, 1, 0);
   glRotatef(angxz, cos(rad), 0, sin(rad));
   glTranslatef(-posx, posy-(CUBE_SIZE*1.5), posz);
   update();
  }

  SDL_GL_SwapWindow(window);
  SDL_RenderPresent(sdlRenderer);
  int wait;
  int ftime = SDL_GetTicks()-time;
  if((wait = 1000/FPS-ftime) >= 0) SDL_Delay(wait);
 }
 return 0;
}
예제 #27
0
void IntroState::handle_mouse(const int x, const int y, const Uint8 mouse_button_state) {
    if (mouse_button_state & SDL_BUTTON(1)) {
        std::cout << "Mouse Button 1(left) is pressed.\n" << x << " , " << y << std::endl;
    }                            
}
예제 #28
0
파일: rudl_events.c 프로젝트: matozoid/rudl
VALUE sDLEvent2RubyEvent(SDL_Event* event)
{
    VALUE newEvent=Qnil;

    int hx,hy;

    switch(event->type){
        case SDL_ACTIVEEVENT:
            newEvent=rb_funcall(classActiveEvent, id_new, 0);
            rb_iv_set(newEvent, "@gain", UINT2NUM(event->active.gain));
            rb_iv_set(newEvent, "@state", UINT2NUM(event->active.state));
            break;
        case SDL_KEYDOWN:
            newEvent=rb_funcall(classKeyDownEvent, id_new, 0);
            rb_iv_set(newEvent, "@key", UINT2NUM(event->key.keysym.sym));
            rb_iv_set(newEvent, "@mod", UINT2NUM(event->key.keysym.mod));
            rb_iv_set(newEvent, "@unicode", UINT2NUM(event->key.keysym.unicode));

            break;
        case SDL_KEYUP:
            newEvent=rb_funcall(classKeyUpEvent, id_new, 0);
            rb_iv_set(newEvent, "@key", UINT2NUM(event->key.keysym.sym));
            rb_iv_set(newEvent, "@mod", UINT2NUM(event->key.keysym.mod));
            rb_iv_set(newEvent, "@unicode", UINT2NUM(event->key.keysym.unicode));

            break;
        case SDL_QUIT:
            newEvent=rb_funcall(classQuitEvent, id_new, 0);
            break;
        case SDL_MOUSEMOTION:
            newEvent=rb_funcall(classMouseMotionEvent, id_new, 0);
            rb_iv_set(newEvent, "@pos", rb_ary_new3(2, INT2NUM(event->motion.x), INT2NUM(event->motion.y)));
            rb_iv_set(newEvent, "@rel", rb_ary_new3(2, INT2NUM(event->motion.xrel), INT2NUM(event->motion.yrel)));
            rb_iv_set(newEvent, "@button", rb_ary_new3(3,
                INT2BOOL(event->motion.state&SDL_BUTTON(1)),
                INT2BOOL(event->motion.state&SDL_BUTTON(2)),
                INT2BOOL(event->motion.state&SDL_BUTTON(3))));
            break;
        case SDL_MOUSEBUTTONDOWN:
            newEvent=rb_funcall(classMouseButtonDownEvent, id_new, 0);
            rb_iv_set(newEvent, "@pos", rb_ary_new3(2,
                INT2NUM(event->button.x),
                INT2NUM(event->button.y)));
            rb_iv_set(newEvent, "@button", UINT2NUM(event->button.button));
            break;
        case SDL_MOUSEBUTTONUP:
            newEvent=rb_funcall(classMouseButtonUpEvent, id_new, 0);
            rb_iv_set(newEvent, "@pos", rb_ary_new3(2,
                INT2NUM(event->button.x),
                INT2NUM(event->button.y)));
            rb_iv_set(newEvent, "@button", UINT2NUM(event->button.button));
            break;
        case SDL_JOYAXISMOTION:
            newEvent=rb_funcall(classJoyAxisEvent, id_new, 0);
            rb_iv_set(newEvent, "@id", INT2NUM(event->jaxis.which));
            rb_iv_set(newEvent, "@value", DBL2NUM(event->jaxis.value/32767.0));
            rb_iv_set(newEvent, "@axis", INT2NUM(event->jaxis.axis));
            break;
        case SDL_JOYBALLMOTION:
            newEvent=rb_funcall(classJoyBallEvent, id_new, 0);
            rb_iv_set(newEvent, "@id", INT2NUM(event->jball.which));
            rb_iv_set(newEvent, "@ball", INT2NUM(event->jball.ball));
            rb_iv_set(newEvent, "@rel", rb_ary_new3(2,
                INT2NUM(event->jball.xrel),
                INT2NUM(event->jball.yrel)));
            break;
        case SDL_JOYHATMOTION:
            newEvent=rb_funcall(classJoyHatEvent, id_new, 0);
            rb_iv_set(newEvent, "@id", INT2NUM(event->jhat.which));
            rb_iv_set(newEvent, "@hat", INT2NUM(event->jhat.hat));
            hx = hy = 0;
            if(event->jhat.value&SDL_HAT_UP) hy = 1;
            else if(event->jhat.value&SDL_HAT_DOWN) hy = -1;
            if(event->jhat.value&SDL_HAT_LEFT) hx = 1;
            else if(event->jhat.value&SDL_HAT_LEFT) hx = -1;
            rb_iv_set(newEvent, "@value", rb_ary_new3(2, INT2NUM(hx), INT2NUM(hy)));
            break;
        case SDL_JOYBUTTONUP:
            newEvent=rb_funcall(classJoyButtonUpEvent, id_new, 0);
            rb_iv_set(newEvent, "@id", INT2NUM(event->jbutton.which));
            rb_iv_set(newEvent, "@button", INT2NUM(event->jbutton.button));
            break;
        case SDL_JOYBUTTONDOWN:
            newEvent=rb_funcall(classJoyButtonDownEvent, id_new, 0);
            rb_iv_set(newEvent, "@id", INT2NUM(event->jbutton.which));
            rb_iv_set(newEvent, "@button", INT2NUM(event->jbutton.button));
            break;
        case SDL_VIDEORESIZE:
            {
                /* automatically call DisplaySurface.new to fix the clipping */
                VALUE newDS, oldDS = currentDisplaySurface;

                newDS = rb_funcall(classDisplaySurface, id_new, currDSnumargs,
                    rb_ary_new3(2, UINT2NUM(event->resize.w), UINT2NUM(event->resize.h)),
                    currDSflags, currDSdepth);

                /* keep the old object */
                currentDisplaySurface = oldDS;
                /* replace its SDL_Surface pointer with the new one */
                DATA_PTR(oldDS) = DATA_PTR(newDS);

                newEvent=rb_funcall(classResizeEvent, id_new, 0);
                rb_iv_set(newEvent, "@size", rb_ary_new3(2,
                    UINT2NUM(event->resize.w),
                    UINT2NUM(event->resize.h)));
                break;
            }
        case SDL_VIDEOEXPOSE:
            newEvent=rb_funcall(classVideoExposeEvent, id_new, 0);
            break;
        case RUDL_TIMEREVENT:
            newEvent=rb_funcall(classTimerEvent, id_new, 0);
            rb_iv_set(newEvent, "@id", INT2NUM(event->user.code));
            break;
        case RUDL_ENDMUSICEVENT:
            newEvent=rb_funcall(classEndOfMusicEvent, id_new, 0);
            break;
/*      else
            if(event->type > USEREVENT && event->type < NUMEVENTS){
                newEvent=rb_funcall(classEvent, id_new, 0);
                rb_iv_set(newEvent, "@code", INT2NUM(event->user.code));
                rb_iv_set(newEvent, "@data1", INT2NUM(event->user.data1));
                rb_iv_set(newEvent, "@data2", INT2NUM(event->user.data2));
            }*/
    }

    RUDL_ASSERT(newEvent!=Qnil, "Unknown event received from SDL (SDL too new for this RUDL version?)");

    return newEvent;
}
예제 #29
0
void CEvent::OnEvent(SDL_Event* Event) {
    switch(Event->type) {
    case SDL_ACTIVEEVENT: {
        switch(Event->active.state) {
        case SDL_APPMOUSEFOCUS: {
            if ( Event->active.gain )
                OnMouseFocus();
            else
                OnMouseBlur();
            break;
        }
        case SDL_APPINPUTFOCUS: {
            if ( Event->active.gain )
                OnInputFocus();
            else
                OnInputBlur();
            break;
        }
        case SDL_APPACTIVE:    {
            if ( Event->active.gain )
                OnRestore();
            else
                OnMinimize();
            break;
        }
        }
        break;
    }

    case SDL_KEYDOWN: {
        OnKeyDown(Event->key.keysym.sym,Event->key.keysym.mod,Event->key.keysym.unicode);
        break;
    }

    case SDL_KEYUP: {
        OnKeyUp(Event->key.keysym.sym,Event->key.keysym.mod,Event->key.keysym.unicode);
        break;
    }

    case SDL_MOUSEMOTION: {
        OnMouseMove(Event->motion.x,Event->motion.y,Event->motion.xrel,Event->motion.yrel,(Event->motion.state&SDL_BUTTON(SDL_BUTTON_LEFT))!=0,(Event->motion.state&SDL_BUTTON(SDL_BUTTON_RIGHT))!=0,(Event->motion.state&SDL_BUTTON(SDL_BUTTON_MIDDLE))!=0);
        break;
    }

    case SDL_MOUSEBUTTONDOWN: {
        switch(Event->button.button) {
        case SDL_BUTTON_LEFT: {
            OnLButtonDown(Event->button.x,Event->button.y);
            break;
        }
        case SDL_BUTTON_RIGHT: {
            OnRButtonDown(Event->button.x,Event->button.y);
            break;
        }
        case SDL_BUTTON_MIDDLE: {
            OnMButtonDown(Event->button.x,Event->button.y);
            break;
        }
        }
        break;
    }

    case SDL_MOUSEBUTTONUP:    {
        switch(Event->button.button) {
        case SDL_BUTTON_LEFT: {
            OnLButtonUp(Event->button.x,Event->button.y);
            break;
        }
        case SDL_BUTTON_RIGHT: {
            OnRButtonUp(Event->button.x,Event->button.y);
            break;
        }
        case SDL_BUTTON_MIDDLE: {
            OnMButtonUp(Event->button.x,Event->button.y);
            break;
        }
        }
        break;
    }

    case SDL_JOYAXISMOTION: {
        OnJoyAxis(Event->jaxis.which,Event->jaxis.axis,Event->jaxis.value);
        break;
    }

    case SDL_JOYBALLMOTION: {
        OnJoyBall(Event->jball.which,Event->jball.ball,Event->jball.xrel,Event->jball.yrel);
        break;
    }

    case SDL_JOYHATMOTION: {
        OnJoyHat(Event->jhat.which,Event->jhat.hat,Event->jhat.value);
        break;
    }
    case SDL_JOYBUTTONDOWN: {
        OnJoyButtonDown(Event->jbutton.which,Event->jbutton.button);
        break;
    }

    case SDL_JOYBUTTONUP: {
        OnJoyButtonUp(Event->jbutton.which,Event->jbutton.button);
        break;
    }

    case SDL_QUIT: {
        OnExit();
        break;
    }

    case SDL_SYSWMEVENT: {
        //Ignore
        break;
    }

    case SDL_VIDEORESIZE: {
        OnResize(Event->resize.w,Event->resize.h);
        break;
    }

    case SDL_VIDEOEXPOSE: {
        OnExpose();
        break;
    }

    default: {
        OnUser(Event->user.type,Event->user.code,Event->user.data1,Event->user.data2);
        break;
    }
    }
}
예제 #30
-1
파일: exa-base.cpp 프로젝트: exaexa/orthos
bool exaIsMouseButtonDown (unsigned char button)
{
	if (SDL_BUTTON (button) &mbuttondown) return true;
	return false;
}