Exemplo n.º 1
0
void CTriThreshold::OnMouseMove(UINT nFlags, CPoint point) 
{
	long NewPosition;
	//If they're holding down the left mouse button:
	if(mInDrag)
	{
		//It shouldn't be possible for the left button to be up and mInDrag
		//to be true...
		pgpAssert(nFlags & MK_LBUTTON);

		//Get the new position:
		NewPosition = point.x - (mTriangleWidth / 2);

		//Force it within legal values:
		if(NewPosition < 0)
			NewPosition = 0;
		if(NewPosition > mMaxPosition)
			NewPosition = mMaxPosition;

		MoveTriangle(NewPosition);
	}

	//Save the last known mouse position:
	mLastKnownMousePosition = point;
		
	CButton::OnMouseMove(nFlags, point);
}
Exemplo n.º 2
0
/*This handles the left-button down clicking.  Basically, if they click
 *within ten pixels of the current location, we move straight to the pointer.
 *If not, we move ten pixels closer to the pointer.  This behaviour is
 *modeled on the sliders.
 */
void CTriThreshold::OnLButtonDown(UINT nFlags, CPoint point) 
{
	long ClickPosition, ClickDelta, NewPosition;
	CWnd *oldCaptureWindow;

	//We should never receive a button_down message while we're dragging -
	//if so, the timer has probably gone awry:
	pgpAssert(!mInDrag);

	mClickPosition = point;
	//First, figure out where they clicked:
	ClickPosition = point.x - (mTriangleWidth / 2);

	//Figure out what the change was:
	ClickDelta = ClickPosition - mPosition;

	NewPosition = CalculateTrianglePositionFromDelta(ClickDelta, 
													 mClickMoveAmount);

	//Capture the mouse so that we still get the messages if the user moves
	//the mouse off the slider:
	//(We check oldCaptureWindow so that, if we get multiple clicks from a
	//click-and-hold, we don't make OURSELVES the old capture window, which
	//ends up with nothing else in the application getting mouse moves)
	oldCaptureWindow = SetCapture();
	if(oldCaptureWindow != this)
		mOldCaptureWindow = oldCaptureWindow;

	//If it's moved more than a couple of pixels, it's a "click."
	//If it's moved less, it's a "drag."
	if((abs(ClickDelta) <= DRAG_THRESHOLD_AMOUNT) && !mInClick)
	{
		mInDrag = TRUE;
		mInClick = FALSE;
	}
	else if(!mInClick) //It's a click; if mInClick, we've already done this
	{
		//This sets up a timer so that a "click and hold" can move the
		//slider multiple times.  We update every quarter second in this
		//case.  The LButtonUp does the KillTimer.
		SetTimer(TRIANGLE_TIMER_ID, MS_BETWEEN_CONSTANT_CLICKS, NULL);
		mInClick = TRUE;
		mInDrag = FALSE;
	}

	//Do the deed:
	MoveTriangle(NewPosition);
}
Exemplo n.º 3
0
//Main Methood entry point
int main(int argc, char * arg[]){

	//init everything - SDLm if it is nonzero we have a problem
	if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
		std::cout << "ERROR SDL_Init" << SDL_GetError() << std::endl;
		return -1;
	}

	//initialise the app window
	InitWindow(Window_Width, Window_Height, false);

	//Call out InitOpenGL Function
	initOpenGL();
	//Set out Viewport
	setViewport(Window_Width, Window_Height);


	SDL_Event event;


	double tFall = 0.0; //timer for the game loop for falling
	double tRotate = 0.0; //timer for the game loop for rotation



	// --- GAME LOOP START --- //
	while (running)
	{
		while (SDL_PollEvent(&event))
		{
			//get event type
			if (event.type == SDL_QUIT || event.type == SDL_WINDOWEVENT_CLOSE)
			{
				//set the running controller boolean to false
				running = false;
			}

			/*EXPERIMENTAL BEGGINS*/

			switch (event.type){
				/* Look for a keypress */
			case SDL_KEYDOWN:
				/* Check the SDLKey values and move change the coords */
				switch (event.key.keysym.sym){
				case SDLK_LEFT:
					TR2[0][3] -= 0.1f;
					TR2[1][3] -= 0.1f;
					TR2[2][3] -= 0.1f;
					break;
				case SDLK_RIGHT:
					TR2[0][3] += 0.1f;
					TR2[1][3] += 0.1f;
					TR2[2][3] += 0.1f;
					break;
				case SDLK_UP:
					TR2[1][4] += 0.1f;
					break;
				case SDLK_DOWN:
					TR2[1][4] -= 0.1f;
					break;

				default:
					break;
				}
			}


			/*EXPERIMENTAL ENDS*/

		} //event checking ends here


		if (tFall > fallSpeed)
		{
			MoveTriangle();
			tFall = 0.0;
		}
		tFall++;

		if (tRotate > rotateSpeed)
		{
			rotate = 1;
			tRotate = 0.0;
		}
		tRotate++;


		update();
		render();


	}

	CleanUp();
	return 0;

}