Code Search for Developers
 
 
  

mouse.cpp from NeoEngineNG at Krugle


Show mouse.cpp syntax highlighted

/***************************************************************************
                 mouse.cpp  -  Mouse and pointer auxiliary methods
                             -------------------
    begin                : Tue Apr 1 2003
    copyright            : (C) 2003 by Reality Rift Studios
    email                : mattias@realityrift.com
 ***************************************************************************

 The contents of this file are subject to the Mozilla Public License Version
 1.1 (the "License"); you may not use this file except in compliance with
 the License. You may obtain a copy of the License at 
 http://www.mozilla.org/MPL/

 Software distributed under the License is distributed on an "AS IS" basis,
 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 for the specific language governing rights and limitations under the
 License.

 The Original Code is the NeoEngine, NeoDevOpenGL, mouse.cpp

 The Initial Developer of the Original Code is Mattias Jansson.
 Portions created by Mattias Jansson are Copyright (C) 2003
 Reality Rift Studios. All Rights Reserved.

 ***************************************************************************/

#include "device.h"

#include <neoengine/logstream.h>

using namespace std;
using namespace NeoEngine;


namespace NeoOGL
{

void Device::SetMouseCursor( int iForm ){
#ifdef WIN32
	if (iForm==0)
		SetCursor(LoadCursor(NULL,IDC_CROSS));
	else
		SetCursor(LoadCursor(NULL,MAKEINTRESOURCE(iForm)));
	//m_iMouseShape=iForm;
	setMouseShape(iForm);
#endif
}

void Device::SetMousePos( int iX, int iY )
{
	if( iX < 0 )
		iX = 0;
	else if( iX >= (int)m_kWindow.m_kResolution.m_uiWidth )
		iX = m_kWindow.m_kResolution.m_uiWidth - 1;

	if( iY < 0 )
		iY = 0;
	else if( iY >= (int)m_kWindow.m_kResolution.m_uiHeight )
		iY = m_kWindow.m_kResolution.m_uiHeight - 1;

#ifdef WIN32

	POINT pt;

	pt.x = iX;
	pt.y = iY;

	ClientToScreen( (HWND)m_kWindow.m_hWnd, &pt );

	SetCursorPos( pt.x, pt.y );

#elif POSIX

	XWarpPointer( (Display*)m_kWindow.m_pDisplay, (Window)m_kWindow.m_Window, (Window)m_kWindow.m_Window, 0, 0, m_kWindow.m_kResolution.m_uiWidth, m_kWindow.m_kResolution.m_uiHeight, iX, iY );

#elif __APPLE__

	CGPoint pt;

	pt.x = iX;
	pt.y = iY;

	CGPostMouseEvent( pt, TRUE, 0, FALSE);

#else
#  error Platform not implemented
#endif

}


void Device::CaptureMouse( bool bCapture )
{
	if( bCapture )
	{
#ifdef WIN32

		POINT pt;

		pt.x = 0;
		pt.y = 0;

		ClientToScreen( (HWND)m_kWindow.m_hWnd, &pt );

		RECT rect;

		rect.top    = pt.x;
		rect.bottom = rect.top + m_kWindow.m_kResolution.m_uiHeight;
		rect.left   = pt.y;
		rect.right  = rect.left + m_kWindow.m_kResolution.m_uiWidth;

		ClipCursor( &rect );

#elif POSIX

		if( XGrabPointer( (Display*)m_kWindow.m_pDisplay, (Window)m_kWindow.m_Window, true, 0, GrabModeAsync, GrabModeAsync, (Window)m_kWindow.m_Window, None, CurrentTime ) != GrabSuccess )
			neolog << LogLevel( WARNING ) << "Unable to capture mouse!" << endl;

#elif __APPLE__

		neolog << LogLevel( ERROR ) << "[Device::CaptureMouse] capture not implemented" << endl;

#else
#  error Platform not implemented
#endif

	}
	else
	{

#ifdef WIN32

		ClipCursor( 0 );

#elif POSIX

		XUngrabPointer( (Display*)m_kWindow.m_pDisplay, CurrentTime );

#elif __APPLE__

		neolog << LogLevel( ERROR ) << "[Device::CaptureMouse] uncapture not implemented"  << endl;

#else
#  error Platform not implemented
#endif

	}
}


void Device::ShowCursor( bool bShow )
{
#ifdef WIN32

	::ShowCursor( bShow ? TRUE : FALSE );

#elif POSIX

	if( bShow )
		XDefineCursor( (Display*)m_kWindow.m_pDisplay, (Window)m_kWindow.m_Window, 0 );
	else
	{
		Cursor    kEmptyCursor;
		Pixmap    kEmptyPixmap;
		XColor    kBlack;
		XColor    kUnused;
		Colormap  kColormap;
		Display  *pkDisplay = (Display*)m_kWindow.m_pDisplay;
		Window    kWindow   = (Window)m_kWindow.m_Window;

		unsigned char aucEmptyCursorData[] = { 0,0,0,0,0,0,0,0 };

		kColormap    = DefaultColormap( pkDisplay, DefaultScreen( pkDisplay ) );

		XAllocNamedColor( pkDisplay, kColormap, "black", &kBlack, &kUnused );

		kEmptyPixmap = XCreateBitmapFromData( pkDisplay, kWindow, (const char*)aucEmptyCursorData, 8, 8 );
		kEmptyCursor = XCreatePixmapCursor( pkDisplay, kEmptyPixmap, kEmptyPixmap, &kBlack, &kBlack, 0, 0 );

		XDefineCursor( pkDisplay, kWindow, kEmptyCursor );
		XFreeCursor( pkDisplay, kEmptyCursor );

		if( kEmptyPixmap != None )
			XFreePixmap( pkDisplay, kEmptyPixmap );
	}

#elif __APPLE__
	//NOT IMPLEMENTED!
#else
#  error Platform not implemented
#endif
}


}; // namespace NeoOGL





