Example #1
0
TEST( Input, MouseInput )
{
    Input newInput = {};
    Input oldInput = {};

    newInput.buttons[BUTTON_LEFT] = true;

    EXPECT_TRUE( ButtonDown( &newInput, BUTTON_LEFT ) );
    EXPECT_FALSE( ButtonDown( &oldInput, BUTTON_RIGHT ) );
    EXPECT_TRUE( ButtonPressed( &newInput, &oldInput, BUTTON_LEFT ) );
    EXPECT_FALSE( ButtonReleased( &newInput, &oldInput, BUTTON_LEFT ) );

    oldInput.buttons[BUTTON_LEFT] = true;

    EXPECT_TRUE( ButtonDown( &newInput, BUTTON_LEFT ) );
    EXPECT_TRUE( ButtonDown( &oldInput, BUTTON_LEFT ) );
    EXPECT_FALSE( ButtonPressed( &newInput, &oldInput, BUTTON_LEFT ) );
    EXPECT_FALSE( ButtonReleased( &newInput, &oldInput, BUTTON_LEFT ) );

    newInput.buttons[BUTTON_LEFT] = false;

    EXPECT_FALSE( ButtonDown( &newInput, BUTTON_LEFT ) );
    EXPECT_TRUE( ButtonDown( &oldInput, BUTTON_LEFT ) );
    EXPECT_FALSE( ButtonPressed( &newInput, &oldInput, BUTTON_LEFT ) );
    EXPECT_TRUE( ButtonReleased( &newInput, &oldInput, BUTTON_LEFT ) );

    newInput.buttons[BUTTON_RIGHT] = true;
    
    EXPECT_TRUE( ButtonDown( &newInput, BUTTON_RIGHT ) );
    EXPECT_FALSE( ButtonDown( &oldInput, BUTTON_RIGHT ) );
    EXPECT_TRUE( ButtonPressed( &newInput, &oldInput, BUTTON_RIGHT ) );
    EXPECT_FALSE( ButtonReleased( &newInput, &oldInput, BUTTON_RIGHT ) );
}
Example #2
0
// Called every frame, before the events and after drawing, for you to update your object if necessary
// Return 1 (do not call again) or 0 (continue calling)
BOOL ExtObject::OnFrame()
{
	if(!remote.IsConnected())
		return 0;

	/*if(remote.RefreshState() == NO_CHANGE)
		return 0;*/
	remote.RefreshState();

	CalculateIrXY();

	//iterate through controls, set states
	vector<RunControl>::iterator i = controls.begin();
	for(; i!= controls.end(); i++)
	{
		float state = pRuntime->GetControlState(i->control.c_str(), i->player);
		state = max(state, ButtonDown(i->button));
		pRuntime->SetControlState(i->control.c_str(), 0, state);
		//debugLastAction = i->control;
	}

	for(int i = 0; i < BUTTONS; i++)
		UpdateButtonState(i);
	return 0;
}
Example #3
0
	bool SPKeyboard::ButtonJustDown(unsigned int key)
	{
		if(ButtonDown(key) && (keyState[key] != lastKeyState[key]))
		{
			return true;
		}

		return false;
	}
Example #4
0
	bool  SPMouse::ButtonJustDown(unsigned int key)
	{
		if(ButtonDown(key) && (mouseState.rgbButtons[key] != 
			lastMouseState.rgbButtons[key]))
		{
			return true;
		}

		return false;
	}
