Example #1
0
/* Mouse capability-change handler: */
void UIMouseHandler::sltMouseCapabilityChanged()
{
    /* If mouse supports absolute pointing and mouse-integration activated: */
    if (uisession()->isMouseSupportsAbsolute() && uisession()->isMouseIntegrated())
    {
        /* Release the mouse: */
        releaseMouse();
        /* Also we should switch guest mouse to the absolute mode: */
        mouse().PutMouseEventAbsolute(-1, -1, 0, 0, 0);
    }
#if 0 /* current team's decision is NOT to capture mouse on mouse-absolute mode loosing! */
    /* If mouse-integration deactivated or mouse doesn't supports absolute pointing: */
    else
    {
        /* Search for the machine-view focused now: */
        int iFocusedView = -1;
        QList<ulong> screenIds = m_views.keys();
        for (int i = 0; i < screenIds.size(); ++i)
        {
            if (m_views[screenIds[i]]->hasFocus())
            {
                iFocusedView = screenIds[i];
                break;
            }
        }
        /* If there is no focused view but views are present we will use the first one: */
        if (iFocusedView == -1 && !screenIds.isEmpty())
            iFocusedView = screenIds[0];
        /* Capture mouse using that view: */
        if (iFocusedView != -1)
            captureMouse(iFocusedView);
    }
#else /* but just to switch the guest mouse into relative mode! */
    /* If mouse-integration deactivated or mouse doesn't supports absolute pointing: */
    else
    {
Example #2
0
/**
 * Sets and releases the "pressed" visual state of the button
 * If press and release, activate (return true)
 */
bool WidgetButton::checkClick(int x, int y) {
	Point mouse(x,y);

	// Change the hover state
	hover = isWithin(pos, mouse);

	// Check the tooltip
	tip_new = checkTooltip(mouse);

	// disabled buttons can't be clicked;
	if (!enabled) return false;

	// main button already in use, new click not allowed
	if (inpt->lock[MAIN1]) return false;
	if (inpt->lock[ACCEPT]) return false;

	// main click released, so the button state goes back to unpressed
	if (pressed && !inpt->lock[MAIN1] && !inpt->lock[ACCEPT]) {
		pressed = false;
		return true;
	}

	pressed = false;

	// detect new click
	if (inpt->pressing[MAIN1]) {
		if (isWithin(pos, mouse)) {

			inpt->lock[MAIN1] = true;
			pressed = true;

		}
	}
	return false;

}
Example #3
0
//--------------------------------------------------------------
void petal::update(){
    
    vel = vel + frc;
	pos = pos + vel;
    
    if (bFly) {
        angle +=  rotateSpeed * vel.length() * diff;
        for (int i=0; i<4; i++) {
            ofApp * app = (ofApp *)ofGetAppPtr();
            ofPoint mouse(app->mouseX[i],app->mouseY[i]);
            if (!isNotTouch) {
           if (mouse.distance(pos)<40) {
                
                    bSelected = true;
                    break;
                }else{
                    bSelected = false;
                }
            }
        }
       
    }
    
}
void Mover::update(int x, int y) {

	// calculate acceleration based on mouse position and desired behavior
	ofPoint mouse(x, y);
	ofPoint diff;
	if(repel) { // repel from mouse
		diff = pos - mouse;
	}
	else { // attract toward mouse
		diff = mouse - pos;
	}
	diff.normalize(); // normalize to length of 1 as we only want direction
	diff = diff * 0.5; // shorten
	acc = diff;

	// update velocity using acceleration
	vel = vel + acc;
	vel.limit(20); // cap the speed to some certain amount
	
	// udpate position using velocity
	pos = pos + vel;
	
	// wrap around the screen
	if(pos.x <= -radius) { // off left
		pos.x = ofGetWidth()+radius; // go to right
	}
	if(pos.x >= ofGetWidth()+radius) { // off right
		pos.x = -radius; // go to left
	}
	if(pos.y <= -radius) { // off top
		pos.y = ofGetHeight()+radius; // go to bottom
	}
	if(pos.y >= ofGetHeight()+radius) { // off bottom
		pos.y = -radius; // go to top
	}
}
Example #5
0
bool isDoubleLbutton()//鼠标双击算法
{
	static int x,y;
	static int state=0;
	static int dTimeB=0;
	if (isLButton()&&state==0)
	{
		state=1;
		x=mouse(X);
		y=mouse(Y);
	}
	if ((!isLButton())&&state==1)
	{
		state=2;
		dTimeB=dTimeB+1000/getfps();
	}
	if ((!isLButton())&&state==2)
	{
		dTimeB=dTimeB+1000/getfps();
	}
	if (state==2&&isLButton())
	{
		x=mouse(X);
		y=mouse(Y);
		state=3;
		dTimeB=dTimeB+1000/getfps();
	}
	if (dTimeB>inf.mouse_speed&&state==2)
	{
		dTimeB=0;
		state=0;
	}
	if (dTimeB<=inf.mouse_speed&&state==3)
	{
		if(abs(mouse(X)-x)<4&&abs(mouse(Y)-y)<4)
		{
			state=0;
			dTimeB=0;
			return true;
		}
	}
	return false;
}
Example #6
0
int main(void)
{
   int gdriver = DETECT,x, gmode,lin,col,sta,stant,ml1[16],ml2[16],mc1[19],mc2[19];
   for(i=0;i<16;i++)
     for(j=0;j<19;j++)
	mt[j] [i]=0;
   i=0;j=0;
   initgraph(&gdriver, &gmode, "c:\\bc\\bgi");
   ml2[0]=65;
   for(lin=40;lin<=440;lin+=25,i++){
      line(95,lin,570,lin);
      if(lin<440){
	 ml1[i]=lin;
	 if(i>0)
	   ml2[i-1]=ml1[i];}}
   ml2[15]=440;
   i=0;
   for(col=95;col<=570;col=col+25,i++){
     line(col,40,col,440);
     if(col<570){
	mc1[i]=col;
	if(i>0)
	   mc2[i-1]=mc1[i];}}
   mc2[18]=570;
   mouse();
   while(!(kbhit())){
	stant=sta;
	lin=(linmouse()*8);
	col=(colmouse()*8);
	sta=status();
      if(lin>40 && lin<440){
	for(i=0;lin>ml1[i] ^ lin<ml2[i];i++);}
      if(col>95 && col<570 && col!=320 && col!=120 && col!=520){
	for(j=0;col>mc1[j] ^ col<mc2[j];j++);}
      if(lin>=ml1[i] && lin<=ml2[i] && col>=mc1[j] && col<=mc2[j] ){
	    if(stant==0 && sta==1){
	      desliga();
	      bar(mc1[j]+2,ml1[i]+2,mc2[j]-2,ml2[i]-2);
	    /*if(mt[j][i]==0)
	      botao(mc1[j]+4,ml1[i]+4,mc2[j]-3,ml2[i]-4,0);
	    else
	      botao(mc1[j]+4,ml1[i]+4,mc2[j]-3,ml2[i]-4,1);*/
	      mouse();
	      mt[j][i]=1;}
	    else if(stant==0 && sta==2){
		 setfillstyle( SOLID_FILL,0);
		 desliga();
		 bar(mc1[j]+2,ml1[i]+2,mc2[j]-2,ml2[i]-2);
		 mouse();
		 mt[j][i]=0;
		 setfillstyle( SOLID_FILL,15);}}

   }
   desliga();
   cleardevice();
   salva();
   cleardevice();
   sta=0;
   flushall();
   /*while(!(kbhit())){
      mudamouse(_DS,(unsigned) dorme1.imag,7,7);
      mouse();
      delay(500);
      mudamouse(_DS,(unsigned) dorme2.imag,7,7);
      mouse();
      delay(500);}*/
   closegraph();
   return 0;
}
Example #7
0
LRESULT CALLBACK InternalWndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT                 ps;         // Structure for the paint message
    POINT                       p = {0, 0}; // Translation point for the window's client region
    HRESULT                     hRet;

    switch (iMsg)
    {
        case WM_MOVE:
            // Make sure we're not moving to be minimized - because otherwise
            // our ratio varialbes (g_dwXRatio and g_dwYRatio) will end up
            // being 0, and once we hit CheckBoundries it divides by 0.
            if (!IsIconic(hwnd))
            {
                g_rcSrc.left = 0;
                g_rcSrc.right = g_sizex;
                g_rcSrc.top = 0;
                g_rcSrc.bottom = g_sizey;
                GetClientRect(hwnd, &g_rcDst);
                g_dwXRatio = (g_rcDst.right - g_rcDst.left) * 1000 /
                             (g_rcSrc.right - g_rcSrc.left);
                g_dwYRatio = (g_rcDst.bottom - g_rcDst.top) * 1000 /
                             (g_rcSrc.bottom - g_rcSrc.top);
                ClientToScreen(hwnd, &p);
                g_rcDst.left = p.x;
                g_rcDst.top = p.y;
                g_rcDst.bottom += p.y;
                g_rcDst.right += p.x;
                CheckBoundries();
            }
            else
                // Else, hide the overlay... just in case we can't do
                // destination color keying, this will pull the overlay
                // off of the screen for the user.
                if (g_pDDSOverlay && g_pDDSPrimary)
                    g_pDDSOverlay->UpdateOverlay(NULL, g_pDDSPrimary, NULL, DDOVER_HIDE, NULL);
            // Check to make sure our window exists before we tell it to
            // repaint. This will fail the first time (while the window is being created).
            if (hwnd)
            {
                InvalidateRect(hwnd, NULL, FALSE);
                UpdateWindow(hwnd);
            }
            return 0L;

        case WM_SIZE:
            // Another check for the minimization action.  This check is
            // quicker though...
            if (wParam != SIZE_MINIMIZED)
            {
                GetClientRect(hwnd, &g_rcDst);
                ClientToScreen(hwnd, &p);
                g_rcDst.left = p.x;
                g_rcDst.top = p.y;
                g_rcDst.bottom += p.y;
                g_rcDst.right += p.x;
                g_rcSrc.left = 0;
                g_rcSrc.right = g_sizex;
                g_rcSrc.top = 0;
                g_rcSrc.bottom = g_sizey;
                // Here we multiply by 1000 to preserve 3 decimal places in the
                // division opperation (we picked 1000 to be on the same order
                // of magnitude as the stretch factor for easier comparisons)
                g_dwXRatio = (g_rcDst.right - g_rcDst.left) * 1000 /
                             (g_rcSrc.right - g_rcSrc.left);
                g_dwYRatio = (g_rcDst.bottom - g_rcDst.top) * 1000 /
                             (g_rcSrc.bottom - g_rcSrc.top);
                CheckBoundries();
            }
            return 0L;

        case WM_PAINT:
            BeginPaint(hwnd, &ps);
            // Check the primary surface to see if it's lost - if so you can
            // pretty much bet that the other surfaces are also lost - thus
            // restore EVERYTHING!  If we got our surfaces stolen by a full
            // screen app - then we'll destroy our primary - and won't be able
            // to initialize it again. When we get our next paint message (the
            // full screen app closed for example) we'll want to try to reinit
            // the surfaces again - that's why there is a check for
            // g_pDDSPrimary == NULL.  The other option, is that our program
            // went through this process, could init the primary again, but it
            // couldn't init the overlay, that's why there's a third check for
            // g_pDDSOverlay == NULL.  Make sure that the check for
            // !g_pDDSPrimary is BEFORE the IsLost call - that way if the
            // pointer is NULL (ie. !g_pDDSPrimary is TRUE) - the compiler
            // won't try to evaluate the IsLost function (which, since the
            // g_pDDSPrimary surface is NULL, would be bad...).
            if (!g_pDDSPrimary || (g_pDDSPrimary->IsLost() != DD_OK) ||
                (g_pDDSOverlay == NULL))
            {
                DestroyOverlay();
                DestroyPrimary();
                if (DDPrimaryInit())
                    if (DDOverlayInit())
                        if (!DrawOverlay())
                            DestroyOverlay();
            }
            // UpdateOverlay is how we put the overlay on the screen.
            if (g_pDDSOverlay && g_pDDSPrimary && g_video->updating)
            {
                hRet = g_pDDSOverlay->UpdateOverlay(&g_rcSrc, g_pDDSPrimary,
                                                    &g_rcDst, g_OverlayFlags,
                                                    &g_OverlayFX);
#ifdef _DEBUG
                if(hRet != DD_OK) DisplayError("Can't update overlay", hRet);
#endif
            }
            EndPaint(hwnd, &ps);
            return 0L;

        // process mouse and keyboard events
        case WM_LBUTTONDOWN:    mouse(1, lParam); break;
        case WM_LBUTTONUP:      mouse(-1, lParam); break;
        case WM_RBUTTONDOWN:    mouse(2, lParam); break;
        case WM_RBUTTONUP:      mouse(-2, lParam); break;
        case WM_MBUTTONDOWN:    mouse(3, lParam); break;
        case WM_MBUTTONUP:      mouse(-3, lParam); break;
        case WM_CHAR:           g_video->on_key(wParam); break;

        case WM_DISPLAYCHANGE:  return 0L;

        case WM_DESTROY:
            // Now, shut down the window...
            PostQuitMessage(0);
            return 0L;
    }
    return g_pUserProc? g_pUserProc(hwnd, iMsg, wParam, lParam) : DefWindowProc(hwnd, iMsg, wParam, lParam);
}
Example #8
0
File: main.cpp Project: dquam/Bak3d
//------------------------------------------------------------------------------
LRESULT CALLBACK WindowProc( HWND   hWnd, 
                             UINT   msg, 
                             WPARAM wParam, 
                             LPARAM lParam )
{
    bool bRes = false;
    //
    // Pass the messages to our UI, first
    //
    if(!bRes) switch( msg )
    {
        case WM_PAINT:
            main::g_renderCnt++;
            break;
        case WM_CHAR:
        case WM_SYSCHAR:
            break;
        case WM_KEYUP:
            main::g_renderCnt++;
            switch( wParam )
            {
            case VK_CONTROL:
                main::g_bCtrl = false;
                break;
            case VK_SHIFT:
                main::g_bShift = false;
                break;
            }
            break;
        case WM_KEYDOWN:
            main::g_renderCnt++;
            switch( wParam )
            {
            case VK_CONTROL:
                main::g_bCtrl = true;
                break;
            case VK_SHIFT:
                main::g_bShift = true;
                break;
            default:
                keyboard_((unsigned char)wParam, main::g_curX, main::g_curY);
                break;
            }
            break;
        case WM_MOUSEWHEEL:
            mousewheel((short)HIWORD(wParam));
            break;
        case WM_LBUTTONDBLCLK:
            main::g_curX = LOWORD (lParam); main::g_curY = HIWORD (lParam);
            mouse(0, 2, LOWORD (lParam), HIWORD (lParam));
            break;
        case WM_LBUTTONDOWN:
            main::g_curX = LOWORD (lParam); main::g_curY = HIWORD (lParam);
            mouse(0, 0, LOWORD (lParam), HIWORD (lParam));
            break;
        case WM_LBUTTONUP:
            main::g_curX = LOWORD (lParam); main::g_curY = HIWORD (lParam);
            mouse(0, 1, LOWORD (lParam), HIWORD (lParam));
            break;
        case WM_RBUTTONDBLCLK:
            main::g_curX = LOWORD (lParam); main::g_curY = HIWORD (lParam);
            mouse(2, 2, LOWORD (lParam), HIWORD (lParam));
            break;
        case WM_RBUTTONDOWN:
            main::g_curX = LOWORD (lParam); main::g_curY = HIWORD (lParam);
            mouse(2, 0, LOWORD (lParam), HIWORD (lParam));
            break;
        case WM_RBUTTONUP:
            main::g_curX = LOWORD (lParam); main::g_curY = HIWORD (lParam);
            mouse(2, 1, LOWORD (lParam), HIWORD (lParam));
            break;
        case WM_MBUTTONDOWN:
            main::g_curX = LOWORD (lParam); main::g_curY = HIWORD (lParam);
            mouse(1, 0, LOWORD (lParam), HIWORD (lParam));
            break;
        case WM_MBUTTONUP:
            main::g_curX = LOWORD (lParam); main::g_curY = HIWORD (lParam);
            mouse(1, 1, LOWORD (lParam), HIWORD (lParam));
            break;
        case WM_MOUSEMOVE:
            main::g_curX = LOWORD (lParam); main::g_curY = HIWORD (lParam);
            motion(LOWORD (lParam), HIWORD (lParam));
            break;
        case WM_SIZE:
            g_winSz[0] = LOWORD(lParam);
            g_winSz[1] = HIWORD(lParam);
            reshape(LOWORD(lParam), HIWORD(lParam));
            break;
        case WM_CLOSE:
            PostQuitMessage(0);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            break;
    }
    return DefWindowProc( hWnd, msg, wParam, lParam );
}
Example #9
0
File: main.c Project: ysei/pdp6
int
main()
{
	SDL_Event ev;
	SDL_MouseButtonEvent *mbev;
	SDL_MouseMotionEvent *mmev;
	SDL_Surface *op_surf, *ind_surf, *extra_surf;
	SDL_Rect op_panel = { 0, 274, 1280, 210 };
	SDL_Rect ind_panel = { 0, 64, 1280, 210 };
	SDL_Rect extra_panel = { 0, 0, 1280, 210 };
	int i;
	Light *l;
	Switch *sw;

//	void testinst(Apr*);
//	testinst(&apr);

	if(SDL_Init(SDL_INIT_VIDEO) < 0){
error:
		fprintf(stderr, "error: %s\n", SDL_GetError());
		return 1;
	}
	screen = SDL_SetVideoMode(1280, 484, 32, SDL_DOUBLEBUF);
	if(screen == NULL)
		goto error;

	if((IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) != IMG_INIT_PNG){
		fprintf(stderr, "error: init SDL_Image: %s\n", IMG_GetError());
		return 1;
	}

	op_surf = IMG_Load("op_panel.png");
	if(op_surf == NULL){
		fprintf(stderr, "Couldn't load op_panel.png\n");
		return 1;
	}
	ind_surf = IMG_Load("ind_panel.png");
	if(ind_surf == NULL){
		fprintf(stderr, "Couldn't load ind_panel.png\n");
		return 1;
	}
	extra_surf = IMG_Load("extra_panel.png");
	if(extra_surf == NULL){
		fprintf(stderr, "Couldn't load extra_panel.png\n");
		return 1;
	}

	keysurf[0] = IMG_Load("key_n.png");
	if(keysurf[0] == NULL){
		fprintf(stderr, "Couldn't load key_n.png\n");
		return 1;
	}
	keysurf[1] = IMG_Load("key_d.png");
	if(keysurf[1] == NULL){
		fprintf(stderr, "Couldn't load key_d.png\n");
		return 1;
	}
	keysurf[2] = IMG_Load("key_u.png");
	if(keysurf[2] == NULL){
		fprintf(stderr, "Couldn't load key_u.png\n");
		return 1;
	}

	lampsurf[0] = IMG_Load("lamp_off.png");
	if(lampsurf[0] == NULL){
		fprintf(stderr, "Couldn't load lamp_off.png\n");
		return 1;
	}
	lampsurf[1] = IMG_Load("lamp_on.png");
	if(lampsurf[1] == NULL){
		fprintf(stderr, "Couldn't load lamp_on.png\n");
		return 1;
	}

	switchsurf[0] = IMG_Load("switch_d.png");
	if(switchsurf[0] == NULL){
		fprintf(stderr, "Couldn't load switch_d.png\n");
		return 1;
	}
	switchsurf[1] = IMG_Load("switch_u.png");
	if(switchsurf[1] == NULL){
		fprintf(stderr, "Couldn't load switch_u.png\n");
		return 1;
	}

	l = op_lights;
	ir_lght   = l; l += 18;
	mi_lght   = l; l += 36;
	pc_lght   = l; l += 18;
	ma_lght   = l; l += 18;
	pih_lght  = l; l += 7;
	pir_lght  = l; l += 7;
	pio_lght  = l; l += 7;
	rest_lght = l;
	sw = switches;
	data_sw      = sw; sw += 36;
	ma_sw        = sw; sw += 18;
	rest_sw      = sw; sw += 4;
	rim_maint_sw = sw;
	l = ind_lights;
	mb_lght   = l; l += 36;
	ar_lght   = l; l += 36;
	mq_lght   = l; l += 36;
	fe_lght   = l; l += 9;
	sc_lght   = l; l += 9;
	ff_lght   = l;
	l = extra_lights;
	membus_lght = l; l += 36;
	pr_lght     = l; l += 8;
	rlr_lght    = l; l += 8;
	rla_lght    = l;
	for(i = 0; i < nelem(keys); i++){
		keys[i].r.x += op_panel.x;
		keys[i].r.y += op_panel.y;
	}
	for(i = 0; i < nelem(op_lights); i++){
		op_lights[i].r.x += op_panel.x;
		op_lights[i].r.y += op_panel.y;
	}
	for(i = 0; i < nelem(ind_lights); i++){
		ind_lights[i].r.x += ind_panel.x;
		ind_lights[i].r.y += ind_panel.y;
	}
	for(i = 0; i < nelem(extra_lights); i++){
		extra_lights[i].r.x += extra_panel.x;
		extra_lights[i].r.y += extra_panel.y;
	}
	for(i = 0; i < nelem(switches)-1; i++){
		switches[i].r.x += op_panel.x;
		switches[i].r.y += op_panel.y;
	}
	rim_maint_sw->r.x += extra_panel.x;
	rim_maint_sw->r.y += extra_panel.y;

	initmem();
	inittty();
	memset(&apr, 0xff, sizeof apr);
	apr.extpulse = 0;

/*	int frm = 0;
	time_t tm, tm2;
	tm = time(nil);*/
	for(;;){
/*
		frm++;
		tm2 = time(nil);
		if((tm2 - tm) > 5){
			print("fps: %f\n", (float)frm/(tm2-tm));
			tm = tm2;
			frm = 0;
		}
*/
//		usleep(1000);

		while(SDL_PollEvent(&ev))
			switch(ev.type){
			case SDL_MOUSEMOTION:
				mmev = (SDL_MouseMotionEvent*)&ev;
				mouse(0, mmev->state,
				      mmev->x, mmev->y);
				break;
			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEBUTTONUP:
				mbev = (SDL_MouseButtonEvent*)&ev;
				mouse(mbev->button, mbev->state,
				      mbev->x, mbev->y);
				break;
			case SDL_QUIT:
				dumpmem();
				SDL_Quit();
				return 0;
			case SDL_USEREVENT:
				print("user\n");
				break;
			}
		setlights(apr.ir, ir_lght, 18);
		setlights(apr.mi, mi_lght, 36);
		setlights(apr.pc, pc_lght, 18);
		setlights(apr.ma, ma_lght, 18);
		setlights(apr.pih, pih_lght, 7);
		setlights(apr.pio, pio_lght, 7);
		setlights(apr.pir, pir_lght, 7);
		rest_lght[4].state = apr.run;
		rest_lght[5].state = apr.mc_stop;
		rest_lght[6].state = apr.pi_active;
		rest_lght[0].state = apr.sw_addr_stop   = rest_sw[0].state;
		rest_lght[1].state = apr.sw_repeat      = rest_sw[1].state;
		rest_lght[2].state = apr.sw_mem_disable = rest_sw[2].state;
		rest_lght[3].state = apr.sw_power       = rest_sw[3].state;
		apr.sw_rim_maint = rim_maint_sw->state;
		apr.data = getswitches(data_sw, 36);
		apr.mas = getswitches(ma_sw, 18);
		apr.key_start     = keys[0].state == 1;
		apr.key_readin    = keys[0].state == 2;
		apr.key_inst_cont = keys[1].state == 1;
		apr.key_mem_cont  = keys[1].state == 2;
		apr.key_inst_stop = keys[2].state == 1;
		apr.key_mem_stop  = keys[2].state == 2;
		apr.key_io_reset  = keys[3].state == 1;
		apr.key_exec      = keys[3].state == 2;
		apr.key_dep       = keys[4].state == 1;
		apr.key_dep_nxt   = keys[4].state == 2;
		apr.key_ex        = keys[5].state == 1;
		apr.key_ex_nxt    = keys[5].state == 2;
		apr.key_rd_off    = keys[6].state == 1;
		apr.key_rd_on     = keys[6].state == 2;
		apr.key_pt_rd     = keys[7].state == 1;
		apr.key_pt_wr     = keys[7].state == 2;

		setlights(apr.mb, mb_lght, 36);
		setlights(apr.ar, ar_lght, 36);
		setlights(apr.mq, mq_lght, 36);
		setlights(apr.fe, fe_lght, 9);
		setlights(apr.sc, sc_lght, 9);
		ff_lght[0].state = apr.key_ex_st;
		ff_lght[1].state = apr.key_ex_sync;
		ff_lght[2].state = apr.key_dep_st;
		ff_lght[3].state = apr.key_dep_sync;
		ff_lght[4].state = apr.key_rd_wr;
		ff_lght[5].state = apr.mc_rd;
		ff_lght[6].state = apr.mc_wr;
		ff_lght[7].state = apr.mc_rq;

		ff_lght[8].state = apr.if1a;
		ff_lght[9].state = apr.af0;
		ff_lght[10].state = apr.af3;
		ff_lght[11].state = apr.af3a;
		ff_lght[12].state = apr.et4_ar_pse;
		ff_lght[13].state = apr.f1a;
		ff_lght[14].state = apr.f4a;
		ff_lght[15].state = apr.f6a;

		ff_lght[16].state = apr.sf3;
		ff_lght[17].state = apr.sf5a;
		ff_lght[18].state = apr.sf7;
		ff_lght[19].state = apr.ar_com_cont;
		ff_lght[20].state = apr.blt_f0a;
		ff_lght[21].state = apr.blt_f3a;
		ff_lght[22].state = apr.blt_f5a;
		ff_lght[23].state = apr.iot_f0a;

		ff_lght[24].state = apr.fpf1;
		ff_lght[25].state = apr.fpf2;
		ff_lght[26].state = apr.faf1;
		ff_lght[27].state = apr.faf2;
		ff_lght[28].state = apr.faf3;
		ff_lght[29].state = apr.faf4;
		ff_lght[30].state = apr.fmf1;
		ff_lght[31].state = apr.fmf2;

		ff_lght[32].state = apr.fdf1;
		ff_lght[33].state = apr.fdf2;
		ff_lght[34].state = apr.ir & H6 && apr.mq & F1 && !apr.nrf3;
		ff_lght[35].state = apr.nrf1;
		ff_lght[36].state = apr.nrf2;
		ff_lght[37].state = apr.nrf3;
		ff_lght[38].state = apr.fsf1;
		ff_lght[39].state = apr.chf7;

		ff_lght[40].state = apr.dsf1;
		ff_lght[41].state = apr.dsf2;
		ff_lght[42].state = apr.dsf3;
		ff_lght[43].state = apr.dsf4;
		ff_lght[44].state = apr.dsf5;
		ff_lght[45].state = apr.dsf6;
		ff_lght[46].state = apr.dsf7;
		ff_lght[47].state = apr.dsf8;

		ff_lght[48].state = apr.dsf9;
		ff_lght[49].state = apr.msf1;
		ff_lght[50].state = apr.mpf1;
		ff_lght[51].state = apr.mpf2;
		ff_lght[52].state = apr.mc_split_cyc_sync;
		ff_lght[53].state = apr.mc_stop_sync;
		ff_lght[54].state = apr.shf1;
		ff_lght[55].state = apr.sc == 0777;

		ff_lght[56].state = apr.chf1;
		ff_lght[57].state = apr.chf2;
		ff_lght[58].state = apr.chf3;
		ff_lght[59].state = apr.chf4;
		ff_lght[60].state = apr.chf5;
		ff_lght[61].state = apr.chf6;
		ff_lght[62].state = apr.lcf1;
		ff_lght[63].state = apr.dcf1;

		ff_lght[64].state = apr.pi_ov;
		ff_lght[65].state = apr.pi_cyc;
		ff_lght[66].state = !!apr.pi_req;
		ff_lght[67].state = apr.iot_go;
		ff_lght[68].state = apr.a_long;
		ff_lght[69].state = apr.ma == apr.mas;
		ff_lght[70].state = apr.uuo_f1;
		ff_lght[71].state = apr.cpa_pdl_ov;

		ff_lght[72].state = !apr.ex_user;
		ff_lght[73].state = apr.cpa_illeg_op;
		ff_lght[74].state = apr.ex_ill_op;
		ff_lght[75].state = apr.ex_uuo_sync;
		ff_lght[76].state = apr.ex_pi_sync;
		ff_lght[77].state = apr.mq36;

		ff_lght[78].state = apr.key_rim_sbr;
		ff_lght[79].state = apr.ar_cry0_xor_cry1;
		ff_lght[80].state = apr.ar_cry0;
		ff_lght[81].state = apr.ar_cry1;
		ff_lght[82].state = apr.ar_ov_flag;
		ff_lght[83].state = apr.ar_cry0_flag;
		ff_lght[84].state = apr.ar_cry1_flag;
		ff_lght[85].state = apr.ar_pc_chg_flag;

		ff_lght[86].state = apr.cpa_non_exist_mem;
		ff_lght[87].state = apr.cpa_clock_enable;
		ff_lght[88].state = apr.cpa_clock_flag;
		ff_lght[89].state = apr.cpa_pc_chg_enable;
		ff_lght[90].state = apr.cpa_arov_enable;
		ff_lght[91].state = !!(apr.cpa_pia&4);
		ff_lght[92].state = !!(apr.cpa_pia&2);
		ff_lght[93].state = !!(apr.cpa_pia&1);

		setlights(membus0, membus_lght, 36);
		setlights(apr.pr, pr_lght, 8);
		setlights(apr.rlr, rlr_lght, 8);
		setlights(apr.rla, rla_lght, 8);

		SDL_BlitSurface(op_surf, NULL, screen, &op_panel);
		SDL_BlitSurface(ind_surf, NULL, screen, &ind_panel);
		SDL_BlitSurface(extra_surf, NULL, screen, &extra_panel);
		for(i = 0; i < nelem(keys); i++)
			SDL_BlitSurface(keys[i].surfs[keys[i].state],
			                NULL, screen, &keys[i].r);
		for(i = 0; i < nelem(op_lights); i++)
			SDL_BlitSurface(op_lights[i].surfs[op_lights[i].state && apr.sw_power],
			                NULL, screen, &op_lights[i].r);
		for(i = 0; i < nelem(ind_lights); i++)
			SDL_BlitSurface(ind_lights[i].surfs[ind_lights[i].state && apr.sw_power],
			                NULL, screen, &ind_lights[i].r);
		for(i = 0; i < nelem(extra_lights); i++)
			SDL_BlitSurface(extra_lights[i].surfs[extra_lights[i].state && apr.sw_power],
			                NULL, screen, &extra_lights[i].r);
		for(i = 0; i < nelem(switches); i++)
			SDL_BlitSurface(switches[i].surfs[switches[i].state],
			                NULL, screen, &switches[i].r);
		SDL_Flip(screen);
	}
}
Example #10
0
/**
 * Sets and releases the "pressed" visual state of the ListBox
 * If press and release, activate (return true)
 */
bool WidgetListBox::checkClick(int x, int y) {

	Point mouse(x, y);

	refresh();

	// check scroll wheel
	Rect scroll_area;
	scroll_area.x = rows[0].x;
	scroll_area.y = rows[0].y;
	scroll_area.w = rows[0].w;
	scroll_area.h = rows[0].h * static_cast<int>(rows.size());

	if (isWithinRect(scroll_area,mouse)) {
		inpt->lock_scroll = true;
		if (inpt->scroll_up) scrollUp();
		if (inpt->scroll_down) scrollDown();
	}
	else {
		inpt->lock_scroll = false;
	}

	// check ScrollBar clicks
	if (has_scroll_bar) {
		switch (scrollbar->checkClick(mouse.x,mouse.y)) {
			case 1:
				scrollUp();
				break;
			case 2:
				scrollDown();
				break;
			case 3:
				cursor = scrollbar->getValue();
				refresh();
				break;
			default:
				break;
		}
	}

	// main ListBox already in use, new click not allowed
	if (inpt->lock[MAIN1]) return false;

	// main click released, so the ListBox state goes back to unpressed
	if (pressed && !inpt->lock[MAIN1] && can_select) {
		pressed = false;

		for(unsigned i=0; i<rows.size(); i++) {
			if (i<items.size()) {
				if (isWithinRect(rows[i], mouse) && items[i+cursor].value != "") {
					// deselect other options if multi-select is disabled
					if (!multi_select) {
						for (unsigned j=0; j<items.size(); j++) {
							if (j!=i+cursor)
								items[j].selected = false;
						}
					}
					// activate upon release
					if (items[i+cursor].selected) {
						if (can_deselect) items[i+cursor].selected = false;
					}
					else {
						items[i+cursor].selected = true;
					}
					refresh();
					return true;
				}
			}
		}
	}

	pressed = false;

	// detect new click
	if (inpt->pressing[MAIN1]) {
		for (unsigned i=0; i<rows.size(); i++) {
			if (isWithinRect(rows[i], mouse)) {

				inpt->lock[MAIN1] = true;
				pressed = true;

			}
		}
	}
	return false;

}
Example #11
0
int mrutils::ColChooser::get() {
    if (!init_ && !(init_ = init())) {
        return -1;
    }

    if (building >= 0) build();
    if (active == -1) {
        active = 0;
        if (!data[0].choices.empty())
            data[0].highlight(0);
    }

    attrset(ATR_INPUT);

    int c;
    for (;;) {
        c = getch();

        if (enteringSearch) {
            switch (c) {
                case '/':
                case '\n':
                    enteringSearch = false;
                    printPrompt(name.c_str());
                    break;
                case '?':
                    enteringSearch = false;
                    data[active].applySearch = false;
                    data[active].resetSearch();
                    data[active].highlight( 0 );
                    break;
                case KEY_ESC:
                    enteringSearch = data[active].applySearch = false;
                    data[active].resetSearch();
                    data[active].highlight(0);
                    break;
                case KEY_BACKSPACE:
                case KEY_DELETE:
                    if (inputP == data[active].search) {
                        enteringSearch = data[active].applySearch = false;
                        data[active].resetSearch();
                        data[active].highlight(0);
                    } else {
                        *(--inputP) = '\0';
                        data[active].resetSearch();
                        data[active].highlight(0);
                        printPrompt(data[active].search,"/");
                    }
                    break;
                default:
                    *inputP++ = c; *inputP = '\0';
                    data[active].resetSearch();
                    data[active].highlight(0);
                    printPrompt(data[active].search,"/");
            }
        } else {
            if (c == 'q' || c == ';') break;
            switch(c) {
                case KEY_ESC:
                case '?':
                    if (data[active].applySearch) {
                        data[active].applySearch = false;
                        data[active].resetSearch();
                        data[active].highlight( 0 );
                    }
                    break;

                case 'o':
                    if (active == data.size()-1 && openFn != NULL) {
                        (openFn)(*this,openData);
                        redraw();
                        break;
                    } 
                case '\n': 
                {
                    if (!acceptReturn) break;

                    selectNumber = 0;
                    if (active == data.size()-1) {
                        return depth[active];
                    } else {
                        nextColumn();
                    }
                    break;
                }
                case KEY_MOUSE:
                    selectNumber = 0;

                    if ((c = mouse()) >= 0) {
                        if (!acceptReturn) break;
                        return c;
                    }
                    break;


                case 'L':
                    redraw();
                    break;

                case 'l':
                    selectNumber = 0;
                    nextColumn();
                    break;
                case 'h':
                    selectNumber = 0;
                    prevColumn();
                    break;
                case 'j':
                    selectNumber = 0;
                    data[active].highlightNext();
                    break;
                case 'k':
                    selectNumber = 0;
                    data[active].highlightPrev();
                    break;
                case '.': // repeat last command
                    if (lastCommand[0] == '\0') break;
                    strcpy(data[active].search, lastCommand);
                    printPrompt(data[active].search, "sent command ");
                    return -1;

                case 'x':
                case 'm':
                    if (active == data.size()-1) {
                        toggleTargetInternal(depth[active]);
                    }
                    break;

                case '>':
                    selectNumber = 0;
                    printPrompt(">");
                    enteringText = true;

                    wattrset((WINDOW*)chooserWin,ATR_INPUT);
                    getnstr(data[active].search,sizeof(data[active].search));
                    mrutils::compress(data[active].search);
                    strcpy(lastCommand, data[active].search);
                    if (data[active].search[0] == '\0') {
                        resetPrompt();
                        enteringText = false;
                        break;
                    }
                    enteringText = false;
                    return -1;

                case 'p':
                case 'u':
                    selectNumber = 0;
                    data[active].pageUp();
                    break;

                case 'd':
                case 'n':
                case ' ':
                    selectNumber = 0;
                    data[active].pageDn();
                    break;

                case '/':
                    inputP = data[active].search;
                    data[active].applySearch = true;
                    enteringSearch = true;
                    printPrompt("search for...");
                    break;

                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                case '0': 
                {
                    if (data[active].choices.empty()) break;

                    if (selectNumber == 0) inputP = data[active].search;
                    int tmp = 10 * selectNumber + (c - '0');

                    if (tmp >= data[active].choices.size() + startIndex) {
                        printPrompt(data[active].search);
                        break;
                    } else {
                        *inputP++ = c; *inputP = '\0';
                        selectNumber = tmp;
                        if (selectNumber >= data[active].head+startIndex 
                            && selectNumber <= data[active].tail+startIndex) 
                            data[active].highlight(selectNumber - startIndex, false, false);
                        printPrompt(data[active].search);
                    }
                    break;
                }

                case KEY_BACKSPACE:
                case KEY_DELETE:
                    if (data[active].choices.empty()) break;

                    if (selectNumber == 0) {
                        resetPrompt();
                        break;
                    }

                    selectNumber -= *(--inputP) - '0'; 
                    selectNumber /= 10; *inputP = '\0';

                    if (data[active].search[0] == '\0') {
                        resetPrompt();
                    } else {
                        if (selectNumber >= data[active].head 
                            && selectNumber <= data[active].tail) 
                            data[active].highlight(selectNumber, false, false);
                        printPrompt(data[active].search);
                    }
                    break;
                default:
                    resetPrompt();
            }
        }
    }

    data[active].search[0] = '\0';
    done();
    return -1;

}
Example #12
0
void InputBox::Update(float deltaTime)
{
	mSprite.Update(deltaTime);

	// Update caret info
	mCaret += deltaTime;
	if (mCaret > CARET_BLINK_RATE_SECONDS) {
		mCaret -= CARET_BLINK_RATE_SECONDS;
	}

	SVector2 mouse((float) Input_GetMouseScreenX(), (float) Input_GetMouseScreenY());
	// If a mouse click is detected this box is no longer selected. Below it checks if it is the one being clicked on
	if(Input_IsMousePressed(Mouse::LBUTTON))
	{
		mActive = mouse.x > (mPosition.x - 25) && mouse.x < mPosition.x + mWidth && mouse.y > (mPosition.y - 25) && mouse.y < mPosition.y + mHeight;
	}

	// If Active Capture Text
	if(mActive)
	{
		// Dont go over max length
		if(mTextPosition < mMaxLength)
		{		if (Input_IsKeyDown(Keys::LSHIFT) || Input_IsKeyDown(Keys::RSHIFT) )
				{
					if(Input_IsKeyPressed(Keys::A)) { mText[mTextPosition++] = 'A'; }
					if(Input_IsKeyPressed(Keys::B)) { mText[mTextPosition++] = 'B'; }
					if(Input_IsKeyPressed(Keys::C)) { mText[mTextPosition++] = 'C'; }
					if(Input_IsKeyPressed(Keys::D)) { mText[mTextPosition++] = 'D'; }
					if(Input_IsKeyPressed(Keys::E)) { mText[mTextPosition++] = 'E'; }
					if(Input_IsKeyPressed(Keys::F)) { mText[mTextPosition++] = 'F'; }
					if(Input_IsKeyPressed(Keys::G)) { mText[mTextPosition++] = 'G'; }
					if(Input_IsKeyPressed(Keys::H)) { mText[mTextPosition++] = 'H'; }
					if(Input_IsKeyPressed(Keys::I)) { mText[mTextPosition++] = 'I'; }
					if(Input_IsKeyPressed(Keys::J)) { mText[mTextPosition++] = 'J'; }
					if(Input_IsKeyPressed(Keys::K)) { mText[mTextPosition++] = 'K'; }
					if(Input_IsKeyPressed(Keys::L)) { mText[mTextPosition++] = 'L'; }
					if(Input_IsKeyPressed(Keys::M)) { mText[mTextPosition++] = 'M'; }
					if(Input_IsKeyPressed(Keys::N)) { mText[mTextPosition++] = 'N'; }
					if(Input_IsKeyPressed(Keys::O)) { mText[mTextPosition++] = 'O'; }
					if(Input_IsKeyPressed(Keys::P)) { mText[mTextPosition++] = 'P'; }
					if(Input_IsKeyPressed(Keys::Q)) { mText[mTextPosition++] = 'Q'; }
					if(Input_IsKeyPressed(Keys::R)) { mText[mTextPosition++] = 'R'; }
					if(Input_IsKeyPressed(Keys::S)) { mText[mTextPosition++] = 'S'; }
					if(Input_IsKeyPressed(Keys::T)) { mText[mTextPosition++] = 'T'; }
					if(Input_IsKeyPressed(Keys::U)) { mText[mTextPosition++] = 'U'; }
					if(Input_IsKeyPressed(Keys::V)) { mText[mTextPosition++] = 'V'; }
					if(Input_IsKeyPressed(Keys::W)) { mText[mTextPosition++] = 'W'; }
					if(Input_IsKeyPressed(Keys::X)) { mText[mTextPosition++] = 'X'; }
					if(Input_IsKeyPressed(Keys::Y)) { mText[mTextPosition++] = 'Y'; }
					if(Input_IsKeyPressed(Keys::Z)) { mText[mTextPosition++] = 'Z'; }

					if(Input_IsKeyPressed(Keys::SEMICOLON)) { mText[mTextPosition++] = ':'; }
					if(Input_IsKeyPressed(Keys::ONE)) { mText[mTextPosition++] = '!'; }
					if(Input_IsKeyPressed(Keys::TWO)) { mText[mTextPosition++] = '@'; }
					if(Input_IsKeyPressed(Keys::THREE)) { mText[mTextPosition++] = '#'; }
					if(Input_IsKeyPressed(Keys::FOUR)) { mText[mTextPosition++] = '$'; }
					if(Input_IsKeyPressed(Keys::FIVE)) { mText[mTextPosition++] = '%'; }
					if(Input_IsKeyPressed(Keys::SIX)) { mText[mTextPosition++] = '^'; }
					if(Input_IsKeyPressed(Keys::SEVEN)) { mText[mTextPosition++] = '&'; }
					if(Input_IsKeyPressed(Keys::EIGHT)) { mText[mTextPosition++] = '*'; }
					if(Input_IsKeyPressed(Keys::NINE)) { mText[mTextPosition++] = '('; }
					if(Input_IsKeyPressed(Keys::ZERO)) { mText[mTextPosition++] = ')'; }
					if(Input_IsKeyPressed(Keys::SLASH)) { mText[mTextPosition++] = '?'; }
					if(Input_IsKeyPressed(Keys::PERIOD)) { mText[mTextPosition++] = '>'; }
					if(Input_IsKeyPressed(Keys::COMMA)) { mText[mTextPosition++] = '<'; }
					if(Input_IsKeyPressed(Keys::APOSTROPHE)) { mText[mTextPosition++] = '"'; }
					if(Input_IsKeyPressed(Keys::GRAVE)) { mText[mTextPosition++] = '~'; }
					if(Input_IsKeyPressed(Keys::LBRACKET)) { mText[mTextPosition++] = '{'; }
					if(Input_IsKeyPressed(Keys::RBRACKET)) { mText[mTextPosition++] = '}'; }
				}
				else
				{
					if(Input_IsKeyPressed(Keys::A)) { mText[mTextPosition++] = 'a'; }
					if(Input_IsKeyPressed(Keys::B)) { mText[mTextPosition++] = 'b'; }
					if(Input_IsKeyPressed(Keys::C)) { mText[mTextPosition++] = 'c'; }
					if(Input_IsKeyPressed(Keys::D)) { mText[mTextPosition++] = 'd'; }
					if(Input_IsKeyPressed(Keys::E)) { mText[mTextPosition++] = 'e'; }
					if(Input_IsKeyPressed(Keys::F)) { mText[mTextPosition++] = 'f'; }
					if(Input_IsKeyPressed(Keys::G)) { mText[mTextPosition++] = 'g'; }
					if(Input_IsKeyPressed(Keys::H)) { mText[mTextPosition++] = 'h'; }
					if(Input_IsKeyPressed(Keys::I)) { mText[mTextPosition++] = 'i'; }
					if(Input_IsKeyPressed(Keys::J)) { mText[mTextPosition++] = 'j'; }
					if(Input_IsKeyPressed(Keys::K)) { mText[mTextPosition++] = 'k'; }
					if(Input_IsKeyPressed(Keys::L)) { mText[mTextPosition++] = 'l'; }
					if(Input_IsKeyPressed(Keys::M)) { mText[mTextPosition++] = 'm'; }
					if(Input_IsKeyPressed(Keys::N)) { mText[mTextPosition++] = 'n'; }
					if(Input_IsKeyPressed(Keys::O)) { mText[mTextPosition++] = 'o'; }
					if(Input_IsKeyPressed(Keys::P)) { mText[mTextPosition++] = 'p'; }
					if(Input_IsKeyPressed(Keys::Q)) { mText[mTextPosition++] = 'q'; }
					if(Input_IsKeyPressed(Keys::R)) { mText[mTextPosition++] = 'r'; }
					if(Input_IsKeyPressed(Keys::S)) { mText[mTextPosition++] = 's'; }
					if(Input_IsKeyPressed(Keys::T)) { mText[mTextPosition++] = 't'; }
					if(Input_IsKeyPressed(Keys::U)) { mText[mTextPosition++] = 'u'; }
					if(Input_IsKeyPressed(Keys::V)) { mText[mTextPosition++] = 'v'; }
					if(Input_IsKeyPressed(Keys::W)) { mText[mTextPosition++] = 'w'; }
					if(Input_IsKeyPressed(Keys::X)) { mText[mTextPosition++] = 'x'; }
					if(Input_IsKeyPressed(Keys::Y)) { mText[mTextPosition++] = 'y'; }
					if(Input_IsKeyPressed(Keys::Z)) { mText[mTextPosition++] = 'z'; }

					if(Input_IsKeyPressed(Keys::ZERO)) { mText[mTextPosition++] = '0'; }
					if(Input_IsKeyPressed(Keys::ONE)) { mText[mTextPosition++] = '1'; }
					if(Input_IsKeyPressed(Keys::TWO)) { mText[mTextPosition++] = '2'; }
					if(Input_IsKeyPressed(Keys::THREE)) { mText[mTextPosition++] = '3'; }
					if(Input_IsKeyPressed(Keys::FOUR)) { mText[mTextPosition++] = '4'; }
					if(Input_IsKeyPressed(Keys::FIVE)) { mText[mTextPosition++] = '5'; }
					if(Input_IsKeyPressed(Keys::SIX)) { mText[mTextPosition++] = '6'; }
					if(Input_IsKeyPressed(Keys::SEVEN)) { mText[mTextPosition++] = '7'; }
					if(Input_IsKeyPressed(Keys::EIGHT)) { mText[mTextPosition++] = '8'; }
					if(Input_IsKeyPressed(Keys::NINE)) { mText[mTextPosition++] = '9'; }
					if(Input_IsKeyPressed(Keys::SLASH)) { mText[mTextPosition++] = '/'; }
					if(Input_IsKeyPressed(Keys::PERIOD)) { mText[mTextPosition++] = '.'; }
					if(Input_IsKeyPressed(Keys::APOSTROPHE)) { mText[mTextPosition++] = '\''; }
					if(Input_IsKeyPressed(Keys::COMMA)) { mText[mTextPosition++] = ','; }
					if(Input_IsKeyPressed(Keys::MINUS)) { mText[mTextPosition++] = '-'; }
					if(Input_IsKeyPressed(Keys::EQUALS)) { mText[mTextPosition++] = '='; }
					if(Input_IsKeyPressed(Keys::SEMICOLON)) { mText[mTextPosition++] = ';'; }
					if(Input_IsKeyPressed(Keys::GRAVE)) { mText[mTextPosition++] = '`'; }
					if(Input_IsKeyPressed(Keys::LBRACKET)) { mText[mTextPosition++] = '['; }
					if(Input_IsKeyPressed(Keys::RBRACKET)) { mText[mTextPosition++] = ']'; }
				}

				if(Input_IsKeyPressed(Keys::SPACE)) { mText[mTextPosition++] = ' '; }
		}

		// Backspace
		if(mTextPosition > 0 && Input_IsKeyPressed(Keys::BACKSPACE))
		{
			mText[--mTextPosition] = '\0';
		}
	}
}
int main()
{
    Object* nameSpace;
    esInit(&nameSpace);

    Handle<es::Context> root(nameSpace);
    Handle<es::Stream> mouse(root->lookup("device/mouse"));
    Handle<es::Cursor> cursor(root->lookup("device/cursor"));
    Handle<es::Stream> framebuffer(root->lookup("device/framebuffer"));
    Handle<es::Pageable> pageable(framebuffer);
    TEST(pageable);

    fill(framebuffer, 255, 0, 0);
    fill(framebuffer, 0, 255, 0);
    fill(framebuffer, 0, 0, 255);
    fill(framebuffer, 255, 255, 255);

    pattern(framebuffer);
    cursor->show();

    for (int y = 0; y < 768; ++y)
    {
        cursor->setPosition(512, y);
    }

    for (int x = 0; x < 1024; ++x)
    {
        cursor->setPosition(x, 768 / 2);
    }

    for (int y = 0; y < 768; ++y)
    {
        cursor->setPosition(1023, y);
    }

    for (int x = 0; x < 1024; ++x)
    {
        cursor->setPosition(x, 767);
    }

    long long size;
    size = framebuffer->getSize();
    for (long long offset(0); offset < size; offset += 4096)
    {
        unsigned long pte = pageable->get(offset);
        esReport("%llx: %lx\n", offset, pte);
    }

    esReport("done.\n");    // for testing

    cursor->setPosition(1024 / 2, 768 / 2);
    for (;;)
    {
        s8 buffer[4];
        long count;
        int i;

        count = mouse->read(buffer, 4);
        if (4 <= count && (buffer[1] || buffer[2]))
        {
            cursor->move(buffer[1], -buffer[2]);
        }
        esSleep(10000000 / 60);
    }
}
Example #14
0
void Menu::passEvent(const sf::Event &event)
{
    if(!active) return;
    bool update = false;
    int deltaScroll = 0;
    if(event.type == sf::Event::KeyPressed)
    {
        switch(event.key.code)
        {
        case sf::Keyboard::Up:
            if(--marker < 0)
            {
                marker = menuList.size()-1;
                deltaScroll = menuList.size()-itemsVisible;
            }
            else if(marker < scrolled)
                deltaScroll = -1;
            update = true;
            break;
        case sf::Keyboard::Down:
            if(size_t(++marker) > menuList.size()-1)
            {
                deltaScroll = -menuList.size()+itemsVisible;
                marker = 0;
            }
            else if(marker-scrolled+1>itemsVisible)
                deltaScroll = 1;
            update = true;
            break;
        case sf::Keyboard::Return:
            clicked = marker;
            break;
        default:
            break;
        }
    }
    else if(event.type == sf::Event::MouseMoved)
    {
        sf::Vector2f mouse(event.mouseMove.x,event.mouseMove.y);
        sf::Vector2f mouseInView = rndrTxtre.mapPixelToCoords(sf::Vector2i(mouse) - sf::Vector2i(spr.getPosition()));
        if(spr.getGlobalBounds().contains(mouse) && mouseInView.y/(linePadding+characterSize) != marker && mouseInView.y/(linePadding+characterSize)-scrolled <= menuList.size())
        {
            marker = mouseInView.y/(linePadding+characterSize);
            update = true;
        }
    }
    else if(event.type == sf::Event::MouseButtonPressed)
    {
        sf::Vector2f mouse(event.mouseButton.x,event.mouseButton.y);
        sf::Vector2f mouseInView = rndrTxtre.mapPixelToCoords(sf::Vector2i(mouse) - sf::Vector2i(spr.getPosition()));
        if(spr.getGlobalBounds().contains(mouse) && mouseInView.y/(linePadding+characterSize) != marker && mouseInView.y/(linePadding+characterSize)-scrolled <= menuList.size())
        {
            clicked = marker = mouseInView.y/(linePadding+characterSize);
            update = true;
        }
    }
    else if(event.type == sf::Event::MouseWheelMoved)
    {
        if(-event.mouseWheel.delta+scrolled+itemsVisible <= int(menuList.size()) && -event.mouseWheel.delta+scrolled >= 0)
        {
            sf::Vector2f mouse(event.mouseWheel.x,event.mouseWheel.y);
            if(spr.getGlobalBounds().contains(mouse))
            {
                deltaScroll = -event.mouseWheel.delta;
                update = true;
                mouse.y += deltaScroll*(linePadding+characterSize);//adjust for the new scroll
                mouse -= spr.getPosition();
                mouse = rndrTxtre.mapPixelToCoords(static_cast<sf::Vector2i>(mouse));
                if(mouse.y/(linePadding+characterSize) != marker/* && mouse.y/(linePadding+characterSize)-scrolled <= itemsVisible*/)
                    marker = mouse.y/(linePadding+characterSize);
            }
        }
    }

    if(update)  updateTexture(deltaScroll);
}
Example #15
0
	int SDLApplication::run()
	{
		bool quit = false;
		SDL_Event event;

		m_totalTime = SDL_GetTicks();

		while (!quit)
		{
			while (SDL_PollEvent(&event))
			{
				switch (event.type)
				{
				case SDL_KEYDOWN:
					if (event.key.keysym.sym == SDLK_ESCAPE || event.key.keysym.sym == SDLK_q)
						quit = true;
					else if (event.key.keysym.sym == SDLK_UP || event.key.keysym.sym == SDLK_w)
						keyDown(KEY_MOVE_FORWARD);
					else if (event.key.keysym.sym == SDLK_DOWN || event.key.keysym.sym == SDLK_s)
						keyDown(KEY_MOVE_BACKWARD);
					else if (event.key.keysym.sym == SDLK_LEFT || event.key.keysym.sym == SDLK_a)
						keyDown(KEY_MOVE_LEFT);
					else if (event.key.keysym.sym == SDLK_RIGHT || event.key.keysym.sym == SDLK_d)
						keyDown(KEY_MOVE_RIGHT);
					else if (event.key.keysym.sym == SDLK_SPACE)
						keyDown(KEY_CONTINUE);
					break;
				case SDL_KEYUP:
					if (event.key.keysym.sym == SDLK_ESCAPE || event.key.keysym.sym == SDLK_q)
						quit = true;
					else if (event.key.keysym.sym == SDLK_UP || event.key.keysym.sym == SDLK_w)
						keyUp(KEY_MOVE_FORWARD);
					else if (event.key.keysym.sym == SDLK_DOWN || event.key.keysym.sym == SDLK_s)
						keyUp(KEY_MOVE_BACKWARD);
					else if (event.key.keysym.sym == SDLK_LEFT || event.key.keysym.sym == SDLK_a)
						keyUp(KEY_MOVE_LEFT);
					else if (event.key.keysym.sym == SDLK_RIGHT || event.key.keysym.sym == SDLK_d)
						keyUp(KEY_MOVE_RIGHT);
					else if (event.key.keysym.sym == SDLK_RETURN)
						keyUp(KEY_RESET_1);
					else if (event.key.keysym.sym == SDLK_c)
						keyUp(KEY_RESET_2);
					else if (event.key.keysym.sym == SDLK_h)
						keyUp(KEY_HELP);
					else if (event.key.keysym.sym == SDLK_SPACE)
						keyUp(KEY_CONTINUE);
					break;
				case SDL_MOUSEBUTTONDOWN:
					// this is to avoid a "jump" of the mouse delta after the first movement after a mouse click
					SDL_WarpMouse(m_width/2, m_height/2);
					break;
				case SDL_MOUSEMOTION:
					if (event.button.button == SDL_BUTTON_LEFT) {
						int middleX = int(m_width/2);
						int middleY = int(m_height/2);
						if (middleX != event.motion.x || middleY != event.motion.y)
						{
							mouse(KEY_MOUSE_LEFT, middleX - event.motion.x, middleY - event.motion.y);
							SDL_WarpMouse(middleX, middleY);
						}
					}

					break;
				case SDL_VIDEORESIZE:
					{
						Uint8 bpp = m_surface->format->BitsPerPixel;
						Uint32 flags = m_surface->flags;
						SDL_FreeSurface(m_surface);
						m_surface = SDL_SetVideoMode(event.resize.w, event.resize.h, bpp, flags);
						window_resized(event.resize.w, event.resize.h);
					}
					break;
				case SDL_QUIT:
					quit = true;
					break;
				}
			}

			int currentTime = SDL_GetTicks();
			float dt = float(currentTime - m_totalTime);

			if (!m_fixedTimeStep || dt >= m_targetElapsedTime * 1000) {
				m_totalTime = currentTime;
				if (dt > 0)
					update(dt);
			}

			draw();

			SDL_GL_SwapBuffers();
		}

		SDL_Quit();

		return 0;
	}
void Patch::drawPatch() {

    ofPoint mouse(ofGetMouseX(), ofGetMouseY());

    ofPushStyle();

    portsSize(20);

    if (max_y > 0.0f) {
        height = max_y - y + 10;
    }



    title_box = font.getBBox(name + " - " + "uid: " + ofToString(uid), 16,
            (int) (x + 5), (int) (y - 3));
    title_box.y -= 5;
    title_box.height += 10;

    if (title_box.inside(mouse)) {
        ofSetColor(ofColor::steelBlue);
    } else {
        ofSetColor(text_color);
    }


    font.draw(name + " - " + "uid: " + ofToString(uid), 16,
            (int) (x + 5), (int) (y - 3));

    address_box = font.getBBox(address.str, 16,
            (int) (x + 5), (int) (y + height + 14));
    address_box.y -= 5;
    address_box.height += 10;

    if (address_box.inside(mouse)) {
        ofSetColor(ofColor::steelBlue);
    } else {
        ofSetColor(text_color);
    }

    font.draw(address.str, 16,
              (int) (x + 5), (int) (y + height + 14));

    ofFill();

    if (status == UNRESPONSIVE) {
        ofSetColor(ofColor::gray);
    } else {
        ofSetColor(color);
        if (hover) {
            ofSetColor(color - ofColor(20));
        }
    }

    ofRect(x, y, width, height);

    drawPorts(20);


    ofPopStyle();
}
Example #17
0
/**
 * Sets and releases the "pressed" visual state of the ListBox
 * If press and release, activate (return true)
 */
bool WidgetListBox::checkClick(int x, int y) {

	Point mouse(x, y);

	refresh();

	// check scroll wheel
	SDL_Rect scroll_area;
	scroll_area.x = rows[0].x;
	scroll_area.y = rows[0].y;
	scroll_area.w = rows[0].w;
	scroll_area.h = rows[0].h * list_height;
	if (isWithin(scroll_area,mouse)) {
		if (inpt->scroll_up) {
			scrollUp();
			inpt->resetScroll();
		}
		if (inpt->scroll_down) {
			scrollDown();
			inpt->resetScroll();
		}
	} else {
		inpt->resetScroll();
	}

	// check ScrollBar clicks
	if (has_scroll_bar) {
		switch (scrollbar->checkClick(mouse.x,mouse.y)) {
			case 1:
				scrollUp();
				break;
			case 2:
				scrollDown();
				break;
			case 3:
				cursor = scrollbar->getValue();
				refresh();
				break;
			default:
				break;
		}
	}

	// main ListBox already in use, new click not allowed
	if (inpt->lock[MAIN1]) return false;

	// main click released, so the ListBox state goes back to unpressed
	if (pressed && !inpt->lock[MAIN1] && can_select) {
		pressed = false;

		for(int i=0; i<list_height; i++) {
			if (i<list_amount) {
				if (isWithin(rows[i], mouse) && values[i+cursor] != "") {
					// deselect other options if multi-select is disabled
					if (!multi_select) {
						for (int j=0; j<list_amount; j++) {
							if (j!=i+cursor)
								selected[j] = false;
						}
					}
					// activate upon release
					if (selected[i+cursor]) {
						if (can_deselect) selected[i+cursor] = false;
					} else {
						selected[i+cursor] = true;
					}
					refresh();
					return true;
				}
			}
		}
	}

	pressed = false;

	// detect new click
	if (inpt->pressing[MAIN1]) {
		for (int i=0; i<list_height;i++) {
			if (isWithin(rows[i], mouse)) {

				inpt->lock[MAIN1] = true;
				pressed = true;

			}
		}
	}
	return false;

}
Example #18
0
//--------------------------------------------------------------
void ofApp::draw(){
	
	ofEnableDepthTest();
    
    ofEnableLighting();
    pointLight.enable();
    pointLight2.enable();
    pointLight3.enable();

	cam.lookAt(camObjective);

	//Cam setup
	cam.begin();
	//cam.draw();
	//ofSetColor(0, 255, 0);
	//camObjective.draw();
	//ofDrawAxis(floorLimits);

	//Bezier line with evaluator
	ofFill();
    ofSetColor(pointLight.getDiffuseColor());
    //pointLight.draw();
    ofSetColor(pointLight2.getDiffuseColor());
    //pointLight2.draw();
    ofSetColor(pointLight3.getDiffuseColor());
    //pointLight3.draw();


	ofSetColor(ofColor::red);
	drawBezierLine();		
  
	//ofSetColor(ofColor::mediumPurple);
	//actorNode.draw();
	
	ofSetColor(ofColor::blueSteel);
	myHuman.draw();
		
	
	//daWorld

	ofSetColor(0, 15, 250);
	daWorld.draw();

	//Floor

	
	ofSetColor(0, 100, 25);
	floor.draw();

    /* Quad Floor
	glBegin(GL_QUADS);	
        glVertex3f( floorLimits, 0.0,  floorLimits);
		glVertex3f( floorLimits, 0.0, -floorLimits);
		glVertex3f(-floorLimits, 0.0, -floorLimits);
        glVertex3f(-floorLimits, 0.0,  floorLimits);
    glEnd();
	*/
	

	// draw bzNodes
	for(int i=0; i<kBezierPoints; i++) {
		ofSetColor(255, 128, 255);
		bzPoints[i].draw();
		if(i == 0 || i == 2){
			ofSetColor(255, 255, 0);
			ofVec3f v1 = bzNodes[i].getGlobalPosition();
			ofVec3f v2 = bzNodes[i+1].getGlobalPosition();
			ofLine(v1,v2);
		}
	}

	//glPushMatrix();

		
    //glPopMatrix();
	cam.end();

	
	ofSetColor(ofColor::gray);
	ofVec2f mouse(mouseX, mouseY);
	ofLine(nearestVertex, mouse);
	
	ofNoFill();
	ofSetColor(ofColor::yellow);
	ofSetLineWidth(2);
	ofCircle(nearestVertex, 4);
	ofSetLineWidth(1);

	// Test Mouse Picker
	/*ofVec3f cur2 = cam.worldToScreen(bzNodes[nearestIndex].getGlobalPosition());
	ofVec3f cur1 = cam.screenToWorld(ofVec3f(mouse.x,mouse.y, cur2.z));
	ofVec3f cur3 = cam.screenToWorld(ofVec3f(mouse.x,mouse.y, 1));	
		bool t = false;

		string s2 = string("Cursor") + 
		""+ ofToString(mouse)+
		"\n"+ ofToString(cur1)+
		"\n"+ ofToString(cur2)+
		"\n"+ ofToString(cur3);
	
	

	glDisable(GL_CULL_FACE);
	ofSetColor(255,0,0);
	ofDisableLighting();
	ofDrawBitmapString(s2, ofPoint(20, 40));
	glEnable(GL_CULL_FACE);*/

	

	//MSG

	string s = string("BZ Point: P") + 
		""+ ofToString(nearestIndex+1) + 
		"("+ ofToString(bzNodes[nearestIndex].getGlobalPosition()) + ")";

	ofDrawBitmapString(s, ofPoint(20, 20));	
}
Example #19
0
int main ( int argc, char ** argv )
{
	//glutInit ( &argc, argv );

	if(!glfwInit()) {
    fprintf( stderr, "Failed to initialize GLFW\n" );
    return EXIT_FAILURE;
  }
 
  

// 	GLenum err = glewInit();
//   if (GLEW_OK != err) {
//     fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
//   }
  
 

	if ( argc != 1 && argc != 6 ) {
		fprintf ( stderr, "usage : %s N dt diff visc force source\n", argv[0] );
		fprintf ( stderr, "where:\n" );\
		fprintf ( stderr, "\t N      : grid resolution\n" );
		fprintf ( stderr, "\t dt     : time step\n" );
		fprintf ( stderr, "\t diff   : diffusion rate of the density\n" );
		fprintf ( stderr, "\t visc   : viscosity of the fluid\n" );
		fprintf ( stderr, "\t force  : scales the mouse movement that generate a force\n" );
		fprintf ( stderr, "\t source : amount of density that will be deposited\n" );
		exit ( 1 );
	}

	if ( argc == 1 ) {
		N = 64;
		dt = 0.1f;
		diff = 0.0f;
		visc = 0.0f;
		force = 5.0f;
		source = 100.0f;
		fprintf ( stderr, "Using defaults : N=%d dt=%g diff=%g visc=%g force = %g source=%g\n",
			N, dt, diff, visc, force, source );
	} else {
		N = atoi(argv[1]);
		dt = atof(argv[2]);
		diff = atof(argv[3]);
		visc = atof(argv[4]);
		force = atof(argv[5]);
		source = atof(argv[6]);
	}

	printf ( "\n\nHow to use this demo:\n\n" );
	printf ( "\t Add densities with the right mouse button\n" );
	printf ( "\t Add velocities with the left mouse button and dragging the mouse\n" );
	printf ( "\t Toggle density/velocity display with the 'v' key\n" );
	printf ( "\t Clear the simulation by pressing the 'c' key\n" );
	printf ( "\t Quit by pressing the 'q' key\n" );

	dvel = 2;

	if ( !allocate_data () ) exit ( 1 );
	clear_data ();

	win_x = 512;
	win_y = 512;
	open_glut_window ();

	while(1) {
		idle_func();
		display_func();
		mouse();

    if (!glfwGetWindowParam(GLFW_OPENED)) {
      exit(0);
    }
	}

	glfwTerminate();

	//glutMainLoop ();

	exit ( 0 );
}
Example #20
0
//--------------------------------------------------------------
void ofApp::update(){

	pointLight.setOrientation(ofVec3f(0,0,180));
	pointLight2.setOrientation(ofVec3f(0,0,180));
	pointLight3.setOrientation(ofVec3f(0,0,180));

	pointLight.setPosition(
		cos(ofGetElapsedTimef()*.5)*floorLimits*0.7, 
		floorLimits/4, 
		sin(ofGetElapsedTimef()*.5)*floorLimits*0.7);
    pointLight2.setPosition(
		sin(ofGetElapsedTimef()*.5)*floorLimits*0.5, 
		floorLimits/3, 
		cos(ofGetElapsedTimef()*.5)*floorLimits*0.5);
    pointLight3.setPosition(
		floorLimits/2, 
		floorLimits/2, 
		-floorLimits/2);

	
		
	//Cam test
	//camObjective.setPosition(ofVec3f(0,(floorLimits/2)-ofGetElapsedTimef()*10,0));

	//Test random controlPoints
	/*circ++;

	if(circ%cicl == 0){
		for(int i=0; i<kBezierPoints; i++) {
			bzNodes[i].setPosition(ofVec3f(ofRandom(-floorLimits,floorLimits),20,ofRandom(-floorLimits,floorLimits)));
			ctrlpoints[i][0]=bzNodes[i].getX();
			ctrlpoints[i][1]=bzNodes[i].getY();
			ctrlpoints[i][2]=bzNodes[i].getZ();
		}
		glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlpoints[0][0]);
		glEnable(GL_MAP1_VERTEX_3);
	}
	if(circ > cicl){
		circ = 0;
	}*/

	//Update control points
	for(int i=0; i<kBezierPoints; i++) {
		ctrlpoints[i][0]=bzNodes[i].getX();
		ctrlpoints[i][1]=bzNodes[i].getY();
		ctrlpoints[i][2]=bzNodes[i].getZ();
	}

	actorNode.setPosition(bzNodes[0].getGlobalPosition());
	
	GLfloat b2 = (sin(ofGetElapsedTimef()*.5) + 1) / 2;
	GLfloat a1 = GLfloat(1.0-b2);
		
	//Draw actor node
	ofVec3f lastPosition = actorNode.getPosition();

	ofVec3f nextPosition = ofVec3f(
		bzNodes[0].getX()*a1*a1*a1 + bzNodes[1].getX()*3*a1*a1*b2 + bzNodes[2].getX()*3*a1*b2*b2 + bzNodes[3].getX()*b2*b2*b2,
		bzNodes[0].getY()*a1*a1*a1 + bzNodes[1].getY()*3*a1*a1*b2 + bzNodes[2].getY()*3*a1*b2*b2 + bzNodes[3].getY()*b2*b2*b2,
		bzNodes[0].getZ()*a1*a1*a1 + bzNodes[1].getZ()*3*a1*a1*b2 + bzNodes[2].getZ()*3*a1*b2*b2 + bzNodes[3].getZ()*b2*b2*b2);

	nextPosition.y = nextPosition.y + humanScale*2.25;
	actorNode.setPosition(nextPosition);
	myHuman.lookAt(nextPosition);
	myHuman.setPosition(nextPosition);
	myHuman.update();

	/*Update current steo and actor direction
	if(int(ofGetElapsedTimef())% 3 == 0 ){
		currentStep += actorDirection;
		
		if(0>currentStep || currentStep>bezierMovSubDiv){
			actorDirection*=-1;
		}
	}*/
	
	//Calculate and edit current bezir point
	ofVec2f mouse(mouseX, mouseY);
	for(int i = 0; i < kBezierPoints; i++) {
		ofVec3f cur = cam.worldToScreen(bzNodes[i].getGlobalPosition());
		bzPoints[i].setGlobalPosition(bzNodes[i].getGlobalPosition());
		float distance = cur.distance(mouse);
		if(i == 0 || distance < nearestDistance) {
			nearestDistance = distance;
			nearestVertex = cur;
			nearestIndex = i;
		}
	}
	

	
}
bool
nsXBLMouseEventHandler::EventMatched(nsIDOMEvent* aEvent)
{
  nsCOMPtr<nsIDOMMouseEvent> mouse(do_QueryInterface(aEvent));
  return mouse && mProtoHandler->MouseEventMatched(mouse);
}
Example #22
0
/* ---------- reset the mouse ---------- */
void resetmouse(void)
{
	segread(&sregs);
    mouse(0,0,0,0);
}
Example #23
0
int main(int argc, char * argv[])
{
    // Various settings and flags
    bool show_match_result = true;
    bool show_timings = false;
    bool learn_online = false;
    int num_classes = 0;
    int matching_threshold = 80;
    /// @todo Keys for changing these?
    cv::Size roi_size(200, 200);
    int learning_lower_bound = 90;
    int learning_upper_bound = 95;

    // Timers
    Timer extract_timer;
    Timer match_timer;

    // Initialize HighGUI
    help();
    cv::namedWindow("color");
    cv::namedWindow("normals");
    Mouse::start("color");

    // Initialize LINEMOD data structures
    cv::Ptr<cv::linemod::Detector> detector;
    std::string filename;
    if (argc == 1)
    {
        filename = "linemod_templates.yml";
        detector = cv::linemod::getDefaultLINEMOD();
    }
    else
    {
        detector = readLinemod(argv[1]);

        std::vector<cv::String> ids = detector->classIds();
        num_classes = detector->numClasses();
        printf("Loaded %s with %d classes and %d templates\n",
            argv[1], num_classes, detector->numTemplates());
        if (!ids.empty())
        {
            printf("Class ids:\n");
            std::copy(ids.begin(), ids.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
        }
    }
    int num_modalities = (int)detector->getModalities().size();

    // Open Kinect sensor
    cv::VideoCapture capture(cv::CAP_OPENNI2);
    if (!capture.isOpened())
    {
        printf("Could not open OpenNI-capable sensor\n");
        return -1;
    }
    capture.set(cv::CAP_PROP_OPENNI_REGISTRATION, 1);
    double focal_length = capture.get(cv::CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH);
    //printf("Focal length = %f\n", focal_length);

    // Main loop
    cv::Mat color, depth;
    for (;;)
    {
        // Capture next color/depth pair
        capture.grab();
        capture.retrieve(depth, cv::CAP_OPENNI_DEPTH_MAP);
        capture.retrieve(color, cv::CAP_OPENNI_BGR_IMAGE);

        std::vector<cv::Mat> sources;
        sources.push_back(color);
        sources.push_back(depth);
        cv::Mat display = color.clone();

        if (!learn_online)
        {
            cv::Point mouse(Mouse::x(), Mouse::y());
            int event = Mouse::event();

            // Compute ROI centered on current mouse location
            cv::Point roi_offset(roi_size.width / 2, roi_size.height / 2);
            cv::Point pt1 = mouse - roi_offset; // top left
            cv::Point pt2 = mouse + roi_offset; // bottom right

            if (event == cv::EVENT_RBUTTONDOWN)
            {
                // Compute object mask by subtracting the plane within the ROI
                std::vector<CvPoint> chain(4);
                chain[0] = pt1;
                chain[1] = cv::Point(pt2.x, pt1.y);
                chain[2] = pt2;
                chain[3] = cv::Point(pt1.x, pt2.y);
                cv::Mat mask;
                subtractPlane(depth, mask, chain, focal_length);

                cv::imshow("mask", mask);

                // Extract template
                std::string class_id = cv::format("class%d", num_classes);
                cv::Rect bb;
                extract_timer.start();
                int template_id = detector->addTemplate(sources, class_id, mask, &bb);
                extract_timer.stop();
                if (template_id != -1)
                {
                    printf("*** Added template (id %d) for new object class %d***\n",
                        template_id, num_classes);
                    //printf("Extracted at (%d, %d) size %dx%d\n", bb.x, bb.y, bb.width, bb.height);
                }

                ++num_classes;
            }

            // Draw ROI for display
            cv::rectangle(display, pt1, pt2, CV_RGB(0, 0, 0), 3);
            cv::rectangle(display, pt1, pt2, CV_RGB(255, 255, 0), 1);
        }

        // Perform matching
        std::vector<cv::linemod::Match> matches;
        std::vector<cv::String> class_ids;
        std::vector<cv::Mat> quantized_images;
        match_timer.start();
        detector->match(sources, (float)matching_threshold, matches, class_ids, quantized_images);
        match_timer.stop();

        int classes_visited = 0;
        std::set<std::string> visited;

        for (int i = 0; (i < (int)matches.size()) && (classes_visited < num_classes); ++i)
        {
            cv::linemod::Match m = matches[i];

            if (visited.insert(m.class_id).second)
            {
                ++classes_visited;

                if (show_match_result)
                {
                    printf("Similarity: %5.1f%%; x: %3d; y: %3d; class: %s; template: %3d\n",
                        m.similarity, m.x, m.y, m.class_id.c_str(), m.template_id);
                }

                // Draw matching template
                const std::vector<cv::linemod::Template>& templates = detector->getTemplates(m.class_id, m.template_id);
                drawResponse(templates, num_modalities, display, cv::Point(m.x, m.y), detector->getT(0));

                if (learn_online == true)
                {
                    /// @todo Online learning possibly broken by new gradient feature extraction,
                    /// which assumes an accurate object outline.

                    // Compute masks based on convex hull of matched template
                    cv::Mat color_mask, depth_mask;
                    std::vector<CvPoint> chain = maskfusionromTemplate(templates, num_modalities,
                        cv::Point(m.x, m.y), color.size(),
                        color_mask, display);
                    subtractPlane(depth, depth_mask, chain, focal_length);

                    cv::imshow("mask", depth_mask);

                    // If pretty sure (but not TOO sure), add new template
                    if (learning_lower_bound < m.similarity && m.similarity < learning_upper_bound)
                    {
                        extract_timer.start();
                        int template_id = detector->addTemplate(sources, m.class_id, depth_mask);
                        extract_timer.stop();
                        if (template_id != -1)
                        {
                            printf("*** Added template (id %d) for existing object class %s***\n",
                                template_id, m.class_id.c_str());
                        }
                    }
                }
            }
        }

        if (show_match_result && matches.empty())
            printf("No matches found...\n");
        if (show_timings)
        {
            printf("Training: %.2fs\n", extract_timer.time());
            printf("Matching: %.2fs\n", match_timer.time());
        }
        if (show_match_result || show_timings)
            printf("------------------------------------------------------------\n");

        cv::imshow("color", display);
        cv::imshow("normals", quantized_images[1]);

        cv::FileStorage fs;
        char key = (char)cv::waitKey(10);
        if (key == 'q')
            break;

        switch (key)
        {
        case 'h':
            help();
            break;
        case 'm':
            // toggle printing match result
            show_match_result = !show_match_result;
            printf("Show match result %s\n", show_match_result ? "ON" : "OFF");
            break;
        case 't':
            // toggle printing timings
            show_timings = !show_timings;
            printf("Show timings %s\n", show_timings ? "ON" : "OFF");
            break;
        case 'l':
            // toggle online learning
            learn_online = !learn_online;
            printf("Online learning %s\n", learn_online ? "ON" : "OFF");
            break;
        case '[':
            // decrement threshold
            matching_threshold = std::max(matching_threshold - 1, -100);
            printf("New threshold: %d\n", matching_threshold);
            break;
        case ']':
            // increment threshold
            matching_threshold = std::min(matching_threshold + 1, +100);
            printf("New threshold: %d\n", matching_threshold);
            break;
        case 'w':
            // write model to disk
            writeLinemod(detector, filename);
            printf("Wrote detector and templates to %s\n", filename.c_str());
            break;
        default:
            ;
        }
    }
    return 0;
}
Example #24
0
int main(int argc, char* argv[])
{
	sf::RenderWindow WINDOW(sf::VideoMode(1280, 720, 32), "Arctic", sf::Style::Close);
	WINDOW.SetFramerateLimit(60);

	Levels* levels;
	levels->setLevels();
	sf::Clock clock;
	float time = clock.GetElapsedTime();
	state = Ingame;
	prevState = Menu;

	/* Main Menu Buttons */
	BUTTON play(440, 200, "PLAY");
	BUTTON options(440, 320, "OPTIONS");
	BUTTON quit(440, 440, "QUIT");

	/* Pause Buttons */
	BUTTON resume(440, 200, "RESUME");
	BUTTON pauseOptions(440, 320, "OPTIONS");
	BUTTON quitToMenu(440, 440, "QUIT TO MENU");	

	/* Strings */
	STRING str("Arctic - Sprite Testing", 5, 2, sf::Color(255, 255, 255));

	while(WINDOW.IsOpened())
	{
		sf::Event event;
		sf::Vector2i mouse(WINDOW.GetInput().GetMouseX(), WINDOW.GetInput().GetMouseY());
		time = clock.GetElapsedTime();

		while(WINDOW.GetEvent(event))
		{
			switch(event.Type)
			{
			case sf::Event::Closed:
				WINDOW.Close();
				break;
			case sf::Event::KeyPressed:
				if(event.Key.Code == sf::Key::Escape)
				{
					if(state == Menu)
					{					
						WINDOW.Close();		
					}
					else if(state == Ingame)
					{
						state = Paused;
						prevState = Ingame;
					}
					else if(state == Options)
					{
						state = prevState;
						prevState = Options;
					}
					else if(state == Paused)
					{
						state = prevState;
						prevState = Paused;
					}
				}
				if(event.Key.Code == sf::Key::Space)
				{
					for(int i = 0; i < ice.size(); i++)
					{
						if(ice[i]->state != Ice::IceState::Rock)
						{
							ice[i]->state = Ice::IceState::Reg;
						}
					}
				}
				break;
				case sf::Event::MouseButtonReleased:
				if(event.MouseButton.Button == sf::Mouse::Button::Left)
				{
					if(state == Menu)
					{
						if(play.contains(mouse))
						{
							state = Ingame;
						}
						else if(options.contains(mouse))
						{
							state = Options;
							prevState = Menu;
						}
						else if(quit.contains(mouse))
						{
							WINDOW.Close();
						}
					}
					else if(state == Paused)
					{
						if(resume.contains(mouse))
						{
							state = Ingame;
						}
						else if(pauseOptions.contains(mouse))
						{
							state = Options;
							prevState = Paused;
						}
						else if(quitToMenu.contains(mouse))
						{
							state = Menu;
							prevState = Paused;
						}
					}
				}
				break;
			}
		}
		WINDOW.Clear(sf::Color(80, 80, 80, 0));
		/* DRAWING CODE */
		if(state == Ingame)
		{
			/* Tiles */
			levels->draw(currentLevel, WINDOW);			

			/* HUD Elements */
			str.Draw(WINDOW);
		}
		else if(state == Menu)
		{
			play.Draw(WINDOW);
			options.Draw(WINDOW);
			quit.Draw(WINDOW);
			play.Update(mouse);
			options.Update(mouse);
			quit.Update(mouse);
		}
		else if(state == Options)
		{

		}
		else if(state == Paused)
		{
			resume.Draw(WINDOW);
			pauseOptions.Draw(WINDOW);
			quitToMenu.Draw(WINDOW);
			resume.Update(mouse);
			pauseOptions.Update(mouse);
			quitToMenu.Update(mouse);
		}

		/* END OF DRAWING */
		WINDOW.Display();
	}
	return EXIT_SUCCESS;
}
Example #25
0
void Game::menu()
{	
	okno.setView(okno.getDefaultView());
	okno.setMouseCursorVisible(true);
	Text title("Nazwa Gry", font,80);
	Texture tekstura;
	tekstura.loadFromFile("data/ground.jpg");
	tekstura.setRepeated(true);

	Sprite background;
	background.setTexture(tekstura);
	background.setPosition(Vector2f(0, 0));
	background.setOrigin(Vector2f(0, 0));
	background.setTextureRect(IntRect(0, 0, 1280, 720));



	title.setColor(Color(138, 7, 7));
	title.setPosition(1280 / 2 - title.getGlobalBounds().width / 2, 10);
	
	const int ile = 2;

	Text tekst[ile];

	string str[] = { "PLAY","EXIT" };

	for (int i = 0; i<ile; i++)
	{
		tekst[i].setFont(font);
		tekst[i].setCharacterSize(50);

		tekst[i].setString(str[i]);
		tekst[i].setPosition((float)(1280 / 2.0 - tekst[i].getGlobalBounds().width / 2), (float)(250 + i * 120.0));
	}

	while (state == MENU)
	{
		Vector2f mouse(Mouse::getPosition(okno));

		Event event;
		while (okno.pollEvent(event))
		{
			
			if (event.type == Event::Closed || event.type == Event::KeyPressed &&
				event.key.code == Keyboard::Escape)
				state = END;

			
			else if (tekst[1].getGlobalBounds().contains(mouse) &&
				event.type == Event::MouseButtonReleased && event.key.code == Mouse::Left)
				state = END;

			else if (tekst[0].getGlobalBounds().contains(mouse) &&
				event.type == Event::MouseButtonReleased && event.key.code == Mouse::Left)
				state = GAME;

		}

		for (int i = 0; i<ile; i++)
			if (tekst[i].getGlobalBounds().contains(mouse))
			{
				tekst[i].setColor(Color(138, 7, 7));
			}
			else tekst[i].setColor(Color::White);



			okno.clear();
			okno.draw(background);
			okno.draw(title);

			for (int i = 0; i<ile; i++)
				okno.draw(tekst[i]);

			okno.display();
	}

}
Example #26
0
void Game::menu()
{
	Text title("Mechanized Techno Explorer",font,80);
	title.setStyle(Text::Bold);

	title.setPosition(1280/2-title.getGlobalBounds().width/2,20);

	const int ile = 2;

	Text tekst[ile];

	string str[] = {"Play","Exit"};
	for(int i=0;i<ile;i++)
	{
		tekst[i].setFont(font);
		tekst[i].setCharacterSize(65);

		tekst[i].setString(str[i]);
		tekst[i].setPosition(1280/2-tekst[i].getGlobalBounds().width/2,250+i*120);
	}

	while(state == MENU)
	{
		Vector2f mouse(Mouse::getPosition(window));
		Event event;

		while(window.pollEvent(event))
		{
			//Wciœniêcie ESC lub przycisk X
			if(event.type == Event::Closed || event.type == Event::KeyPressed &&
				event.key.code == Keyboard::Escape)
				state = END;
			
			//klikniêcie MENU                                        
			else if(tekst[0].getGlobalBounds().contains(mouse) &&
				event.type == Event::MouseButtonReleased && event.key.code == Mouse::Left)
			{
				state = GAME;
			}
			
			//klikniêcie EXIT
			else if(tekst[1].getGlobalBounds().contains(mouse) &&
				event.type == Event::MouseButtonReleased && event.key.code == Mouse::Left)
			{
				state = END;
			}
		}
		for(int i=0;i<ile;i++)
			if(tekst[i].getGlobalBounds().contains(mouse))
				tekst[i].setColor(Color::Cyan);
			else tekst[i].setColor(Color::White);
		
		window.clear();
		
		window.draw(title);
		for(int i=0;i<ile;i++)
			window.draw(tekst[i]);

		window.display();
	}
}
Example #27
0
void ofApp::mouseMoved(int x, int y){
    ofPoint mouse(x,y);
    for(auto &m :movers){
        m.setTarget(mouse, ofRandom(2));
    }
}
bool ofx2DFormMapping::mouseDragged(ofMouseEventArgs &args) {

	ofPoint mouse(args.x,args.y);

	for (unsigned int i = 0; i < shapes.size(); i++) {

		ofPtr<ofx2DMappingObject> obj = parent_projector->getMappingObject(i);

		for (unsigned int j = 0; j < shapes[i].polyline.size(); j++) {

			if (shapes[i].polyline[j].bBeingDragged == true){

				ofPoint zoomed_mouse = removeZoomRelativeOfDstRect(mouse);
				ofPoint zoomed_mapping_rect_dst_lefttop = removeZoomRelativeOfDstRect(mapping_rect_dst.getPosition());
				ofPoint zoomed_mapping_rect_dst_rightbottom = removeZoomRelativeOfDstRect(mapping_rect_dst.getPosition()+ofPoint(mapping_rect_dst.getWidth(), mapping_rect_dst.getHeight()));

				if(mouse.x < mapping_rect_dst.x+mapping_rect_dst.width) {
					if(mouse.x > mapping_rect_dst.x)
						shapes[i].polyline[j].x = zoomed_mouse.x;
					else
						shapes[i].polyline[j].x = zoomed_mapping_rect_dst_lefttop.x;
				}
				else {
					shapes[i].polyline[j].x = zoomed_mapping_rect_dst_rightbottom.x;
				}
				if(mouse.y < mapping_rect_dst.y+mapping_rect_dst.height) {
					if(mouse.y > mapping_rect_dst.y)
						shapes[i].polyline[j].y = zoomed_mouse.y;
					else
						shapes[i].polyline[j].y = zoomed_mapping_rect_dst_lefttop.y;
				}
				else {
					shapes[i].polyline[j].y = zoomed_mapping_rect_dst_rightbottom.y;
				}

				if(shapes[i].polyline.size() == 4) {

					if(ofPtr<ofx2DMappingShape> shape = std::dynamic_pointer_cast<ofx2DMappingShape>(obj)) {
						shape->dst[j].x = (shapes[i].polyline[j].x-mapping_rect_dst.x)/mapping_rect_dst.width;
						shape->dst[j].y = (shapes[i].polyline[j].y-mapping_rect_dst.y)/mapping_rect_dst.height;

						shape->polyline[j].x = shape->dst[j].x;
						shape->polyline[j].y = shape->dst[j].y;
					}

				}
				else {

					if(ofPtr<ofx2DMappingShape> shape = std::dynamic_pointer_cast<ofx2DMappingShape>(obj)) {
						shape->polyline[j].x = (shapes[i].polyline[j].x-mapping_rect_dst.x)/mapping_rect_dst.width;
						shape->polyline[j].y = (shapes[i].polyline[j].y-mapping_rect_dst.y)/mapping_rect_dst.height;

						ofRectangle bounding = shape->polyline.getBoundingBox();

						shape->dst[0].x = bounding.x;
						shape->dst[0].y = bounding.y;
						shape->dst[1].x = bounding.x+bounding.width;
						shape->dst[1].y = bounding.y;
						shape->dst[2].x = bounding.x+bounding.width;
						shape->dst[2].y = bounding.y+bounding.height;
						shape->dst[3].x = bounding.x;
						shape->dst[3].y = bounding.y+bounding.height;
					}
					if(ofPtr<ofx2DMappingPoint> point = std::dynamic_pointer_cast<ofx2DMappingPoint>(obj)) {
						//j should be 0
						point->pos.x = (shapes[i].polyline[j].x-mapping_rect_dst.x)/mapping_rect_dst.width;
						point->pos.y = (shapes[i].polyline[j].y-mapping_rect_dst.y)/mapping_rect_dst.height;

					}

				}

				obj->newpos = true;
				parent_list->getListItems().at(shapes.size()-1-i)->setBackgroundColor(ofColor(0,200,210));
//                    Visuals::get().reloadLinesFromRaw();
			}
		}

		if(ofPtr<ofx2DMappingContentShape> cshape = std::dynamic_pointer_cast<ofx2DMappingContentShape>(obj)) {

			for (unsigned int j = 0; j < shapes[i].src.size(); j++){
				if (shapes[i].src[j].bBeingDragged == true){
					if(mouse.x < mapping_rect_src.x+mapping_rect_src.width) {
						if(mouse.x > mapping_rect_src.x)
							shapes[i].src[j].x = mouse.x;
						else
							shapes[i].src[j].x = mapping_rect_src.x;
					}
					else {
						shapes[i].src[j].x = mapping_rect_src.x+mapping_rect_src.width;
					}
					if(mouse.y < mapping_rect_src.y+mapping_rect_src.height) {
						if(mouse.y > mapping_rect_src.y)
							shapes[i].src[j].y = mouse.y;
						else
							shapes[i].src[j].y = mapping_rect_src.y;
					}
					else {
						shapes[i].src[j].y = mapping_rect_src.y+mapping_rect_src.height;
					}
					cshape->src[j].x = (shapes[i].src[j].x-mapping_rect_src.x)/mapping_rect_src.width;
					cshape->src[j].y = (shapes[i].src[j].y-mapping_rect_src.y)/mapping_rect_src.height;

					switch(j) {
					case 0: {
						cshape->src[1].y = cshape->src[j].y;
						cshape->src[3].x = cshape->src[j].x;
						shapes[i].src[1].y = shapes[i].src[j].y;
						shapes[i].src[3].x = shapes[i].src[j].x;
						break;
					}
					case 1: {
						cshape->src[0].y = cshape->src[j].y;
						cshape->src[2].x = cshape->src[j].x;
						shapes[i].src[0].y = shapes[i].src[j].y;
						shapes[i].src[2].x = shapes[i].src[j].x;
						break;
					}
					case 2: {
						cshape->src[1].x = cshape->src[j].x;
						cshape->src[3].y = cshape->src[j].y;
						shapes[i].src[1].x = shapes[i].src[j].x;
						shapes[i].src[3].y = shapes[i].src[j].y;
						break;
					}
					case 3: {
						cshape->src[0].x = cshape->src[j].x;
						cshape->src[2].y = cshape->src[j].y;
						shapes[i].src[0].x = shapes[i].src[j].x;
						shapes[i].src[2].y = shapes[i].src[j].y;
						break;
					}
					default:
						break;
					}

					cshape->newpos = true;
				}
			}

		}

	}

	if(dragging_dst) {
		zoom_point_offset += mouse - last_mouse;
		last_mouse = mouse;
	}

	return ofxPanel::mouseDragged(args);
}
Example #29
0
//------------------------------------------------------------------------------
void ofApp::update()
{
    // first I create a vector (x,y,z) value for my mouse.
    // I will use this to prevent lines from being drawn around my cursor.
    ofVec3f mouse(ofGetMouseX(),ofGetMouseY());

    // Next I introduce a "jiggle" factor.
    // In this case, I'm just adding a tiny bit of random noise
    // to the x and y positions of each point.  Since I only allow a small
    // random variation and the random numbers are uniformly distributed,
    // they should stay in the same place (approximately) but jiggle a little.
    for(std::size_t i = 0; i < TOTAL_POINTS; ++i)
    {
        float jiggleFactor = 1;

        // here I measure the distance in pixels from the mouse
        // to the current point that I am working with in my array.
        float distance = points[i].distance(mouse);

        // here I scale my "jiggle" factor based on how close
        // the point is to my mouse.  
        if(distance < threshold)
        {
            jiggleFactor = ofMap(distance,0,threshold,100,1);
        }

        points[i].x += ofRandom(-.5,.5) * jiggleFactor;
        points[i].y += ofRandom(-.5,.5) * jiggleFactor;
    }

    // here I clear my ofVboMesh object (the object I use to draw everything
    // really really fast).
    mesh.clear();

    // I set the line mode.  Other possibilities include:

    //        OF_PRIMITIVE_TRIANGLES,
    //        OF_PRIMITIVE_TRIANGLE_STRIP,
    //        OF_PRIMITIVE_TRIANGLE_FAN,
    //        OF_PRIMITIVE_LINES,
    //        OF_PRIMITIVE_LINE_STRIP,
    //        OF_PRIMITIVE_LINE_LOOP,
    //        OF_PRIMITIVE_POINTS

    // Try some.

    mesh.setMode(OF_PRIMITIVE_LINES);

    // Here I cycle through all points with all other points.
    // If the objects are within "threshold" distance, then I draw
    // a line by adding two points to the mesh.  I also set
    // colors for that mesh point pair.  A "gradient" in the line
    // naturally occurs as the graphics card attempts to smoothly
    // transition the color between two points.
    for(size_t i = 0; i < TOTAL_POINTS; ++i)
    {
        for(size_t j = 0; j < TOTAL_POINTS; ++j)
        {
            // I don't compare a point to itself.
            if(i != j)
            {
                float distance = points[i].distance(points[j]);

                if(distance < threshold)
                {
                    float alpha = ofMap(distance, 0, threshold, 1, 0);

                    mesh.addVertex(points[i]);
                    mesh.addColor(ofFloatColor(colors[i],alpha));
                    mesh.addVertex(points[j]);
                    mesh.addColor(ofFloatColor(colors[j],alpha));
                }
            }
        }
    }

}
void Patch::drawPorts(float off_y) {

    ofPoint mouse(ofGetMouseX(), ofGetMouseY());

    port_hover = false;

    for (int i = 0; i < ports_in.size(); i++) {

        ofSetColor(ofColor::black);
        ofNoFill();
        Patch::font.draw(ports_in[i]->name, 16, (int) (x + 10),
                (int) (y + off_y + 20 * i));
        //ofRect(ports_in[i]->r);

        ofRectangle port_c = ports_in[i]->r;
        port_c.x = x;
        port_c.width = 30;

        ofRectangle socket = ports_in[i]->r;
        socket.x = x;
        socket.width = 5;

        ports_in[i]->cp.set(socket.x, socket.y + socket.height / 2);
        ofFill();
        if (port_c.inside(mouse)) {
            hover_port = ports_in[i];
            port_hover = true;
            line_start = ports_in[i]->cp;
            ofSetColor(ofColor::red);
        } else {
            ofSetColor(ofColor::orange);
        }
        ofRect(socket);
    }

    for (int i = 0; i < ports_out.size(); i++) {

        ofSetColor(ofColor::black);
        ofNoFill();
        font.draw(ports_out[i]->name, 16,
                (int) (x + width - ports_out[i]->r.width - 10),
                (int) (y + off_y + 20 * i));
        //ofRect(ports_out[i]->r);

        ofRectangle port_c = ports_out[i]->r;
        port_c.x = x + width - 30;
        port_c.width = 30;

        ofRectangle socket = ports_out[i]->r;
        socket.x = x + width - 5;
        socket.width = 5;

        ports_out[i]->cp.set(socket.x + socket.width,
                socket.y + socket.height / 2);
        ofFill();
        if (port_c.inside(mouse)) {
            hover_port = ports_out[i];
            port_hover = true;
            line_start = ports_out[i]->cp;
            ofSetColor(ofColor::red);
        } else {
            ofSetColor(ofColor::orange);
        }
        ofRect(socket);
    }
}