See more files for this project here

NeoEngineNG

NeoenEngine NG (Next Generation) is the evolution of neoengine one,it\'s a different development from NeoEngine2, it\'s a direct inherits from NeoEngine one.\n

Project homepage: http://sourceforge.net/projects/neoengineng
Programming language(s): C,C++
License: other

  glew/
    bin/
      glew32.dll
      glewinfo.exe
      visualinfo.exe
    doc/
      advanced.html
      basic.html
      credits.html
      glew.css
      glew.html
      glew.png
      glx.txt
      glxew.html
      gpl.txt
      index.html
      install.html
      log.html
      new.png
      ogl_sm.jpg
      sgi.txt
      wglew.html
    include/
      GL/
    lib/
      glew32.lib
      glew32s.lib
  Makefile.am
  SConscript
  base.h
  begin.cpp
  buffermanager.cpp
  buffermanager.h
  bufferregion.cpp
  bufferregion.h
  callback.cpp
  clear.cpp
  close.cpp
  config.cpp
  device.cpp
  device.h
  end.cpp
  execute.cpp
  extensions.cpp
  extensions.h
  flip.cpp
  framebuffertarget.cpp
  framebuffertarget.h
  glext.h
  glue.cpp
  glxext.h
  initialize.cpp
  input.cpp
  light.cpp
  link.h
  mouse.cpp
  neodevopengl-static.dev
  neodevopengl.cbp
  neodevopengl.depend
  neodevopengl.dev
  neodevopengl.dsp
  neodevopengl.layout
  neodevopengl.vcproj
  op.h
  open.cpp
  pixelbuffer.cpp
  pixelbuffer.h
  pixelbuffertarget.cpp
  pixelbuffertarget.h
  polygonbuffer.cpp
  polygonstripbuffer.cpp
  program-glsl.cpp
  program-glsl.h
  projection.cpp
  query.cpp
  render.cpp
  renderqueue.cpp
  renderqueue.h
  rendertarget.cpp
  rendertarget.h
  resize.cpp
  shader.cpp
  shader.h
  shadowmap.cpp
  shadowmap.h
  shutdown.cpp
  statistics.cpp
  statistics.h
  stencilbuffer.cpp
  texture.cpp
  texture.h
  textureunit.cpp
  textureunit.h
  vertexbuffer-glsl.cpp
  vertexbuffer-glsl.h
  vertexbuffer.cpp
  vertexbuffer.h
  vertexbuffermanager-glsl.cpp
  vertexbuffermanager-glsl.h
  vertexbuffermanager-nobs.cpp
  vertexbuffermanager-nobs.h
  vertexbuffermanager.cpp
  vertexbuffermanager.h
  viewport.cpp
  wglext.h
  zbufferstate.cpp
  zbufferstate.h