Example #5
0
LRESULT CSVGSymbolsDlg::OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	CPoint point;
	point.x = (short)LOWORD(lParam);
	point.y = (short)HIWORD(lParam);
	UINT nFlags = wParam;

	ButtonDown(nFlags, point);

	return 0;
}
Example #6
0
LRESULT CSVGElementListView::OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	CPoint point;
	point.x = (short)LOWORD(lParam);
	point.y = (short)HIWORD(lParam);
	UINT nFlags = wParam;

	ButtonDown(nFlags, point);

	::SendMessage(GetParent(), WM_COMMAND, MAKEWPARAM(GetWindowLong(GWL_ID), BN_CLICKED), (LPARAM)m_hWnd);

	return 0;
}
Example #7
0
void ExtObject::UpdateButtonState(const int button) {
	if(ButtonDown(button)) {
		if(ButtonStates[button] == WiiButtonState::UP) {
			ButtonStates[button] = WiiButtonState::JUST_PRESSED;
			return;
		}
		if(ButtonStates[button] == WiiButtonState::JUST_PRESSED) {
			ButtonStates[button] = WiiButtonState::DOWN;
			return;
		}
	} else {
		if(ButtonStates[button] == WiiButtonState::DOWN) {
			ButtonStates[button] = WiiButtonState::JUST_RELEASED;
			return;
		}
		if(ButtonStates[button] == WiiButtonState::JUST_RELEASED) {
			ButtonStates[button] = WiiButtonState::UP;
			return;
		}
	}
}
Example #8
0
int main(int argc, char *argv[])
{
	int n,
		show_days = 0,
		but_stat  = 0,
		microtm   = 0,
		running   = 0,
		force     = 0;
	time_t
		last_time = 0;
	char
		*geometry = NULL,
		*xdisplay = NULL;
	static int signals[] =
		{SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2, 0};
	XEvent Event;

	assert(sizeof(char) == 1);

	umask(077);
	do_opts(argc, argv, &show_days, &xdisplay, &geometry, &force);

	path_len = strlen(getenv("HOME")) + strlen("/.wmwork/worklog") + 1;
	if ((dirName = malloc(path_len)) == NULL || (logname = malloc(path_len)) == NULL || (lockname = malloc(path_len)) == NULL) {
		fprintf(stderr, "%s: cannot allocate memory for path variable\n", PACKAGE_NAME);
		fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno));
		exit(1);
	}
	snprintf(dirName,  path_len, "%s/.wmwork", getenv("HOME"));
	snprintf(logname,  path_len, "%s/worklog", dirName);
	snprintf(lockname, path_len, "%s/.#LOCK",  dirName);
	if (chdir(dirName) < 0) {
		if (errno == ENOENT) {
			if (mkdir(dirName, 0777)) {
				fprintf(stderr, "%s: cannot mkdir '%s'\n", PACKAGE_NAME, dirName);
				fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno));
				exit(1);
			}
			compat();
		} else {
			fprintf(stderr, "%s: cannot chdir into '%s'\n", PACKAGE_NAME, dirName);
			fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno));
			exit(1);
		}
	}

	for (n = 0; signals[n]; n++) {
		if (signal(signals[n], handler) == SIG_ERR) {
			fprintf(stderr, "%s: cannot set handler for signal %d\n", PACKAGE_NAME, signals[n]);
			fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno));
		}
	}

	make_lock(force);
	atexit(at_exit);
	read_log();
	current = first;

	initXwindow(xdisplay);
	createXBMfromXPM(wmwork_mask_bits, wmwork_master_xpm, 64, 64);
	openXwindow(argc, argv, wmwork_master_xpm, wmwork_mask_bits, 64, 64, geometry, NULL);
	AddMouseRegion(BUT_START,  5, 48, 22, 58);
	AddMouseRegion(BUT_PAUSE, 23, 48, 40, 58);
	AddMouseRegion(BUT_STOP,  41, 48, 58, 58);
	AddMouseRegion(BUT_PREV,   5, 33, 16, 43);
	AddMouseRegion(BUT_NEXT,  47, 33, 58, 43);
	drawTime(current->time, sess_time, microtm, show_days, running);
	drawProject(current->name);

	while (1) {
		last_time = now.tv_sec;
		gettimeofday(&now, &tz);
		if (running) {
			current->time += now.tv_sec - last_time;
			sess_time     += now.tv_sec - last_time;
			microtm        = now.tv_usec;
			drawTime(current->time, sess_time, microtm, show_days, running);
			RedrawWindow();
		}
		while (XPending(display)) {
			XNextEvent(display, &Event);
			switch (Event.type) {
			case Expose:
				RedrawWindow();
				break;
			case DestroyNotify:
				XCloseDisplay(display);
				exit(0);
			case ButtonPress:
				n = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
				switch (n) {
				case BUT_START:
				case BUT_PAUSE:
				case BUT_STOP:
				case BUT_PREV:
				case BUT_NEXT:
					ButtonDown(n);
					break;
				}
				but_stat = n;
				RedrawWindow();
				break;
			case ButtonRelease:
				n = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
				switch (but_stat) {
				case BUT_START:
				case BUT_PAUSE:
				case BUT_STOP:
				case BUT_PREV:
				case BUT_NEXT:
					ButtonUp(but_stat);
					break;
				}
				if (but_stat && n == but_stat) {
					switch (but_stat) {
					case BUT_START:
						running = 1;
						break;
					case BUT_PAUSE:
						running = 0;
						break;
					case BUT_STOP:
						write_log();
						write_record();
						running   = 0;
						sess_time = 0;
						break;
					case BUT_PREV:
						if (!running && sess_time == 0)
							current = current->prev;
						break;
					case BUT_NEXT:
						if (!running && sess_time == 0)
							current = current->next;
						break;
					}
					drawTime(current->time, sess_time, microtm, show_days, running);
					drawProject(current->name);
				}
				RedrawWindow();
				but_stat = 0;
				break;
			}
		}
		usleep(50000L);
		if (do_exit)
			exit(0);
	}
}
Example #9
0
void
yawmppp_routine (int argc, char **argv)
{
    int i, j;

    int but_stat;

    long currenttime;
    long lasttime;
    long waittime;
    long ppptime;
    int hour, minute;
    long timetolog;

    long ppp_send, ppp_sl = -1;
    long ppp_recv, ppp_rl = -1;
    long ppp_sbytes, ppp_rbytes;
    long ppp_osbytes, ppp_orbytes;

    struct stat st;

    pid_t stop_child = 0;
    pid_t start_child = 0;
    int status;

    int isonline = 0;

    XEvent Event;

    int speed_ind = 10;

    /* Initialize some stuff */

    get_statistics (active_interface, &ppp_rl, &ppp_sl,
		    &ppp_orbytes, &ppp_osbytes);
    if (caution>0)
      close_ppp();

    grab_isp_info(1);

    /* Open the display */

    createXBMfromXPM (dock_mask_bits, dockxpm_xpm,
		      dock_mask_width, dock_mask_height);

    openXwindow (argc, argv, dockxpm_xpm, dock_mask_bits,
		 dock_mask_width, dock_mask_height);

    /* V Button */
    AddMouseRegion (0, 35, 48, 46, 58);
    /* x Button */
    AddMouseRegion (1, 47, 48, 58, 58);

    /* < Button */
    AddMouseRegion (2, 5, 48, 16, 58);
    /* > Button */
    AddMouseRegion (3, 17, 48, 28, 58);
    /* ISP display */
    AddMouseRegion (4, 5, 6, 59, 43);

    starttime = 0;
    currenttime = time (0);
    ppptime = 0;
    but_stat = -1;
    waittime = 0;
    timetolog=0;

    /* 888k8 on bottom */
    copyXPMArea (ERR_SRC_X+28, ERR_SRC_Y+9, 25, 8, ERR_DEST_X, ERR_DEST_Y);

    DrawISPName ();

    while (1)
      {
	  lasttime = currenttime;
	  currenttime = time (0);

	  /* Check if any child has left the playground */
	  i = waitpid (0, &status, WNOHANG);
	  if (i == stop_child && stop_child != 0)
	    {

		starttime = 0;
		SetOffLED (LED_PPP_POWER);
		SetOffLED (LED_PPP_RX);
		SetOffLED (LED_PPP_TX);
		/* 888k8 on bottom */
		copyXPMArea (ERR_SRC_X+28, ERR_SRC_Y+9, 25, 8,
			     ERR_DEST_X, ERR_DEST_Y);
		RedrawWindow ();

		stop_child = 0;
	    }
	  if (i == start_child && start_child != 0)
	    {
		if (WIFEXITED (status))
		  {
		      if (WEXITSTATUS (status) == 10)
			{

			    starttime = 0;
			    /* 88k8 on bottom */
			    copyXPMArea (ERR_SRC_X+28, ERR_SRC_Y+9, 25, 8,
					 ERR_DEST_X, ERR_DEST_Y);
			    SetOffLED (LED_PPP_POWER);
			    DrawTime (0, 1);
			    RedrawWindow ();
			}
		      start_child = 0;
		  }
	    }

	  /* On-line detectie! 1x per second */

	  if (currenttime != lasttime)
	    {
		i = 0;

		if (stillonline (active_interface))
		  {
		      i = 1;
		      if (!starttime)
			{
			    starttime = currenttime;

			    if (stat (STAMP_FILE, &st) == 0)
				starttime = st.st_mtime;

			    SetOnLED (LED_PPP_POWER);
			    waittime = 0;

			    /* 88k8 on bottom */
			    copyXPMArea (ERR_SRC_X+28, ERR_SRC_Y+9, 25, 8,
					 ERR_DEST_X, ERR_DEST_Y);

			    if (IspData[current_isp].SpeedAction)
				DrawSpeedInd (IspData[current_isp].SpeedAction);

			    speed_ind = currenttime + 10;

			    RedrawWindow ();
			}
		  }
		if (!i && starttime)
		  {
		      starttime = 0;
		      SetErrLED (LED_PPP_POWER);
		      logconn.status=1;

		      /* Error */
		      copyXPMArea (ERR_SRC_X, ERR_SRC_Y+9, 25, 8,
				   ERR_DEST_X, ERR_DEST_Y);

		      if (IspData[current_isp].IfDownAction)
			  execCommand (IspData[current_isp].IfDownAction);

		      RedrawWindow ();
		  }
	    }

	  if (waittime && waittime <= currenttime)
	    {
		SetOffLED (LED_PPP_POWER);
		RedrawWindow ();
		waittime = 0;
	    }

	  if ((starttime)&&(!isonline)) {
	    isonline=1;

	    logconn.start=time(NULL);
	    logconn.status=0;
	    strcpy(logconn.longname,IspData[current_isp].LongName);
	    strcpy(logconn.shortname,IspData[current_isp].ShortName);
	    strcpy(logconn.user,IspData[current_isp].User);
	    strcpy(logconn.phone,IspData[current_isp].Phone);

	    if (!strlen(logconn.shortname))
	      strcpy(logconn.shortname,"empty");
	    if (!strlen(logconn.longname))
	      strcpy(logconn.longname,"empty");
	    if (!strlen(logconn.user))
	      strcpy(logconn.user,"empty");
	    if (!strlen(logconn.phone))
	      strcpy(logconn.phone,"empty");

	    make_guards();
	  }
	  if ((!starttime)&&(isonline)) {
	    isonline=0;
	    logconn.end=time(NULL);
	    write_log();
	    if (got_sched)
	      make_delayed_update();
	    if (caution>0)
	      close_ppp();
	  }

	  /* If we are on-line. Print the time we are */
	  if (starttime)
	    {
		i = currenttime - starttime;

		i /= TimerDivisor;

		if (TimerDivisor == 1)
		    if (i > 59 * 60 + 59)
			i /= 60;

		minute = i % 60;
		hour = (i / 60) % 100;
		i = hour * 100 + minute;

		DrawTime (i, currenttime % 2);
		/* We are online, so we can check for send/recv packets */

		get_statistics (active_interface, &ppp_recv, &ppp_send,
				&ppp_rbytes, &ppp_sbytes);
		if (caution>1)
		  close_ppp();

		if (ppp_send != ppp_sl)
		    SetOnLED (LED_PPP_TX);
		else
		    SetOffLED (LED_PPP_TX);

		if (ppp_recv != ppp_rl)
		    SetOnLED (LED_PPP_RX);
		else
		    SetOffLED (LED_PPP_RX);

		ppp_sl = ppp_send;
		ppp_rl = ppp_recv;

		/* Every five seconds we check to load on the line */

		if (currenttime - timetolog >= 0) {
		  timetolog=currenttime + 60;
		  make_guards();
		}

		if ((currenttime - ppptime >= 0) || (ppptime == 0))
		  {

		      ppptime = currenttime + updaterate;

		      ppp_history[PPP_STATS_HIS][0] = ppp_rbytes - ppp_orbytes;
		      ppp_history[PPP_STATS_HIS][1] = ppp_sbytes - ppp_osbytes;

		      ppp_orbytes = ppp_rbytes;
		      ppp_osbytes = ppp_sbytes;

		      DrawStats (54, 17, 5, 32);

		      for (j = 1; j < 55; j++)
			{
			    ppp_history[j - 1][0] = ppp_history[j][0];
			    ppp_history[j - 1][1] = ppp_history[j][1];
			}
		      if (currenttime > speed_ind)
			{
			    DrawLoadInd ((ppp_history[54][0] + ppp_history[54][1]) / updaterate);
			}
		  }

		RedrawWindow ();
	    }


	  while (XPending (display))
	    {
		XNextEvent (display, &Event);
		switch (Event.type)
		  {
		  case Expose:
		      RedrawWindow ();
		      break;
		  case DestroyNotify:
		      XCloseDisplay (display);
		      while (start_child | stop_child)
			{
			    i = waitpid (0, &status, WNOHANG);
			    if (i == stop_child)
				stop_child = 0;
			    if (i == start_child)
				start_child = 0;
			    usleep (50000l);
			}
		      exit (0);
		      break;
		  case ButtonPress:
		      i = CheckMouseRegion (Event.xbutton.x, Event.xbutton.y);
		      switch (i)
			{
			case 0:
			    ButtonDown (BUT_V);
			    break;
			case 1:
			    ButtonDown (BUT_X);
			    break;
			case 2:
			    ButtonDown (BUT_REW);
			    break;
			case 3:
			    ButtonDown (BUT_FF);
			    break;
			}
		      but_stat = i;

		      RedrawWindow ();
		      break;
		  case ButtonRelease:
		      i = CheckMouseRegion (Event.xbutton.x, Event.xbutton.y);
		      // Button but_stat omhoogdoen!
		      switch (but_stat)
			{
			case 0:
			    ButtonUp (BUT_V);
			    break;
			case 1:
			    ButtonUp (BUT_X);
			    break;
			case 2:
			    ButtonUp (BUT_REW);
			    break;
			case 3:
			    ButtonUp (BUT_FF);
			    break;
			}

		      if (i == but_stat && but_stat >= 0)
			{
			    switch (i)
			      {
			      case 0:
				  if (!starttime)
				    {
				      /* 888k8 */
				      copyXPMArea (ERR_SRC_X+28, ERR_SRC_Y+9,
						   25, 8,
						   ERR_DEST_X, ERR_DEST_Y);
					DrawTime (0, 1);
					start_child = execCommand (IspData[current_isp].StartAction);
					SetWaitLED (LED_PPP_POWER);
					waittime = ORANGE_LED_TIMEOUT + currenttime;
				    }

				  break;
			      case 1:
				  if (stop_child == 0)
				    {
					stop_child = execCommand (IspData[current_isp].StopAction);
				    }
				  break;
			      case 2:
				  if (!starttime)
				    {
					current_isp--;
					if (current_isp < 0)
					    current_isp = num_isps - 1;
					if (current_isp < 0)
					  current_isp=0;
					DrawISPName ();
				    }
				  break;
			      case 3:
				  if (!starttime)
				    {
					current_isp++;
					if (current_isp == num_isps)
					    current_isp = 0;
					DrawISPName ();
				    }
				  break;
			      case 4:
				if (Event.xbutton.button==Button1)
				  run_pref_app();
				else
				  run_log_app();
				break;
			      }
			}
		      RedrawWindow ();

		      but_stat = -1;
		      break;
		  default:
		      break;
		  }
	    }
	  usleep (50000L);
      }
}
Example #10
0
	bool SPJoystick::ButtonUp(unsigned int button)
	{
		return !ButtonDown(button);
	}