<commit_before>// ***************************************************************************
//
//   Generated automatically by genwrapper.
//   Please DO NOT EDIT this file!
//
// ***************************************************************************

#include <osgIntrospection/ReflectionMacros>
#include <osgIntrospection/TypedMethodInfo>
#include <osgIntrospection/StaticMethodInfo>
#include <osgIntrospection/Attributes>

#include <osg/GraphicsContext>
#include <osg/GraphicsThread>
#include <osg/State>
#include <osg/Vec4>

// Must undefine IN and OUT macros defined in Windows headers
#ifdef IN
#undef IN
#endif
#ifdef OUT
#undef OUT
#endif

TYPE_NAME_ALIAS(std::list< osg::Camera * >, osg::GraphicsContext::Cameras);

BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::GraphicsContext)
	I_BaseType(osg::Referenced);
	I_Method1(void, add, IN, osg::GraphicsOperation *, operation,
	          __void__add__GraphicsOperation_P1,
	          "Add operation to end of OperationQueue. ",
	          "");
	I_Method1(void, remove, IN, osg::GraphicsOperation *, operation,
	          __void__remove__GraphicsOperation_P1,
	          "Remove operation from OperationQueue. ",
	          "");
	I_Method1(void, remove, IN, const std::string &, name,
	          __void__remove__C5_std_string_R1,
	          "Remove named operation from OperationQueue. ",
	          "");
	I_Method0(void, removeAllOperations,
	          __void__removeAllOperations,
	          "Remove all operations from OperationQueue. ",
	          "");
	I_Method0(void, runOperations,
	          __void__runOperations,
	          "Run the operations. ",
	          "");
	I_Method0(const osg::GraphicsContext::Traits *, getTraits,
	          __C5_Traits_P1__getTraits,
	          "Get the traits of the GraphicsContext. ",
	          "");
	I_Method0(bool, valid,
	          __bool__valid,
	          "Return whether a valid and usable GraphicsContext has been created. ",
	          "");
	I_Method1(void, setState, IN, osg::State *, state,
	          __void__setState__State_P1,
	          "Set the State object which tracks the current OpenGL state for this graphics context. ",
	          "");
	I_Method0(osg::State *, getState,
	          __State_P1__getState,
	          "Get the State object which tracks the current OpenGL state for this graphics context. ",
	          "");
	I_Method0(const osg::State *, getState,
	          __C5_State_P1__getState,
	          "Get the const State object which tracks the current OpenGL state for this graphics context. ",
	          "");
	I_Method1(void, setClearColor, IN, const osg::Vec4 &, color,
	          __void__setClearColor__C5_Vec4_R1,
	          "Sets the clear color. ",
	          "");
	I_Method0(const osg::Vec4 &, getClearColor,
	          __C5_Vec4_R1__getClearColor,
	          "Returns the clear color. ",
	          "");
	I_Method1(void, setClearMask, IN, GLbitfield, mask,
	          __void__setClearMask__GLbitfield,
	          "Set the clear mask used in glClear(. ",
	          ".). Defaults to GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT. ");
	I_Method0(GLbitfield, getClearMask,
	          __GLbitfield__getClearMask,
	          "Get the clear mask. ",
	          "");
	I_Method0(void, clear,
	          __void__clear,
	          "Do an OpenGL clear of the full graphics context/window. ",
	          "Note, must only be called from a thread with this context current. ");
	I_Method0(bool, realize,
	          __bool__realize,
	          "Realise the GraphicsContext. ",
	          "");
	I_MethodWithDefaults1(void, close, IN, bool, callCloseImplementation, true,
	                      __void__close__bool,
	                      "close the graphics context. ",
	                      "close(bool) stops any associated graphics threads, releases the contextID for the GraphicsContext then optional calls closeImplementation() to do the actual deletion of the graphics. This call is made optional as there are times when the graphics context has already been deleted externally and only the OSG side of the its data need to be closed down. ");
	I_Method0(void, swapBuffers,
	          __void__swapBuffers,
	          "swap the front and back buffers. ",
	          "");
	I_Method0(bool, isRealized,
	          __bool__isRealized,
	          "Return true if the graphics context has been realised and is ready to use. ",
	          "");
	I_Method0(void, makeCurrent,
	          __void__makeCurrent,
	          "Make this graphics context current. ",
	          "Implementated by first aquiring a lock of the GraphicsContext mutex, and then doing a call to makeCurrentImplementation(). ");
	I_Method1(void, makeContextCurrent, IN, osg::GraphicsContext *, readContext,
	          __void__makeContextCurrent__GraphicsContext_P1,
	          "Make this graphics context current with specified read context. ",
	          "Implementated by first aquiring a lock of the GraphicsContext mutex, and then doing a call to makeContextCurrentImplementation(). ");
	I_Method0(void, releaseContext,
	          __void__releaseContext,
	          "Release the graphics context by unlocking the GraphicsContext mutex. ",
	          "");
	I_Method0(bool, isCurrent,
	          __bool__isCurrent,
	          "Return true if the current thread has this OpenGL graphics context. ",
	          "");
	I_Method1(void, bindPBufferToTexture, IN, GLenum, buffer,
	          __void__bindPBufferToTexture__GLenum,
	          "Bind the graphics context to associated texture. ",
	          "");
	I_Method0(void, createGraphicsThread,
	          __void__createGraphicsThread,
	          "Create a graphics thread to the graphics context, so that the thread handles all OpenGL operations. ",
	          "");
	I_Method1(void, setGraphicsThread, IN, osg::GraphicsThread *, gt,
	          __void__setGraphicsThread__GraphicsThread_P1,
	          "Assign a graphics thread to the graphics context, so that the thread handles all OpenGL operations. ",
	          "");
	I_Method0(osg::GraphicsThread *, getGraphicsThread,
	          __GraphicsThread_P1__getGraphicsThread,
	          "Get the graphics thread assigned the graphics context. ",
	          "");
	I_Method0(const osg::GraphicsThread *, getGraphicsThread,
	          __C5_GraphicsThread_P1__getGraphicsThread,
	          "Get the const graphics thread assigned the graphics context. ",
	          "");
	I_Method0(bool, realizeImplementation,
	          __bool__realizeImplementation,
	          "Realise the GraphicsContext implementation, Pure virtual - must be implemented by concrate implementations of GraphicsContext. ",
	          "");
	I_Method0(bool, isRealizedImplementation,
	          __bool__isRealizedImplementation,
	          "Return true if the graphics context has been realised, and is ready to use, implementation. ",
	          "Pure virtual - must be implemented by concrate implementations of GraphicsContext. ");
	I_Method0(void, closeImplementation,
	          __void__closeImplementation,
	          "Close the graphics context implementation. ",
	          "Pure virtual - must be implemented by concrate implementations of GraphicsContext. ");
	I_Method0(void, makeCurrentImplementation,
	          __void__makeCurrentImplementation,
	          "Make this graphics context current implementation. ",
	          "Pure virtual - must be implemented by concrate implementations of GraphicsContext. ");
	I_Method1(void, makeContextCurrentImplementation, IN, osg::GraphicsContext *, readContext,
	          __void__makeContextCurrentImplementation__GraphicsContext_P1,
	          "Make this graphics context current with specified read context implementation. ",
	          "Pure virtual - must be implemented by concrate implementations of GraphicsContext. ");
	I_Method1(void, bindPBufferToTextureImplementation, IN, GLenum, buffer,
	          __void__bindPBufferToTextureImplementation__GLenum,
	          "Pure virtual, Bind the graphics context to associated texture implementation. ",
	          "Pure virtual - must be implemented by concrate implementations of GraphicsContext. ");
	I_Method0(void, swapBuffersImplementation,
	          __void__swapBuffersImplementation,
	          "Swap the front and back buffers implementation. ",
	          "Pure virtual - must be implemented by Concrate implementations of GraphicsContext. ");
	I_Method4(void, resized, IN, int, x, IN, int, y, IN, int, width, IN, int, height,
	          __void__resized__int__int__int__int,
	          "resized method should be called when the underlying window has been resized and the GraphicsWindow and associated Cameras must be updated to keep in sync with the new size. ",
	          "");
	I_Method0(osg::GraphicsContext::Cameras &, getCameras,
	          __Cameras_R1__getCameras,
	          "Get the the list of cameras associated with this graphics context. ",
	          "");
	I_Method0(const osg::GraphicsContext::Cameras &, getCameras,
	          __C5_Cameras_R1__getCameras,
	          "Get the the const list of cameras associated with this graphics context. ",
	          "");
	I_StaticMethod1(void, setWindowingSystemInterface, IN, osg::GraphicsContext::WindowingSystemInterface *, wsInterface,
	                __void__setWindowingSystemInterface__WindowingSystemInterface_P1_S,
	                "Set the querry the windowing system for screens and create graphics context - this functor should be supplied by the windows toolkit. ",
	                "");
	I_StaticMethod0(osg::GraphicsContext::WindowingSystemInterface *, getWindowingSystemInterface,
	                __WindowingSystemInterface_P1__getWindowingSystemInterface_S,
	                "Get the WindowingSystemInterface. ",
	                "");
	I_StaticMethod1(osg::GraphicsContext *, createGraphicsContext, IN, osg::GraphicsContext::Traits *, traits,
	                __GraphicsContext_P1__createGraphicsContext__Traits_P1_S,
	                "Create a graphics context for a specified set of traits. ",
	                "");
	I_StaticMethod0(unsigned int, createNewContextID,
	                __unsigned_int__createNewContextID_S,
	                "Create a contextID for a new graphics context, this contextID is used to set up the osg::State associate with context. ",
	                "Automatically increments the usage count of the contextID to 1. ");
	I_StaticMethod1(void, incrementContextIDUsageCount, IN, unsigned int, contextID,
	                __void__incrementContextIDUsageCount__unsigned_int_S,
	                "Increment the usage count associate with a contextID. ",
	                "The usage count speficies how many graphics contexts a specific contextID is shared between. ");
	I_StaticMethod1(void, decrementContextIDUsageCount, IN, unsigned int, contextID,
	                __void__decrementContextIDUsageCount__unsigned_int_S,
	                "Decrement the usage count associate with a contextID. ",
	                "Once the contextID goes to 0 the contextID is then free to be reused. ");
	I_SimpleProperty(osg::GraphicsContext::Cameras &, Cameras,
	                 __Cameras_R1__getCameras,
	                 0);
	I_SimpleProperty(const osg::Vec4 &, ClearColor,
	                 __C5_Vec4_R1__getClearColor,
	                 __void__setClearColor__C5_Vec4_R1);
	I_SimpleProperty(GLbitfield, ClearMask,
	                 __GLbitfield__getClearMask,
	                 __void__setClearMask__GLbitfield);
	I_SimpleProperty(osg::GraphicsThread *, GraphicsThread,
	                 __GraphicsThread_P1__getGraphicsThread,
	                 __void__setGraphicsThread__GraphicsThread_P1);
	I_SimpleProperty(osg::State *, State,
	                 __State_P1__getState,
	                 __void__setState__State_P1);
	I_SimpleProperty(const osg::GraphicsContext::Traits *, Traits,
	                 __C5_Traits_P1__getTraits,
	                 0);
END_REFLECTOR

BEGIN_VALUE_REFLECTOR(osg::GraphicsContext::ScreenIdentifier)
	I_Constructor0(____ScreenIdentifier,
	               "",
	               "");
	I_Constructor1(IN, unsigned int, in_screenNum,
	               ____ScreenIdentifier__unsigned_int,
	               "",
	               "");
	I_Constructor3(IN, const std::string &, in_hostName, IN, unsigned int, in_displayNum, IN, unsigned int, in_screenNum,
	               ____ScreenIdentifier__C5_std_string_R1__unsigned_int__unsigned_int,
	               "",
	               "");
	I_Method0(std::string, displayName,
	          __std_string__displayName,
	          "",
	          "");
	I_PublicMemberProperty(std::string, hostName);
	I_PublicMemberProperty(unsigned int, displayNum);
	I_PublicMemberProperty(unsigned int, screenNum);
END_REFLECTOR

BEGIN_OBJECT_REFLECTOR(osg::GraphicsContext::Traits)
	I_BaseType(osg::Referenced);
	I_BaseType(osg::GraphicsContext::ScreenIdentifier);
	I_Constructor0(____Traits,
	               "",
	               "");
	I_PublicMemberProperty(int, x);
	I_PublicMemberProperty(int, y);
	I_PublicMemberProperty(int, width);
	I_PublicMemberProperty(int, height);
	I_PublicMemberProperty(std::string, windowName);
	I_PublicMemberProperty(bool, windowDecoration);
	I_PublicMemberProperty(bool, supportsResize);
	I_PublicMemberProperty(unsigned int, red);
	I_PublicMemberProperty(unsigned int, blue);
	I_PublicMemberProperty(unsigned int, green);
	I_PublicMemberProperty(unsigned int, alpha);
	I_PublicMemberProperty(unsigned int, depth);
	I_PublicMemberProperty(unsigned int, stencil);
	I_PublicMemberProperty(unsigned int, sampleBuffers);
	I_PublicMemberProperty(unsigned int, samples);
	I_PublicMemberProperty(bool, pbuffer);
	I_PublicMemberProperty(bool, quadBufferStereo);
	I_PublicMemberProperty(bool, doubleBuffer);
	I_PublicMemberProperty(GLenum, target);
	I_PublicMemberProperty(unsigned int, level);
	I_PublicMemberProperty(unsigned int, face);
	I_PublicMemberProperty(unsigned int, mipMapGeneration);
	I_PublicMemberProperty(osg::GraphicsContext *, sharedContext);
END_REFLECTOR

BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::GraphicsContext::WindowingSystemInterface)
	I_BaseType(osg::Referenced);
	I_Constructor0(____WindowingSystemInterface,
	               "",
	               "");
	I_MethodWithDefaults1(unsigned int, getNumScreens, IN, const osg::GraphicsContext::ScreenIdentifier &, screenIdentifier, osg::GraphicsContext::ScreenIdentifier(),
	                      __unsigned_int__getNumScreens__C5_ScreenIdentifier_R1,
	                      "",
	                      "");
	I_Method3(void, getScreenResolution, IN, const osg::GraphicsContext::ScreenIdentifier &, screenIdentifier, IN, unsigned int &, width, IN, unsigned int &, height,
	          __void__getScreenResolution__C5_ScreenIdentifier_R1__unsigned_int_R1__unsigned_int_R1,
	          "",
	          "");
	I_Method1(osg::GraphicsContext *, createGraphicsContext, IN, osg::GraphicsContext::Traits *, traits,
	          __GraphicsContext_P1__createGraphicsContext__Traits_P1,
	          "",
	          "");
END_REFLECTOR

STD_LIST_REFLECTOR(std::list< osg::Camera * >);

<commit_msg>Fixed genwrapper to add include of osg/Camera.<commit_after>// ***************************************************************************
//
//   Generated automatically by genwrapper.
//   Please DO NOT EDIT this file!
//
// ***************************************************************************

#include <osgIntrospection/ReflectionMacros>
#include <osgIntrospection/TypedMethodInfo>
#include <osgIntrospection/StaticMethodInfo>
#include <osgIntrospection/Attributes>

#include <osg/GraphicsContext>
#include <osg/GraphicsThread>
#include <osg/State>
#include <osg/Vec4>

// Must undefine IN and OUT macros defined in Windows headers
#ifdef IN
#undef IN
#endif
#ifdef OUT
#undef OUT
#endif

#include <osg/Camera>

TYPE_NAME_ALIAS(std::list< osg::Camera * >, osg::GraphicsContext::Cameras);

BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::GraphicsContext)
	I_BaseType(osg::Referenced);
	I_Method1(void, add, IN, osg::GraphicsOperation *, operation,
	          __void__add__GraphicsOperation_P1,
	          "Add operation to end of OperationQueue. ",
	          "");
	I_Method1(void, remove, IN, osg::GraphicsOperation *, operation,
	          __void__remove__GraphicsOperation_P1,
	          "Remove operation from OperationQueue. ",
	          "");
	I_Method1(void, remove, IN, const std::string &, name,
	          __void__remove__C5_std_string_R1,
	          "Remove named operation from OperationQueue. ",
	          "");
	I_Method0(void, removeAllOperations,
	          __void__removeAllOperations,
	          "Remove all operations from OperationQueue. ",
	          "");
	I_Method0(void, runOperations,
	          __void__runOperations,
	          "Run the operations. ",
	          "");
	I_Method0(const osg::GraphicsContext::Traits *, getTraits,
	          __C5_Traits_P1__getTraits,
	          "Get the traits of the GraphicsContext. ",
	          "");
	I_Method0(bool, valid,
	          __bool__valid,
	          "Return whether a valid and usable GraphicsContext has been created. ",
	          "");
	I_Method1(void, setState, IN, osg::State *, state,
	          __void__setState__State_P1,
	          "Set the State object which tracks the current OpenGL state for this graphics context. ",
	          "");
	I_Method0(osg::State *, getState,
	          __State_P1__getState,
	          "Get the State object which tracks the current OpenGL state for this graphics context. ",
	          "");
	I_Method0(const osg::State *, getState,
	          __C5_State_P1__getState,
	          "Get the const State object which tracks the current OpenGL state for this graphics context. ",
	          "");
	I_Method1(void, setClearColor, IN, const osg::Vec4 &, color,
	          __void__setClearColor__C5_Vec4_R1,
	          "Sets the clear color. ",
	          "");
	I_Method0(const osg::Vec4 &, getClearColor,
	          __C5_Vec4_R1__getClearColor,
	          "Returns the clear color. ",
	          "");
	I_Method1(void, setClearMask, IN, GLbitfield, mask,
	          __void__setClearMask__GLbitfield,
	          "Set the clear mask used in glClear(. ",
	          ".). Defaults to GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT. ");
	I_Method0(GLbitfield, getClearMask,
	          __GLbitfield__getClearMask,
	          "Get the clear mask. ",
	          "");
	I_Method0(void, clear,
	          __void__clear,
	          "Do an OpenGL clear of the full graphics context/window. ",
	          "Note, must only be called from a thread with this context current. ");
	I_Method0(bool, realize,
	          __bool__realize,
	          "Realise the GraphicsContext. ",
	          "");
	I_MethodWithDefaults1(void, close, IN, bool, callCloseImplementation, true,
	                      __void__close__bool,
	                      "close the graphics context. ",
	                      "close(bool) stops any associated graphics threads, releases the contextID for the GraphicsContext then optional calls closeImplementation() to do the actual deletion of the graphics. This call is made optional as there are times when the graphics context has already been deleted externally and only the OSG side of the its data need to be closed down. ");
	I_Method0(void, swapBuffers,
	          __void__swapBuffers,
	          "swap the front and back buffers. ",
	          "");
	I_Method0(bool, isRealized,
	          __bool__isRealized,
	          "Return true if the graphics context has been realised and is ready to use. ",
	          "");
	I_Method0(void, makeCurrent,
	          __void__makeCurrent,
	          "Make this graphics context current. ",
	          "Implementated by first aquiring a lock of the GraphicsContext mutex, and then doing a call to makeCurrentImplementation(). ");
	I_Method1(void, makeContextCurrent, IN, osg::GraphicsContext *, readContext,
	          __void__makeContextCurrent__GraphicsContext_P1,
	          "Make this graphics context current with specified read context. ",
	          "Implementated by first aquiring a lock of the GraphicsContext mutex, and then doing a call to makeContextCurrentImplementation(). ");
	I_Method0(void, releaseContext,
	          __void__releaseContext,
	          "Release the graphics context by unlocking the GraphicsContext mutex. ",
	          "");
	I_Method0(bool, isCurrent,
	          __bool__isCurrent,
	          "Return true if the current thread has this OpenGL graphics context. ",
	          "");
	I_Method1(void, bindPBufferToTexture, IN, GLenum, buffer,
	          __void__bindPBufferToTexture__GLenum,
	          "Bind the graphics context to associated texture. ",
	          "");
	I_Method0(void, createGraphicsThread,
	          __void__createGraphicsThread,
	          "Create a graphics thread to the graphics context, so that the thread handles all OpenGL operations. ",
	          "");
	I_Method1(void, setGraphicsThread, IN, osg::GraphicsThread *, gt,
	          __void__setGraphicsThread__GraphicsThread_P1,
	          "Assign a graphics thread to the graphics context, so that the thread handles all OpenGL operations. ",
	          "");
	I_Method0(osg::GraphicsThread *, getGraphicsThread,
	          __GraphicsThread_P1__getGraphicsThread,
	          "Get the graphics thread assigned the graphics context. ",
	          "");
	I_Method0(const osg::GraphicsThread *, getGraphicsThread,
	          __C5_GraphicsThread_P1__getGraphicsThread,
	          "Get the const graphics thread assigned the graphics context. ",
	          "");
	I_Method0(bool, realizeImplementation,
	          __bool__realizeImplementation,
	          "Realise the GraphicsContext implementation, Pure virtual - must be implemented by concrate implementations of GraphicsContext. ",
	          "");
	I_Method0(bool, isRealizedImplementation,
	          __bool__isRealizedImplementation,
	          "Return true if the graphics context has been realised, and is ready to use, implementation. ",
	          "Pure virtual - must be implemented by concrate implementations of GraphicsContext. ");
	I_Method0(void, closeImplementation,
	          __void__closeImplementation,
	          "Close the graphics context implementation. ",
	          "Pure virtual - must be implemented by concrate implementations of GraphicsContext. ");
	I_Method0(void, makeCurrentImplementation,
	          __void__makeCurrentImplementation,
	          "Make this graphics context current implementation. ",
	          "Pure virtual - must be implemented by concrate implementations of GraphicsContext. ");
	I_Method1(void, makeContextCurrentImplementation, IN, osg::GraphicsContext *, readContext,
	          __void__makeContextCurrentImplementation__GraphicsContext_P1,
	          "Make this graphics context current with specified read context implementation. ",
	          "Pure virtual - must be implemented by concrate implementations of GraphicsContext. ");
	I_Method1(void, bindPBufferToTextureImplementation, IN, GLenum, buffer,
	          __void__bindPBufferToTextureImplementation__GLenum,
	          "Pure virtual, Bind the graphics context to associated texture implementation. ",
	          "Pure virtual - must be implemented by concrate implementations of GraphicsContext. ");
	I_Method0(void, swapBuffersImplementation,
	          __void__swapBuffersImplementation,
	          "Swap the front and back buffers implementation. ",
	          "Pure virtual - must be implemented by Concrate implementations of GraphicsContext. ");
	I_Method4(void, resized, IN, int, x, IN, int, y, IN, int, width, IN, int, height,
	          __void__resized__int__int__int__int,
	          "resized method should be called when the underlying window has been resized and the GraphicsWindow and associated Cameras must be updated to keep in sync with the new size. ",
	          "");
	I_Method0(osg::GraphicsContext::Cameras &, getCameras,
	          __Cameras_R1__getCameras,
	          "Get the the list of cameras associated with this graphics context. ",
	          "");
	I_Method0(const osg::GraphicsContext::Cameras &, getCameras,
	          __C5_Cameras_R1__getCameras,
	          "Get the the const list of cameras associated with this graphics context. ",
	          "");
	I_StaticMethod1(void, setWindowingSystemInterface, IN, osg::GraphicsContext::WindowingSystemInterface *, wsInterface,
	                __void__setWindowingSystemInterface__WindowingSystemInterface_P1_S,
	                "Set the querry the windowing system for screens and create graphics context - this functor should be supplied by the windows toolkit. ",
	                "");
	I_StaticMethod0(osg::GraphicsContext::WindowingSystemInterface *, getWindowingSystemInterface,
	                __WindowingSystemInterface_P1__getWindowingSystemInterface_S,
	                "Get the WindowingSystemInterface. ",
	                "");
	I_StaticMethod1(osg::GraphicsContext *, createGraphicsContext, IN, osg::GraphicsContext::Traits *, traits,
	                __GraphicsContext_P1__createGraphicsContext__Traits_P1_S,
	                "Create a graphics context for a specified set of traits. ",
	                "");
	I_StaticMethod0(unsigned int, createNewContextID,
	                __unsigned_int__createNewContextID_S,
	                "Create a contextID for a new graphics context, this contextID is used to set up the osg::State associate with context. ",
	                "Automatically increments the usage count of the contextID to 1. ");
	I_StaticMethod1(void, incrementContextIDUsageCount, IN, unsigned int, contextID,
	                __void__incrementContextIDUsageCount__unsigned_int_S,
	                "Increment the usage count associate with a contextID. ",
	                "The usage count speficies how many graphics contexts a specific contextID is shared between. ");
	I_StaticMethod1(void, decrementContextIDUsageCount, IN, unsigned int, contextID,
	                __void__decrementContextIDUsageCount__unsigned_int_S,
	                "Decrement the usage count associate with a contextID. ",
	                "Once the contextID goes to 0 the contextID is then free to be reused. ");
	I_SimpleProperty(osg::GraphicsContext::Cameras &, Cameras,
	                 __Cameras_R1__getCameras,
	                 0);
	I_SimpleProperty(const osg::Vec4 &, ClearColor,
	                 __C5_Vec4_R1__getClearColor,
	                 __void__setClearColor__C5_Vec4_R1);
	I_SimpleProperty(GLbitfield, ClearMask,
	                 __GLbitfield__getClearMask,
	                 __void__setClearMask__GLbitfield);
	I_SimpleProperty(osg::GraphicsThread *, GraphicsThread,
	                 __GraphicsThread_P1__getGraphicsThread,
	                 __void__setGraphicsThread__GraphicsThread_P1);
	I_SimpleProperty(osg::State *, State,
	                 __State_P1__getState,
	                 __void__setState__State_P1);
	I_SimpleProperty(const osg::GraphicsContext::Traits *, Traits,
	                 __C5_Traits_P1__getTraits,
	                 0);
END_REFLECTOR

BEGIN_VALUE_REFLECTOR(osg::GraphicsContext::ScreenIdentifier)
	I_Constructor0(____ScreenIdentifier,
	               "",
	               "");
	I_Constructor1(IN, unsigned int, in_screenNum,
	               ____ScreenIdentifier__unsigned_int,
	               "",
	               "");
	I_Constructor3(IN, const std::string &, in_hostName, IN, unsigned int, in_displayNum, IN, unsigned int, in_screenNum,
	               ____ScreenIdentifier__C5_std_string_R1__unsigned_int__unsigned_int,
	               "",
	               "");
	I_Method0(std::string, displayName,
	          __std_string__displayName,
	          "",
	          "");
	I_PublicMemberProperty(std::string, hostName);
	I_PublicMemberProperty(unsigned int, displayNum);
	I_PublicMemberProperty(unsigned int, screenNum);
END_REFLECTOR

BEGIN_OBJECT_REFLECTOR(osg::GraphicsContext::Traits)
	I_BaseType(osg::Referenced);
	I_BaseType(osg::GraphicsContext::ScreenIdentifier);
	I_Constructor0(____Traits,
	               "",
	               "");
	I_PublicMemberProperty(int, x);
	I_PublicMemberProperty(int, y);
	I_PublicMemberProperty(int, width);
	I_PublicMemberProperty(int, height);
	I_PublicMemberProperty(std::string, windowName);
	I_PublicMemberProperty(bool, windowDecoration);
	I_PublicMemberProperty(bool, supportsResize);
	I_PublicMemberProperty(unsigned int, red);
	I_PublicMemberProperty(unsigned int, blue);
	I_PublicMemberProperty(unsigned int, green);
	I_PublicMemberProperty(unsigned int, alpha);
	I_PublicMemberProperty(unsigned int, depth);
	I_PublicMemberProperty(unsigned int, stencil);
	I_PublicMemberProperty(unsigned int, sampleBuffers);
	I_PublicMemberProperty(unsigned int, samples);
	I_PublicMemberProperty(bool, pbuffer);
	I_PublicMemberProperty(bool, quadBufferStereo);
	I_PublicMemberProperty(bool, doubleBuffer);
	I_PublicMemberProperty(GLenum, target);
	I_PublicMemberProperty(unsigned int, level);
	I_PublicMemberProperty(unsigned int, face);
	I_PublicMemberProperty(unsigned int, mipMapGeneration);
	I_PublicMemberProperty(osg::GraphicsContext *, sharedContext);
END_REFLECTOR

BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::GraphicsContext::WindowingSystemInterface)
	I_BaseType(osg::Referenced);
	I_Constructor0(____WindowingSystemInterface,
	               "",
	               "");
	I_MethodWithDefaults1(unsigned int, getNumScreens, IN, const osg::GraphicsContext::ScreenIdentifier &, screenIdentifier, osg::GraphicsContext::ScreenIdentifier(),
	                      __unsigned_int__getNumScreens__C5_ScreenIdentifier_R1,
	                      "",
	                      "");
	I_Method3(void, getScreenResolution, IN, const osg::GraphicsContext::ScreenIdentifier &, screenIdentifier, IN, unsigned int &, width, IN, unsigned int &, height,
	          __void__getScreenResolution__C5_ScreenIdentifier_R1__unsigned_int_R1__unsigned_int_R1,
	          "",
	          "");
	I_Method1(osg::GraphicsContext *, createGraphicsContext, IN, osg::GraphicsContext::Traits *, traits,
	          __GraphicsContext_P1__createGraphicsContext__Traits_P1,
	          "",
	          "");
END_REFLECTOR

STD_LIST_REFLECTOR(std::list< osg::Camera * >);

<|endoftext|>


<commit_before>// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/command_line.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_bookmark_manager_api.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"

IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BookmarkManager) {
  CommandLine::ForCurrentProcess()->AppendSwitch(
      switches::kEnableExperimentalExtensionApis);

  ASSERT_TRUE(RunExtensionTest("bookmark_manager/standard")) << message_;
}

IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BookmarkManagerEditDisabled) {
  CommandLine::ForCurrentProcess()->AppendSwitch(
      switches::kEnableExperimentalExtensionApis);

  Profile* profile = browser()->profile();

  // Provide some testing data here, since bookmark editing will be disabled
  // within the extension.
  BookmarkModel* model = profile->GetBookmarkModel();
  const BookmarkNode* bar = model->GetBookmarkBarNode();
  const BookmarkNode* folder = model->AddFolder(bar, 0, ASCIIToUTF16("Folder"));
  const BookmarkNode* node = model->AddURL(bar, 1, ASCIIToUTF16("AAA"),
                                           GURL("http://aaa.example.com"));
  node = model->AddURL(folder, 0, ASCIIToUTF16("BBB"),
                                  GURL("http://bbb.example.com"));

  profile->GetPrefs()->SetBoolean(prefs::kEditBookmarksEnabled, false);

  ASSERT_TRUE(RunExtensionTest("bookmark_manager/edit_disabled")) << message_;
}
<commit_msg>Tag ExtensionApiTest.BookmarkManagerEditDisabled flaky.<commit_after>// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/command_line.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_bookmark_manager_api.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"

IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BookmarkManager) {
  CommandLine::ForCurrentProcess()->AppendSwitch(
      switches::kEnableExperimentalExtensionApis);

  ASSERT_TRUE(RunExtensionTest("bookmark_manager/standard")) << message_;
}

IN_PROC_BROWSER_TEST_F(ExtensionApiTest, FLAKY_BookmarkManagerEditDisabled) {
  CommandLine::ForCurrentProcess()->AppendSwitch(
      switches::kEnableExperimentalExtensionApis);

  Profile* profile = browser()->profile();

  // Provide some testing data here, since bookmark editing will be disabled
  // within the extension.
  BookmarkModel* model = profile->GetBookmarkModel();
  const BookmarkNode* bar = model->GetBookmarkBarNode();
  const BookmarkNode* folder = model->AddFolder(bar, 0, ASCIIToUTF16("Folder"));
  const BookmarkNode* node = model->AddURL(bar, 1, ASCIIToUTF16("AAA"),
                                           GURL("http://aaa.example.com"));
  node = model->AddURL(folder, 0, ASCIIToUTF16("BBB"),
                                  GURL("http://bbb.example.com"));

  profile->GetPrefs()->SetBoolean(prefs::kEditBookmarksEnabled, false);

  ASSERT_TRUE(RunExtensionTest("bookmark_manager/edit_disabled")) << message_;
}
<|endoftext|>


<commit_before>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_mount_point_provider.h"
#include "webkit/fileapi/file_system_path_manager.h"

#if defined(OS_CHROMEOS)

class FileSystemExtensionApiTest : public ExtensionApiTest {
 public:
  FileSystemExtensionApiTest() : test_mount_point_("/tmp") {
  }

  virtual ~FileSystemExtensionApiTest() {}

  // Sets up test environment
  void AddTmpMountPoint() {
    // Add tmp mount point.
    fileapi::FileSystemPathManager* path_manager =
        browser()->profile()->GetFileSystemContext()->path_manager();
    fileapi::ExternalFileSystemMountPointProvider* provider =
        path_manager->external_provider();
    provider->AddMountPoint(test_mount_point_);
  }

 private:
  FilePath test_mount_point_;
};

IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, LocalFileSystem) {
  AddTmpMountPoint();
  ASSERT_TRUE(RunComponentExtensionTest("local_filesystem")) << message_;

}

IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, FileBrowserTest) {
  AddTmpMountPoint();
  ASSERT_TRUE(RunExtensionTest("filesystem_handler")) << message_;
  ASSERT_TRUE(RunComponentExtensionTest("filebrowser_component")) << message_;
}

#endif
<commit_msg>Disable failing FileBrowserTest on CrOs.<commit_after>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_mount_point_provider.h"
#include "webkit/fileapi/file_system_path_manager.h"

#if defined(OS_CHROMEOS)

class FileSystemExtensionApiTest : public ExtensionApiTest {
 public:
  FileSystemExtensionApiTest() : test_mount_point_("/tmp") {
  }

  virtual ~FileSystemExtensionApiTest() {}

  // Sets up test environment
  void AddTmpMountPoint() {
    // Add tmp mount point.
    fileapi::FileSystemPathManager* path_manager =
        browser()->profile()->GetFileSystemContext()->path_manager();
    fileapi::ExternalFileSystemMountPointProvider* provider =
        path_manager->external_provider();
    provider->AddMountPoint(test_mount_point_);
  }

 private:
  FilePath test_mount_point_;
};

IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, LocalFileSystem) {
  AddTmpMountPoint();
  ASSERT_TRUE(RunComponentExtensionTest("local_filesystem")) << message_;

}

#if defined(OS_CHROMEOS)
// http://crbug.com/103406
#define MAYBE_FileBrowserTest DISABLED_FileBrowserTest
#else
#define MAYBE_FileBrowserTest FileBrowserTest
#endif

IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, MAYBE_FileBrowserTest) {
  AddTmpMountPoint();
  ASSERT_TRUE(RunExtensionTest("filesystem_handler")) << message_;
  ASSERT_TRUE(RunComponentExtensionTest("filebrowser_component")) << message_;
}

#endif
<|endoftext|>


<commit_before>#include "TabLabel.h"
#include <QPainter>
#include <QDebug>
#include <QColor>

TabLabel::TabLabel(QWidget* parent = 0, QSettings* palette = 0) : QLabel(parent)
{
    this->palette = palette;
    this->isActive = false;
}

void TabLabel::paintEvent(QPaintEvent* event) {
    QLabel::paintEvent(event);
    QColor color(Qt::white);
    if (isActive) {
        if (!palette->value("TitleBar/Fulltab").toBool()) {
         color.setNamedColor(palette->value("Navbar/SelectedColor").toString());
        }

        QLabel::paintEvent(event);
        QPainter painter(this);
        painter.setBrush(QBrush(color));
        painter.drawLine(0,this->height() - 2, this->width(), this->height() - 2);
    }
}
<commit_msg>Fix TabLabel.cpp formatting<commit_after>#include "TabLabel.h"
#include <QPainter>
#include <QDebug>
#include <QColor>

TabLabel::TabLabel(QWidget* parent = 0, QSettings* palette = 0) : QLabel(parent)
{
    this->palette = palette;
    this->isActive = false;
}

void TabLabel::paintEvent(QPaintEvent* event)
{
    QLabel::paintEvent(event);
    QColor color(Qt::white);
    if (isActive)
    {
        if (!palette->value("TitleBar/Fulltab").toBool())
        {
            color.setNamedColor(palette->value("Navbar/SelectedColor").toString());
        }

        QLabel::paintEvent(event);
        QPainter painter(this);
        painter.setBrush(QBrush(color));
        painter.drawLine(0,this->height() - 2, this->width(), this->height() - 2);
    }
}
<|endoftext|>


<commit_before>//-----------------------------------------------------------------------------
// The MIT License (MIT)
//
// Copyright (c) 2017 Jeff Hutchinson
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//-----------------------------------------------------------------------------

#include <cstdio>
#include <vector>
#include <duktape.h>

const char * script =
"var gSharedVariable = 0;\n"
"function add(a, b) {\n"
"   return a + b;\n"
"}\n"
"\n"
"Animal.prototype.test = function() {\n"
"   print('Test Call to javacript from C++.');\n"
"};\n"
"\n"
"function main() {\n"
"   print('Hello World!');\n"
"   print('Value of shared variable is ' + gSharedVariable);\n"
"}\n"
"\n"
"var animal = new Animal();\n"
"for (var i = 0; i < 5; i++) {\n"
"   animal.speak();\n"
"}\n";

duk_context *ctx = nullptr;

void viewStack(duk_context *ctx);

// https://github.com/svaarala/duktape-wiki/blob/master/HowtoNativeConstructor.md
class Animal {
public:
	Animal() {

	}

	void speak() {
		printf("SPEAK!!!!\n");
	}

	void *dukPtr;
};
std::vector<Animal*> gAnimals;

static duk_ret_t Animal_New(duk_context *ctx) {
	if (!duk_is_constructor_call(ctx))
		return DUK_RET_TYPE_ERROR;

	// Stack: []

	Animal *ptr = new Animal();
	gAnimals.push_back(ptr);

	duk_push_this(ctx); // [ this ]
	ptr->dukPtr = duk_get_heapptr(ctx, -1); // [ this ]

	// Bind the native pointer to the js pointer.
	duk_push_string(ctx, "__ptr"); // [ this "__ptr" ]
	duk_push_pointer(ctx, ptr); // [ this "__ptr" 0xPTR ]
	duk_put_prop(ctx, -3); // [ this ]

	return 0;
}

static duk_ret_t Animal_speak(duk_context *ctx) {
	// Get the object we are modifiying, or the thisptr
	duk_push_this(ctx);

	// Get the native pointer handle.
	duk_get_prop_string(ctx, -1, "__ptr");
	void *ptr = duk_get_pointer(ctx, -1);

	// Call speak
	static_cast<Animal*>(ptr)->speak();
	return 0;
}

static void firePrototypeCb_Animal(Animal *animal) {
	duk_push_heapptr(ctx, animal->dukPtr); // [ ... dukPtr ]
	duk_get_prop_string(ctx, -1, "test"); // [ ... dukPtr test_fn ]
	duk_pcall(ctx, 0); // [ ... dukPtr return_value ]
	// Ignore return value
	duk_pop(ctx); // [ ... dukPtr ]

	// pop obj that we pushed.
	duk_pop(ctx); // [ ... ]
}

void viewStack(duk_context *ctx) {
	// duk_to_string modifies the stack, so we have to duplicate the current
	// value that we are inspecting to the top of the stack by pushing it,
	// modifying it, and then poping it so we don't screw up the stack.
	// This is probably slow, but this function is used for inspecting the stack.
	// http://duktape.org/api.html#duk_to_string
	printf("----- Viewing Stack -----\n");
	int count = duk_get_top_index(ctx);
	for (int i = count; i > -1; i--) {
		duk_dup(ctx, i);
		if (duk_is_object(ctx, count + 1))
			printf("%s\n", duk_json_encode(ctx, count + 1));
		else
			printf("%s\n", duk_to_string(ctx, count + 1));
		duk_pop(ctx);
	}
	printf("---- end Stack ----\n");
}

// https://github.com/svaarala/duktape/blob/master/examples/guide/primecheck.c
static duk_ret_t script_print(duk_context *ctxx) {
	duk_push_string(ctxx, " ");
	duk_insert(ctxx, 0);
	duk_join(ctxx, duk_get_top(ctxx) - 1);
	printf("%s\n", duk_to_string(ctxx, -1));
	return 0;
}

// after each line is executed, the comments that follow is what the stack looks like
int main(int argc, const char **argv) {
	ctx = duk_create_heap_default(); // Stack: [ ... ]

	duk_push_global_object(ctx);// Stack: [ ... global_object ]
	duk_push_c_function(ctx, script_print, DUK_VARARGS); // [ ... global_object script_print_fn ]
	duk_put_prop_string(ctx, -2, "print"); // [ ... global_object ]

	/// {
	/// Initialize Animal Prototype

	// Bind the prototype constructor and object.
	duk_push_c_function(ctx, Animal_New, 0); // [ ... global_object AnimalCSTR ]
	duk_push_object(ctx); // [ ... global_object AnimalCSTR PrototypeObj ]

	// Bind methods to the prototype
	{
		duk_push_c_function(ctx, Animal_speak, 0);
		duk_put_prop_string(ctx, -2, "speak");
	}

	// Bind prototype property and the name of the prototype to use with new stmts.
	duk_put_prop_string(ctx, -2, "prototype"); // [ ... global_object AnimalCSTR ]
	duk_put_global_string(ctx, "Animal"); // [ ... global_object ]

	/// }

	duk_eval_string_noresult(ctx, script); // [ ... global_object ]
	duk_get_prop_string(ctx, -1, "main");  // [ ... global_object main_fn ]
	if (duk_pcall(ctx, 0) != 0) { // [ ... global_object return_value ]
		printf("Error: %s\n", duk_safe_to_string(ctx, -1)); // [ ... global_object return_value ]
	}
	duk_pop(ctx); // [ ... global_object ]

	// Call add
	// currently stack is just global object which has add fn.
	duk_get_prop_string(ctx, -1, "add"); // [ ... global_object add_fn ]
	duk_push_int(ctx, 4); // [ ... global_object add_fn 4 ]
	duk_push_int(ctx, 5); // [ ... global_object add_fn 4 5 ]
	if (duk_pcall(ctx, 2) == DUK_EXEC_SUCCESS) { // [ ... global_object return_value ]
		printf("Result of add() is %d\n", duk_get_int(ctx, -1)); // [ ... global_object return_value ]
	} else {
		printf("Error: %s\n", duk_safe_to_string(ctx, -1)); // [ ... global_object return_value ]
	}
	duk_pop(ctx); // [ ... global_object ]

	firePrototypeCb_Animal(gAnimals[0]);

	duk_pop(ctx); // [ ... ]
	duk_destroy_heap(ctx); // []

#ifdef _WIN32
	system("pause");
#endif
	return 0;
}<commit_msg>get single inheritence working!<commit_after>//-----------------------------------------------------------------------------
// The MIT License (MIT)
//
// Copyright (c) 2017 Jeff Hutchinson
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//-----------------------------------------------------------------------------

#include <cstdio>
#include <vector>
#include <duktape.h>

const char * script =
"var gSharedVariable = 0;\n"
"function add(a, b) {\n"
"   return a + b;\n"
"}\n"
"\n"
"Animal.prototype.test = function() {\n"
"   print('Test Call to javacript from C++.');\n"
"};\n"
"\n"
"function main() {\n"
"   print('Hello World!');\n"
"   print('Value of shared variable is ' + gSharedVariable);\n"
"}\n"
"\n"
"var animal = new Animal();\n"
"print('Animal: ' + JSON.stringify(animal));\n"
"for (var i = 0; i < 5; i++) {\n"
"   animal.speak();\n"
"}\n"
"\n"
"var dog = new Dog();\n"
"print('Dog: ' + JSON.stringify(dog));\n"
"dog.speakDog();\n"
"dog.speak();\n";

duk_context *ctx = nullptr;

void viewStack(duk_context *ctx);

// https://github.com/svaarala/duktape-wiki/blob/master/HowtoNativeConstructor.md
class Animal {
public:
	Animal() {

	}

	void speak() {
		printf("SPEAK!!!!\n");
	}

	void *dukPtr;
};

class Dog : public Animal {
public:
	Dog() {

	}

	void speakDog() {
		printf("DOG!\n");
	}
};

std::vector<Animal*> gAnimals;

static duk_ret_t Animal_New(duk_context *ctx) {
	if (!duk_is_constructor_call(ctx))
		return DUK_RET_TYPE_ERROR;

	// Stack: []

	Animal *ptr = new Animal();
	gAnimals.push_back(ptr);

	duk_push_this(ctx); // [ this ]
	ptr->dukPtr = duk_get_heapptr(ctx, -1); // [ this ]

	// Bind the native pointer to the js pointer.
	duk_push_string(ctx, "__ptr"); // [ this "__ptr" ]
	duk_push_pointer(ctx, ptr); // [ this "__ptr" 0xPTR ]
	duk_put_prop(ctx, -3); // [ this ]

	return 0;
}

static duk_ret_t Animal_speak(duk_context *ctx) {
	// Get the object we are modifiying, or the thisptr
	duk_push_this(ctx);

	// Get the native pointer handle.
	duk_get_prop_string(ctx, -1, "__ptr");
	void *ptr = duk_get_pointer(ctx, -1);

	// Call speak
	static_cast<Animal*>(ptr)->speak();
	return 0;
}

static void firePrototypeCb_Animal(Animal *animal) {
	duk_push_heapptr(ctx, animal->dukPtr); // [ ... dukPtr ]
	duk_get_prop_string(ctx, -1, "test"); // [ ... dukPtr test_fn ]
	duk_pcall(ctx, 0); // [ ... dukPtr return_value ]
	// Ignore return value
	duk_pop(ctx); // [ ... dukPtr ]

	// pop obj that we pushed.
	duk_pop(ctx); // [ ... ]
}

static duk_ret_t Dog_New(duk_context *ctx) {
	if (!duk_is_constructor_call(ctx))
		return DUK_RET_TYPE_ERROR;

	// Stack: []

	Dog *ptr = new Dog();
	gAnimals.push_back(ptr);

	duk_push_this(ctx); // [ this ]
	ptr->dukPtr = duk_get_heapptr(ctx, -1); // [ this ]

	// Bind the native pointer to the js pointer.
	duk_push_string(ctx, "__ptr"); // [ this "__ptr" ]
	duk_push_pointer(ctx, ptr); // [ this "__ptr" 0xPTR ]
	duk_put_prop(ctx, -3); // [ this ]

	return 0;
}

static duk_ret_t Dog_speakDog(duk_context *ctx) {
	// Get the object we are modifiying, or the thisptr
	duk_push_this(ctx);

	// Get the native pointer handle.
	duk_get_prop_string(ctx, -1, "__ptr");
	void *ptr = duk_get_pointer(ctx, -1);

	// Call speak
	static_cast<Dog*>(ptr)->speakDog();
	return 0;
}

void viewStack(duk_context *ctx) {
	// duk_to_string modifies the stack, so we have to duplicate the current
	// value that we are inspecting to the top of the stack by pushing it,
	// modifying it, and then poping it so we don't screw up the stack.
	// This is probably slow, but this function is used for inspecting the stack.
	// http://duktape.org/api.html#duk_to_string
	printf("----- Viewing Stack -----\n");
	int count = duk_get_top_index(ctx);
	for (int i = count; i > -1; i--) {
		duk_dup(ctx, i);
		if (duk_is_function(ctx, count + 1))
			printf("%s\n", duk_to_string(ctx, count + 1));
		else if (duk_is_string(ctx, count + 1) || duk_is_number(ctx, count + 1))
			printf("%s\n", duk_to_string(ctx, count + 1));
		else
			printf("%s\n", duk_json_encode(ctx, count + 1));
		duk_pop(ctx);
	}
	printf("---- end Stack ----\n");
}

// https://github.com/svaarala/duktape/blob/master/examples/guide/primecheck.c
static duk_ret_t script_print(duk_context *ctxx) {
	duk_push_string(ctxx, " ");
	duk_insert(ctxx, 0);
	duk_join(ctxx, duk_get_top(ctxx) - 1);
	printf("%s\n", duk_to_string(ctxx, -1));
	return 0;
}

// after each line is executed, the comments that follow is what the stack looks like
int main(int argc, const char **argv) {
	ctx = duk_create_heap_default(); // Stack: [ ... ]

	duk_push_global_object(ctx);// Stack: [ ... global_object ]
	viewStack(ctx);
	duk_push_c_function(ctx, script_print, DUK_VARARGS); // [ ... global_object script_print_fn ]
	viewStack(ctx);
	duk_put_prop_string(ctx, -2, "print"); // [ ... global_object ]
	viewStack(ctx);

	/// {
	/// Initialize Animal Prototype

	// Bind the prototype constructor and object.
	duk_push_c_function(ctx, Animal_New, 0); // [ ... global_object AnimalCSTR ]
	viewStack(ctx);
	duk_push_object(ctx); // [ ... global_object AnimalCSTR PrototypeObj ]
	viewStack(ctx);

	// Bind methods to the prototype
	{
		duk_push_c_function(ctx, Animal_speak, 0);
		viewStack(ctx);
		duk_put_prop_string(ctx, -2, "speak");
		viewStack(ctx);
	}

	// Bind prototype property and the name of the prototype to use with new stmts.
	duk_put_prop_string(ctx, -2, "prototype"); // [ ... global_object AnimalCSTR ]
	viewStack(ctx);
	duk_put_global_string(ctx, "Animal"); // [ ... global_object ]
	viewStack(ctx);

	/// }

	/// {
	/// Initialize Dog Prototype

	duk_push_c_function(ctx, Dog_New, 0);
	viewStack(ctx);
	duk_get_global_string(ctx, "Animal");
	viewStack(ctx);
	duk_new(ctx, 0);
	viewStack(ctx);

	// Bind dog methods
	{
		duk_push_c_function(ctx, Dog_speakDog, 0);
		viewStack(ctx);
		duk_put_prop_string(ctx, -2, "speakDog");
		viewStack(ctx);
	}

	duk_put_prop_string(ctx, -2, "prototype");
	viewStack(ctx);
	duk_put_global_string(ctx, "Dog");
	viewStack(ctx);

	//duk_eval_string_noresult(ctx, "Dog.prototype = new Animal();");

	/// }

	if (duk_peval_string(ctx, script) != 0) { // [ ... global_object result ]
		printf("Script pEval Failure: %s\n", duk_safe_to_string(ctx, -1));
#ifdef _WIN32
		system("pause");
#endif
		exit(1);
	}
	duk_pop(ctx); // [ ... global_object ]
	duk_get_prop_string(ctx, -1, "main");  // [ ... global_object main_fn ]
	if (duk_pcall(ctx, 0) != 0) { // [ ... global_object return_value ]
		printf("Error: %s\n", duk_safe_to_string(ctx, -1)); // [ ... global_object return_value ]
	}
	duk_pop(ctx); // [ ... global_object ]

	// Call add
	// currently stack is just global object which has add fn.
	duk_get_prop_string(ctx, -1, "add"); // [ ... global_object add_fn ]
	duk_push_int(ctx, 4); // [ ... global_object add_fn 4 ]
	duk_push_int(ctx, 5); // [ ... global_object add_fn 4 5 ]
	if (duk_pcall(ctx, 2) == DUK_EXEC_SUCCESS) { // [ ... global_object return_value ]
		printf("Result of add() is %d\n", duk_get_int(ctx, -1)); // [ ... global_object return_value ]
	} else {
		printf("Error: %s\n", duk_safe_to_string(ctx, -1)); // [ ... global_object return_value ]
	}
	duk_pop(ctx); // [ ... global_object ]

	firePrototypeCb_Animal(gAnimals[0]);

	duk_pop(ctx); // [ ... ]
	duk_destroy_heap(ctx); // []

#ifdef _WIN32
	system("pause");
#endif
	return 0;
}<|endoftext|>


<commit_before>/**
 * BSD 3-Clause License
 *
 * Copyright (c) 2017, Soumyajit De
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * * Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 *
 * * Neither the name of the copyright holder nor the names of its
 *   contributors may be used to endorse or promote products derived from
 *   this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <map>
#include <iostream>
#include <functional>
#include <tuple>
#include <memory>
#include <initializer_list>
#include <utility>
#include <shogun/lib/Vector.hpp>

using namespace shogun;
using Reducers::custom;
using Reducers::sum;
using Reducers::prod;
using Reducers::double_mean;
using std::cout;
using std::endl;
using std::make_pair;
using std::pair;
using std::get;

template <class C>
void test_off_the_shelf_stream_methods(const C& c)
{
	cout << "off-the-shelf stream methods ----------" << endl;
	cout << "sum = " << c.stream().sum() << endl;
	cout << "prod = " << c.stream().prod() << endl;
	cout << "mean = " << c.stream().double_mean() << endl;
}

template <class C>
void test_off_the_shelf_reducers(const C& c)
{
	cout << "off-the-shelf Recuders ----------" << endl;
	cout << "sum = " << c.stream().reduce(sum<int>()) << endl;
	cout << "prod = " << c.stream().reduce(prod<int>()) << endl;
	cout << "mean = " << c.stream().reduce(double_mean<int>()).first << endl;
}

template <class C>
void test_off_the_shelf_reducers_multiple(const C& c)
{
	cout << "off-the-shelf (multiple)----------" << endl;
	auto ots_m1 = c.stream().reduce(sum<int>(), prod<int>());
	auto ots_m2 = c.stream().reduce(sum<int>(), prod<int>(), double_mean<int>());
	cout << "sum,prod = " << get<0>(ots_m1) << ","	<< get<1>(ots_m1) << endl;
	cout << "sum,prod,mean = " << get<0>(ots_m2) << ","	<< get<1>(ots_m2) << "," << get<2>(ots_m2).first << endl;
}

template <class C>
void test_custom_reducers(const C& c)
{
	auto reducer1 = custom(0, [](int r, const int& v) { return r+v; });
	auto reducer2 = custom(1, [](int r, const int& v) { return r*v; });
	auto reducer3 = custom(make_pair(0.0,1ul), [](pair<double,size_t> r, const int& v)
			{
				auto delta = v - r.first;
				r.first += delta/r.second++;
				return r;
			});

	cout << "cutom reducers ----------" << endl;
	cout << "sum = " << c.stream().reduce(reducer1) << endl;
	cout << "prod = " << c.stream().reduce(reducer2) << endl;
	cout << "mean = " << c.stream().reduce(reducer3).first << endl;
}

template <class C>
void test_custom_reducers_multiple(const C& c)
{
	auto reducer1 = custom(0, [](int r, const int& v) { return r+v; });
	auto reducer2 = custom(1, [](int r, const int& v) { return r*v; });
	auto reducer3 = custom(make_pair(0.0,1ul), [](pair<double,size_t> r, const int& v)
			{
				auto delta = v - r.first;
				r.first += delta/r.second++;
				return r;
			});

	auto result2 = c.stream().reduce(reducer1, reducer2);
	auto result3 = c.stream().reduce(reducer1, reducer2, reducer3);

	cout << "custom reducers (multiple)--------" << endl;
	cout << "sum,prd = " << get<0>(result2) << "," << get<1>(result2) << endl;
	cout << "sum,prod,mean = " << get<0>(result3) << "," << get<1>(result3)  << "," << get<2>(result3).first << endl;
}

template <class C>
void test_off_the_shelf_reducers_bind_channel(const C& c)
{
	const int&(*get_0)(const std::pair<int,int>&) = std::get<0,int,int>;
	const int&(*get_1)(const std::pair<int,int>&) = std::get<1,int,int>;

	cout << "off-the-shelf Recuders bind channel ----------" << endl;
	cout << "sum = " << c.stream().reduce(bind_channel(sum<int>(), get_0)) << endl;
	cout << "sum = " << c.stream().reduce(bind_channel(sum<int>(), get_1)) << endl;
	cout << "prod = " << c.stream().reduce(bind_channel(prod<int>(), get_0)) << endl;
	cout << "prod = " << c.stream().reduce(bind_channel(prod<int>(), get_1)) << endl;
	cout << "mean = " << c.stream().reduce(bind_channel(double_mean<int>(), get_0)).first << endl;
	cout << "mean = " << c.stream().reduce(bind_channel(double_mean<int>(), get_1)).first << endl;
}

int main()
{
	Vector<int> v({1,2,3,4,5,6,7,8,9,10});
	test_off_the_shelf_stream_methods(v);
	test_off_the_shelf_reducers(v);
	test_off_the_shelf_reducers_multiple(v);
	test_custom_reducers(v);
	test_custom_reducers_multiple(v);

	Vector<std::pair<int,int>> vp({std::make_pair(1,2),std::make_pair(3,4),std::make_pair(5,6),std::make_pair(7,8)});
	test_off_the_shelf_reducers_bind_channel(vp);
	return 0;
}
<commit_msg>tests, more tests<commit_after>/**
 * BSD 3-Clause License
 *
 * Copyright (c) 2017, Soumyajit De
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * * Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 *
 * * Neither the name of the copyright holder nor the names of its
 *   contributors may be used to endorse or promote products derived from
 *   this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <map>
#include <iostream>
#include <functional>
#include <tuple>
#include <memory>
#include <initializer_list>
#include <utility>
#include <shogun/lib/Vector.hpp>

using namespace shogun;
using Reducers::custom;
using Reducers::sum;
using Reducers::prod;
using Reducers::double_mean;
using std::cout;
using std::endl;
using std::make_pair;
using std::pair;
using std::get;

template <class C>
void test_off_the_shelf_stream_methods(const C& c)
{
	cout << "off-the-shelf stream methods ----------" << endl;
	cout << "sum = " << c.stream().sum() << endl;
	cout << "prod = " << c.stream().prod() << endl;
	cout << "mean = " << c.stream().double_mean() << endl;
}

template <class C>
void test_off_the_shelf_reducers(const C& c)
{
	cout << "off-the-shelf Recuders ----------" << endl;
	cout << "sum = " << c.stream().reduce(sum<int>()) << endl;
	cout << "prod = " << c.stream().reduce(prod<int>()) << endl;
	cout << "mean = " << c.stream().reduce(double_mean<int>()).first << endl;
}

template <class C>
void test_off_the_shelf_reducers_multiple(const C& c)
{
	cout << "off-the-shelf (multiple)----------" << endl;
	auto ots_m1 = c.stream().reduce(sum<int>(), prod<int>());
	auto ots_m2 = c.stream().reduce(sum<int>(), prod<int>(), double_mean<int>());
	cout << "sum,prod = " << get<0>(ots_m1) << ","	<< get<1>(ots_m1) << endl;
	cout << "sum,prod,mean = " << get<0>(ots_m2) << ","	<< get<1>(ots_m2) << "," << get<2>(ots_m2).first << endl;
}

template <class C>
void test_custom_reducers(const C& c)
{
	auto reducer1 = custom(0, [](int r, const int& v) { return r+v; });
	auto reducer2 = custom(1, [](int r, const int& v) { return r*v; });
	auto reducer3 = custom(make_pair(0.0,1ul), [](pair<double,size_t> r, const int& v)
			{
				auto delta = v - r.first;
				r.first += delta/r.second++;
				return r;
			});

	cout << "cutom reducers ----------" << endl;
	cout << "sum = " << c.stream().reduce(reducer1) << endl;
	cout << "prod = " << c.stream().reduce(reducer2) << endl;
	cout << "mean = " << c.stream().reduce(reducer3).first << endl;
}

template <class C>
void test_custom_reducers_multiple(const C& c)
{
	auto reducer1 = custom(0, [](int r, const int& v) { return r+v; });
	auto reducer2 = custom(1, [](int r, const int& v) { return r*v; });
	auto reducer3 = custom(make_pair(0.0,1ul), [](pair<double,size_t> r, const int& v)
			{
				auto delta = v - r.first;
				r.first += delta/r.second++;
				return r;
			});

	auto result2 = c.stream().reduce(reducer1, reducer2);
	auto result3 = c.stream().reduce(reducer1, reducer2, reducer3);

	cout << "custom reducers (multiple)--------" << endl;
	cout << "sum,prd = " << get<0>(result2) << "," << get<1>(result2) << endl;
	cout << "sum,prod,mean = " << get<0>(result3) << "," << get<1>(result3)  << "," << get<2>(result3).first << endl;
}

template <class C>
void test_off_the_shelf_reducers_bind_channel(const C& c)
{
	const int&(*get_0)(const std::pair<int,int>&) = std::get<0,int,int>;
	const int&(*get_1)(const std::pair<int,int>&) = std::get<1,int,int>;

	cout << "off-the-shelf Recuders bind channel ----------" << endl;
	cout << "sum(0) = " << c.stream().reduce(bind_channel(sum<int>(), get_0)) << endl;
	cout << "sum(1)= " << c.stream().reduce(bind_channel(sum<int>(), get_1)) << endl;
	cout << "prod(0) = " << c.stream().reduce(bind_channel(prod<int>(), get_0)) << endl;
	cout << "prod(1) = " << c.stream().reduce(bind_channel(prod<int>(), get_1)) << endl;
	cout << "mean(0) = " << c.stream().reduce(bind_channel(double_mean<int>(), get_0)).first << endl;
	cout << "mean(1) = " << c.stream().reduce(bind_channel(double_mean<int>(), get_1)).first << endl;
}

template <class C>
void test_off_the_shelf_multiple_reducers_bind_channel(const C& c)
{
	const int&(*get_0)(const std::pair<int,int>&) = std::get<0,int,int>;
	const int&(*get_1)(const std::pair<int,int>&) = std::get<1,int,int>;

	auto result = c.stream().reduce(bind_channel(sum<int>(), get_0), bind_channel(double_mean<int>(), get_1));
	cout << "off-the-shelf Multiple Recuders bind channel ----------" << endl;
	cout << "sum(0), mean(1) = " << result.first << "," << result.second.first << std::endl;
}

int main()
{
	Vector<int> v({1,2,3,4,5,6,7,8,9,10});
	test_off_the_shelf_stream_methods(v);
	test_off_the_shelf_reducers(v);
	test_off_the_shelf_reducers_multiple(v);
	test_custom_reducers(v);
	test_custom_reducers_multiple(v);

	Vector<std::pair<int,int>> vp({std::make_pair(1,2),std::make_pair(3,4),std::make_pair(5,6),std::make_pair(7,8)});
	test_off_the_shelf_reducers_bind_channel(vp);
	test_off_the_shelf_multiple_reducers_bind_channel(vp);

	return 0;
}
<|endoftext|>


<commit_before>/*********************************************************************/
/* Copyright (c) 2013, EPFL/Blue Brain Project                       */
/*                     Raphael Dumusc <raphael.dumusc@epfl.ch>       */
/* All rights reserved.                                              */
/*                                                                   */
/* Redistribution and use in source and binary forms, with or        */
/* without modification, are permitted provided that the following   */
/* conditions are met:                                               */
/*                                                                   */
/*   1. Redistributions of source code must retain the above         */
/*      copyright notice, this list of conditions and the following  */
/*      disclaimer.                                                  */
/*                                                                   */
/*   2. Redistributions in binary form must reproduce the above      */
/*      copyright notice, this list of conditions and the following  */
/*      disclaimer in the documentation and/or other materials       */
/*      provided with the distribution.                              */
/*                                                                   */
/*    THIS  SOFTWARE IS PROVIDED  BY THE  UNIVERSITY OF  TEXAS AT    */
/*    AUSTIN  ``AS IS''  AND ANY  EXPRESS OR  IMPLIED WARRANTIES,    */
/*    INCLUDING, BUT  NOT LIMITED  TO, THE IMPLIED  WARRANTIES OF    */
/*    MERCHANTABILITY  AND FITNESS FOR  A PARTICULAR  PURPOSE ARE    */
/*    DISCLAIMED.  IN  NO EVENT SHALL THE UNIVERSITY  OF TEXAS AT    */
/*    AUSTIN OR CONTRIBUTORS BE  LIABLE FOR ANY DIRECT, INDIRECT,    */
/*    INCIDENTAL,  SPECIAL, EXEMPLARY,  OR  CONSEQUENTIAL DAMAGES    */
/*    (INCLUDING, BUT  NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE    */
/*    GOODS  OR  SERVICES; LOSS  OF  USE,  DATA,  OR PROFITS;  OR    */
/*    BUSINESS INTERRUPTION) HOWEVER CAUSED  AND ON ANY THEORY OF    */
/*    LIABILITY, WHETHER  IN CONTRACT, STRICT  LIABILITY, OR TORT    */
/*    (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY WAY OUT    */
/*    OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF ADVISED  OF  THE    */
/*    POSSIBILITY OF SUCH DAMAGE.                                    */
/*                                                                   */
/* The views and conclusions contained in the software and           */
/* documentation are those of the authors and should not be          */
/* interpreted as representing official policies, either expressed   */
/* or implied, of The University of Texas at Austin.                 */
/*********************************************************************/

#include "WebkitPixelStreamer.h"

#include <QtWebKit/QWebFrame>
#include <QtWebKit/QWebView>
#include <QtWebKit/QWebElement>
#include <QKeyEvent>

#include <QTimer>

#include "log.h"

#define WEPPAGE_DEFAULT_WIDTH   1280
#define WEBPAGE_DEFAULT_HEIGHT  1024
#define WEBPAGE_DEFAULT_ZOOM    2.0
#define WEPPAGE_MIN_WIDTH   (WEPPAGE_DEFAULT_WIDTH/2)
#define WEBPAGE_MIN_HEIGHT  (WEBPAGE_DEFAULT_HEIGHT/2)

WebkitPixelStreamer::WebkitPixelStreamer(QString uri)
    : LocalPixelStreamer(uri)
    , webView_(0)
    , timer_(0)
    , frameIndex_(0)
{
    webView_ = new QWebView();
    webView_->page()->setViewportSize( QSize( WEPPAGE_DEFAULT_WIDTH*WEBPAGE_DEFAULT_ZOOM, WEBPAGE_DEFAULT_HEIGHT*WEBPAGE_DEFAULT_ZOOM ));
    webView_->setZoomFactor(WEBPAGE_DEFAULT_ZOOM);

    webView_->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
    webView_->settings()->setAttribute(QWebSettings::FrameFlatteningEnabled, true);

    timer_ = new QTimer();
    connect(timer_, SIGNAL(timeout()), this, SLOT(update()));
    timer_->start(30);
}

WebkitPixelStreamer::~WebkitPixelStreamer()
{
    timer_->stop();
    delete timer_;
    delete webView_;
}

void WebkitPixelStreamer::setUrl(QString url)
{
    QMutexLocker locker(&mutex_);

    webView_->load( QUrl(url) );
}

void WebkitPixelStreamer::updateInteractionState(InteractionState interactionState)
{
    QMutexLocker locker(&mutex_);

    QWebPage* page = webView_->page();

    int x = interactionState.mouseX*page->viewportSize().width();
    int y = interactionState.mouseY*page->viewportSize().height();

    x = std::max(0, std::min(x, page->viewportSize().width()-1));
    y = std::max(0, std::min(y, page->viewportSize().height()-1));

    int dx = interactionState.dx*page->viewportSize().width();
    int dy = interactionState.dy*page->viewportSize().height();

    QPoint pointerPos(x, y);
    QWebFrame *pFrame = page->frameAt(pointerPos);

    if (interactionState.type == InteractionState::EVT_CLICK)
    {
        // History navigation (until swipe gestures are fixed)
        if (interactionState.mouseX < 0.02)
        {
            webView_->back();
            return;
        }
        else if (interactionState.mouseX > 0.98)
        {
            webView_->forward();
            return;
        }

        QWebHitTestResult hitResult = pFrame->hitTestContent(pointerPos);

        if ( !hitResult.isNull() )
        {
            if (!hitResult.linkUrl().isEmpty())
            {
                webView_->load(hitResult.linkUrl());
            }
            else
            {
                hitResult.element().evaluateJavaScript("this.click()");

                if (hitResult.isContentEditable())
                {
                    hitResult.element().setFocus();
                    // Ugly hack to work around a focus problem: some input fields receive
                    // focus yet key events are still directed to a different INPUT field..
                    if (hitResult.element().tagName()== "INPUT")
                        hitResult.element().evaluateJavaScript("this.value = this.value");
                }
            }
        }
    }

    else if (interactionState.type == InteractionState::EVT_MOVE || interactionState.type == InteractionState::EVT_WHEEL)
    {
        pFrame->scroll(-dx,-dy);
    }

    else if (interactionState.type == InteractionState::EVT_SWIPE_LEFT)
    {
        webView_->back();
    }
    else if (interactionState.type == InteractionState::EVT_SWIPE_RIGHT)
    {
        webView_->forward();
    }

    else if (interactionState.type == InteractionState::EVT_KEY_PRESS)
    {
        QKeyEvent myEvent(QEvent::KeyPress, interactionState.key,
                          (Qt::KeyboardModifiers)interactionState.modifiers,
                          QString::fromStdString(interactionState.text)
                          );
        page->event(&myEvent);
    }
    else if (interactionState.type == InteractionState::EVT_KEY_RELEASE)
    {
        QKeyEvent myEvent(QEvent::KeyRelease, interactionState.key,
                          (Qt::KeyboardModifiers)interactionState.modifiers,
                          QString::fromStdString(interactionState.text)
                          );
        page->event(&myEvent);
    }

    else if (interactionState.type == InteractionState::EVT_VIEW_SIZE_CHANGED)
    {
        QSize newSize( std::max((int)interactionState.dx, WEPPAGE_MIN_WIDTH), std::max((int)interactionState.dy, WEBPAGE_MIN_HEIGHT) );

        double zoomFactor = (double)newSize.width() / (double)WEPPAGE_DEFAULT_WIDTH;

        webView_->page()->setViewportSize( newSize );
        webView_->setZoomFactor(zoomFactor);
    }
}

QSize WebkitPixelStreamer::size() const
{
    return webView_->page()->viewportSize();
}

void WebkitPixelStreamer::update()
{
    QMutexLocker locker(&mutex_);

    QWebPage* page = webView_->page();
    if( !page->viewportSize().isEmpty())
    {
        if (image_.size() != page->viewportSize())
	        image_ = QImage( page->viewportSize(), QImage::Format_ARGB32 );

        QPainter painter( &image_ );
        page->mainFrame()->render( &painter );
        painter.end();

        PixelStreamSegment segment;
        segment.parameters = makeSegmentHeader();

        segment.imageData = QByteArray::fromRawData((const char*)image_.bits(), image_.byteCount());
        segment.imageData.detach();

        ++frameIndex_;

        emit segmentUpdated(uri_, segment);
    }
}

PixelStreamSegmentParameters WebkitPixelStreamer::makeSegmentHeader()
{
    PixelStreamSegmentParameters parameters;

    parameters.sourceIndex = 0;
    parameters.frameIndex = frameIndex_;

    parameters.totalHeight = webView_->page()->viewportSize().height();
    parameters.totalWidth = webView_->page()->viewportSize().width();

    parameters.height = parameters.totalHeight;
    parameters.width = parameters.totalWidth;

    parameters.x = 0;
    parameters.y = 0;

    parameters.compressed = false;

    return parameters;
}
<commit_msg>Enable settings in webbrowser to support WebGL and CSS3D<commit_after>/*********************************************************************/
/* Copyright (c) 2013, EPFL/Blue Brain Project                       */
/*                     Raphael Dumusc <raphael.dumusc@epfl.ch>       */
/* All rights reserved.                                              */
/*                                                                   */
/* Redistribution and use in source and binary forms, with or        */
/* without modification, are permitted provided that the following   */
/* conditions are met:                                               */
/*                                                                   */
/*   1. Redistributions of source code must retain the above         */
/*      copyright notice, this list of conditions and the following  */
/*      disclaimer.                                                  */
/*                                                                   */
/*   2. Redistributions in binary form must reproduce the above      */
/*      copyright notice, this list of conditions and the following  */
/*      disclaimer in the documentation and/or other materials       */
/*      provided with the distribution.                              */
/*                                                                   */
/*    THIS  SOFTWARE IS PROVIDED  BY THE  UNIVERSITY OF  TEXAS AT    */
/*    AUSTIN  ``AS IS''  AND ANY  EXPRESS OR  IMPLIED WARRANTIES,    */
/*    INCLUDING, BUT  NOT LIMITED  TO, THE IMPLIED  WARRANTIES OF    */
/*    MERCHANTABILITY  AND FITNESS FOR  A PARTICULAR  PURPOSE ARE    */
/*    DISCLAIMED.  IN  NO EVENT SHALL THE UNIVERSITY  OF TEXAS AT    */
/*    AUSTIN OR CONTRIBUTORS BE  LIABLE FOR ANY DIRECT, INDIRECT,    */
/*    INCIDENTAL,  SPECIAL, EXEMPLARY,  OR  CONSEQUENTIAL DAMAGES    */
/*    (INCLUDING, BUT  NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE    */
/*    GOODS  OR  SERVICES; LOSS  OF  USE,  DATA,  OR PROFITS;  OR    */
/*    BUSINESS INTERRUPTION) HOWEVER CAUSED  AND ON ANY THEORY OF    */
/*    LIABILITY, WHETHER  IN CONTRACT, STRICT  LIABILITY, OR TORT    */
/*    (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY WAY OUT    */
/*    OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF ADVISED  OF  THE    */
/*    POSSIBILITY OF SUCH DAMAGE.                                    */
/*                                                                   */
/* The views and conclusions contained in the software and           */
/* documentation are those of the authors and should not be          */
/* interpreted as representing official policies, either expressed   */
/* or implied, of The University of Texas at Austin.                 */
/*********************************************************************/

#include "WebkitPixelStreamer.h"

#include <QtWebKit/QWebFrame>
#include <QtWebKit/QWebView>
#include <QtWebKit/QWebElement>
#include <QKeyEvent>

#include <QTimer>

#include "log.h"

#define WEPPAGE_DEFAULT_WIDTH   1280
#define WEBPAGE_DEFAULT_HEIGHT  1024
#define WEBPAGE_DEFAULT_ZOOM    2.0
#define WEPPAGE_MIN_WIDTH   (WEPPAGE_DEFAULT_WIDTH/2)
#define WEBPAGE_MIN_HEIGHT  (WEBPAGE_DEFAULT_HEIGHT/2)

WebkitPixelStreamer::WebkitPixelStreamer(QString uri)
    : LocalPixelStreamer(uri)
    , webView_(0)
    , timer_(0)
    , frameIndex_(0)
{
    webView_ = new QWebView();
    webView_->page()->setViewportSize( QSize( WEPPAGE_DEFAULT_WIDTH*WEBPAGE_DEFAULT_ZOOM, WEBPAGE_DEFAULT_HEIGHT*WEBPAGE_DEFAULT_ZOOM ));
    webView_->setZoomFactor(WEBPAGE_DEFAULT_ZOOM);

    QWebSettings* settings = webView_->settings();
    settings->setAttribute( QWebSettings::AcceleratedCompositingEnabled, true );
    settings->setAttribute( QWebSettings::FrameFlatteningEnabled, true );
    settings->setAttribute( QWebSettings::JavascriptEnabled, true );
    settings->setAttribute( QWebSettings::PluginsEnabled, true );
#if QT_VERSION >= 0x040800
    settings->setAttribute( QWebSettings::WebGLEnabled, true );
#endif

    timer_ = new QTimer();
    connect(timer_, SIGNAL(timeout()), this, SLOT(update()));
    timer_->start(30);
}

WebkitPixelStreamer::~WebkitPixelStreamer()
{
    timer_->stop();
    delete timer_;
    delete webView_;
}

void WebkitPixelStreamer::setUrl(QString url)
{
    QMutexLocker locker(&mutex_);

    webView_->load( QUrl(url) );
}

void WebkitPixelStreamer::updateInteractionState(InteractionState interactionState)
{
    QMutexLocker locker(&mutex_);

    QWebPage* page = webView_->page();

    int x = interactionState.mouseX*page->viewportSize().width();
    int y = interactionState.mouseY*page->viewportSize().height();

    x = std::max(0, std::min(x, page->viewportSize().width()-1));
    y = std::max(0, std::min(y, page->viewportSize().height()-1));

    int dx = interactionState.dx*page->viewportSize().width();
    int dy = interactionState.dy*page->viewportSize().height();

    QPoint pointerPos(x, y);
    QWebFrame *pFrame = page->frameAt(pointerPos);

    if (interactionState.type == InteractionState::EVT_CLICK)
    {
        // History navigation (until swipe gestures are fixed)
        if (interactionState.mouseX < 0.02)
        {
            webView_->back();
            return;
        }
        else if (interactionState.mouseX > 0.98)
        {
            webView_->forward();
            return;
        }

        QWebHitTestResult hitResult = pFrame->hitTestContent(pointerPos);

        if ( !hitResult.isNull() )
        {
            if (!hitResult.linkUrl().isEmpty())
            {
                webView_->load(hitResult.linkUrl());
            }
            else
            {
                hitResult.element().evaluateJavaScript("this.click()");

                if (hitResult.isContentEditable())
                {
                    hitResult.element().setFocus();
                    // Ugly hack to work around a focus problem: some input fields receive
                    // focus yet key events are still directed to a different INPUT field..
                    if (hitResult.element().tagName()== "INPUT")
                        hitResult.element().evaluateJavaScript("this.value = this.value");
                }
            }
        }
    }

    else if (interactionState.type == InteractionState::EVT_MOVE || interactionState.type == InteractionState::EVT_WHEEL)
    {
        pFrame->scroll(-dx,-dy);
    }

    else if (interactionState.type == InteractionState::EVT_SWIPE_LEFT)
    {
        webView_->back();
    }
    else if (interactionState.type == InteractionState::EVT_SWIPE_RIGHT)
    {
        webView_->forward();
    }

    else if (interactionState.type == InteractionState::EVT_KEY_PRESS)
    {
        QKeyEvent myEvent(QEvent::KeyPress, interactionState.key,
                          (Qt::KeyboardModifiers)interactionState.modifiers,
                          QString::fromStdString(interactionState.text)
                          );
        page->event(&myEvent);
    }
    else if (interactionState.type == InteractionState::EVT_KEY_RELEASE)
    {
        QKeyEvent myEvent(QEvent::KeyRelease, interactionState.key,
                          (Qt::KeyboardModifiers)interactionState.modifiers,
                          QString::fromStdString(interactionState.text)
                          );
        page->event(&myEvent);
    }

    else if (interactionState.type == InteractionState::EVT_VIEW_SIZE_CHANGED)
    {
        QSize newSize( std::max((int)interactionState.dx, WEPPAGE_MIN_WIDTH), std::max((int)interactionState.dy, WEBPAGE_MIN_HEIGHT) );

        double zoomFactor = (double)newSize.width() / (double)WEPPAGE_DEFAULT_WIDTH;

        webView_->page()->setViewportSize( newSize );
        webView_->setZoomFactor(zoomFactor);
    }
}

QSize WebkitPixelStreamer::size() const
{
    return webView_->page()->viewportSize();
}

void WebkitPixelStreamer::update()
{
    QMutexLocker locker(&mutex_);

    QWebPage* page = webView_->page();
    if( !page->viewportSize().isEmpty())
    {
        if (image_.size() != page->viewportSize())
            image_ = QImage( page->viewportSize(), QImage::Format_ARGB32 );

        QPainter painter( &image_ );
        page->mainFrame()->render( &painter );
        painter.end();

        PixelStreamSegment segment;
        segment.parameters = makeSegmentHeader();

        segment.imageData = QByteArray::fromRawData((const char*)image_.bits(), image_.byteCount());
        segment.imageData.detach();

        ++frameIndex_;

        emit segmentUpdated(uri_, segment);
    }
}

PixelStreamSegmentParameters WebkitPixelStreamer::makeSegmentHeader()
{
    PixelStreamSegmentParameters parameters;

    parameters.sourceIndex = 0;
    parameters.frameIndex = frameIndex_;

    parameters.totalHeight = webView_->page()->viewportSize().height();
    parameters.totalWidth = webView_->page()->viewportSize().width();

    parameters.height = parameters.totalHeight;
    parameters.width = parameters.totalWidth;

    parameters.x = 0;
    parameters.y = 0;

    parameters.compressed = false;

    return parameters;
}
<|endoftext|>


<commit_before>/*
  Copyright (C) 2013 Jolla Ltd.
  Contact: Thomas Perl <thomas.perl@jollamobile.com>
  All rights reserved.

  You may use this file under the terms of BSD license as follows:

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the Jolla Ltd nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifdef QT_QML_DEBUG
#include <QtQuick>
#endif

#include <sailfishapp.h>

int main(int argc, char *argv[])
{
    // SailfishApp::main() will display "qml/template.qml", if you need more
    // control over initialization, you can use:
    //
    //   - SailfishApp::application(int, char *[]) to get the QGuiApplication *
    //   - SailfishApp::createView() to get a new QQuickView * instance
    //   - SailfishApp::pathTo(QString) to get a QUrl to a resource file
    //
    // To display the view, call "show()" (will show fullscreen on device).

    return SailfishApp::main(argc, argv);
}

<commit_msg>Delete WorkingHoursTracker.cpp<commit_after><|endoftext|>


<commit_before>#include <color.hpp>
#include <converter.hpp>
#include <color.cpp>

#include "Texture.h"
#include "DebugLog.h"
#include "volume.hpp"

#include <chrono>
#include <iostream>

#include <windows.h>
#include <direct.h>
#include <Commdlg.h>
#include <Shellapi.h>

using namespace std;

const int SCREEN_WIDTH = 1280;
const int SCREEN_HEIGHT = 1024;

Texture* texture;

void raycast(const string &fname)
{
	Shader computeShader("Shaders\\raycast.glsl");
	glUseProgram(computeShader.program);

	glBindImageTexture(0, texture->textureId, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F);

	Volume volume(fname);
	const uint64_t volumeSize = sizeof(float) * volume.info.volume();
	header info = volume.info;

	GLuint buffer;
	glGenBuffers(1, &buffer);

	glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer);
	glBufferData(GL_SHADER_STORAGE_BUFFER, volumeSize * 4, volume.data, GL_DYNAMIC_COPY);
	glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, buffer);

	glUniform1f(glGetUniformLocation(computeShader.program, "eyePosition"), -500.0f);
	glUniform1f(glGetUniformLocation(computeShader.program, "monitorPosition"), 0.0f);
	glUniform2i(glGetUniformLocation(computeShader.program, "screen"), SCREEN_WIDTH, SCREEN_HEIGHT);
	glUniform3i(glGetUniformLocation(computeShader.program, "size"), static_cast<GLint>(info.x), static_cast<GLint>(info.y), static_cast<GLint>(info.z));
	glUniform3f(glGetUniformLocation(computeShader.program, "d"), info.d.x, info.d.y, info.d.z);
	glUniform3f(glGetUniformLocation(computeShader.program, "min"), info.min.x, info.min.y, info.min.z);
	glUniform3f(glGetUniformLocation(computeShader.program, "max"), info.max.x, info.max.y, info.max.z);

	const auto start = chrono::high_resolution_clock::now();

	glDispatchCompute(SCREEN_WIDTH, SCREEN_HEIGHT, 1);
	glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);

	const auto end = chrono::high_resolution_clock::now();

	const auto total = chrono::duration<double, milli>(end - start).count();
	cout << "time: " << total << "ms" << endl;

	glDeleteBuffers(1, &buffer);
}

void chooseAndDrawImage(int id)
{
	OPENFILENAME ofn;
	char fileName[MAX_PATH];

	ZeroMemory(&ofn, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = NULL;
	ofn.lpstrFile = fileName;
	ofn.lpstrFile[0] = '\0';
	ofn.nMaxFile = sizeof(fileName);
	ofn.lpstrFilter = "All\0*.*\0.txt\0*.TXT\0.vd\0*.VD\0\0";
	ofn.nFilterIndex = 1;
	ofn.lpstrFileTitle = NULL;
	ofn.nMaxFileTitle = 0;
	ofn.lpstrInitialDir = NULL;
	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

	char CWD[MAX_PATH];
	_getcwd(CWD, MAX_PATH);
	GetOpenFileName(&ofn);
	_chdir(CWD);

	string s(fileName);

	if (id != 0) {
		switch (id) {
		case 1:
			convert<color_ha>(s); break;
		case 2:
			convert<color_rgba>(s); break;
		}

		s += ".vd";
	}

	raycast(s);
}

void display()
{
	glClear(GL_COLOR_BUFFER_BIT);
	glClearColor(.7f, .0f, 1.f, 1.f);

	texture->draw();

	glFlush();
}

void init(int argc, char* argv[])
{
	glutInit(&argc, argv);
	glutInitContextVersion(3, 3);
	glutInitContextProfile(GLUT_CORE_PROFILE);
	glutInitDisplayMode(GLUT_RGBA);
	glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT);
	glutCreateWindow("Volume Ray Casting");

	glutDisplayFunc(display);

	if (glewInit())
	{
		cerr << "Unable to initialize GLEW" << endl;
		exit(EXIT_FAILURE);
	}

#ifdef _DEBUG
	glEnable(GL_DEBUG_OUTPUT);
	glDebugMessageCallback(debugCallback, NULL);
	glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);
	std::cout << "OpenGL Debug enabled" << std::endl;
#endif
}

void menu(int id)
{
	chooseAndDrawImage(id);
	glutPostRedisplay();
}

void createMenu()
{
	int menuId = glutCreateMenu(menu);
	glutAddMenuEntry("Open converted file", 0);
	glutAddMenuEntry("Convert and open ha", 1);
	glutAddMenuEntry("Convert and open rgba", 2);
	glutAttachMenu(GLUT_LEFT_BUTTON);
}

int main(int argc, char* argv[])
{
	init(argc, argv);

	createMenu();

	Shader shader("Shaders\\vertex.glsl", "Shaders\\fragment.glsl");
	texture = new Texture(SCREEN_WIDTH, SCREEN_HEIGHT, shader.program);

	glutMainLoop();

	delete texture;

	return 0;
}<commit_msg>Add check - if file wasn't selected<commit_after>#include <color.hpp>
#include <converter.hpp>
#include <color.cpp>

#include "Texture.h"
#include "DebugLog.h"
#include "volume.hpp"

#include <chrono>
#include <iostream>

#include <windows.h>
#include <direct.h>
#include <Commdlg.h>
#include <Shellapi.h>

using namespace std;

const int SCREEN_WIDTH = 1280;
const int SCREEN_HEIGHT = 1024;

Texture* texture;

void raycast(const string &fname)
{
	Shader computeShader("Shaders\\raycast.glsl");
	glUseProgram(computeShader.program);

	glBindImageTexture(0, texture->textureId, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F);

	Volume volume(fname);
	const uint64_t volumeSize = sizeof(float) * volume.info.volume();
	header info = volume.info;

	GLuint buffer;
	glGenBuffers(1, &buffer);

	glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer);
	glBufferData(GL_SHADER_STORAGE_BUFFER, volumeSize * 4, volume.data, GL_DYNAMIC_COPY);
	glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, buffer);

	glUniform1f(glGetUniformLocation(computeShader.program, "eyePosition"), -500.0f);
	glUniform1f(glGetUniformLocation(computeShader.program, "monitorPosition"), 0.0f);
	glUniform2i(glGetUniformLocation(computeShader.program, "screen"), SCREEN_WIDTH, SCREEN_HEIGHT);
	glUniform3i(glGetUniformLocation(computeShader.program, "size"), static_cast<GLint>(info.x), static_cast<GLint>(info.y), static_cast<GLint>(info.z));
	glUniform3f(glGetUniformLocation(computeShader.program, "d"), info.d.x, info.d.y, info.d.z);
	glUniform3f(glGetUniformLocation(computeShader.program, "min"), info.min.x, info.min.y, info.min.z);
	glUniform3f(glGetUniformLocation(computeShader.program, "max"), info.max.x, info.max.y, info.max.z);

	const auto start = chrono::high_resolution_clock::now();

	glDispatchCompute(SCREEN_WIDTH, SCREEN_HEIGHT, 1);
	glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);

	const auto end = chrono::high_resolution_clock::now();

	const auto total = chrono::duration<double, milli>(end - start).count();
	cout << "time: " << total << "ms" << endl;

	glDeleteBuffers(1, &buffer);
}

void chooseAndDrawImage(int id)
{
	OPENFILENAME ofn;
	char fileName[MAX_PATH];

	ZeroMemory(&ofn, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = NULL;
	ofn.lpstrFile = fileName;
	ofn.lpstrFile[0] = '\0';
	ofn.nMaxFile = sizeof(fileName);
	ofn.lpstrFilter = "All\0*.*\0.txt\0*.TXT\0.vd\0*.VD\0\0";
	ofn.nFilterIndex = 1;
	ofn.lpstrFileTitle = NULL;
	ofn.nMaxFileTitle = 0;
	ofn.lpstrInitialDir = NULL;
	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

	char CWD[MAX_PATH];
	_getcwd(CWD, MAX_PATH);
	GetOpenFileName(&ofn);
	_chdir(CWD);

	string s(fileName);

	if (s.empty()) {
		return;
	}

	if (id != 0) {
		switch (id) {
		case 1:
			convert<color_ha>(s); break;
		case 2:
			convert<color_rgba>(s); break;
		}

		s += ".vd";
	}

	raycast(s);
}

void display()
{
	glClear(GL_COLOR_BUFFER_BIT);
	glClearColor(.7f, .0f, 1.f, 1.f);

	texture->draw();

	glFlush();
}

void init(int argc, char* argv[])
{
	glutInit(&argc, argv);
	glutInitContextVersion(3, 3);
	glutInitContextProfile(GLUT_CORE_PROFILE);
	glutInitDisplayMode(GLUT_RGBA);
	glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT);
	glutCreateWindow("Volume Ray Casting");

	glutDisplayFunc(display);

	if (glewInit())
	{
		cerr << "Unable to initialize GLEW" << endl;
		exit(EXIT_FAILURE);
	}

#ifdef _DEBUG
	glEnable(GL_DEBUG_OUTPUT);
	glDebugMessageCallback(debugCallback, NULL);
	glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);
	std::cout << "OpenGL Debug enabled" << std::endl;
#endif
}

void menu(int id)
{
	chooseAndDrawImage(id);
	glutPostRedisplay();
}

void createMenu()
{
	int menuId = glutCreateMenu(menu);
	glutAddMenuEntry("Open converted file", 0);
	glutAddMenuEntry("Convert and open ha", 1);
	glutAddMenuEntry("Convert and open rgba", 2);
	glutAttachMenu(GLUT_LEFT_BUTTON);
}

int main(int argc, char* argv[])
{
	init(argc, argv);

	createMenu();

	Shader shader("Shaders\\vertex.glsl", "Shaders\\fragment.glsl");
	texture = new Texture(SCREEN_WIDTH, SCREEN_HEIGHT, shader.program);

	glutMainLoop();

	delete texture;

	return 0;
}<|endoftext|>


<commit_before>/*
Register system for console games by Sreyas

*/
// global vars
int data_size, _logined = 0, _connected = 0,
               P_INDEX; // saving data size in a var is much more optimised than use tellg()
// global functions
void Register();

void Login();

void Save();

void connect();

// class for storing player data

class P_DATA
{
public:
    char name[24], password[24];
    int pscore;

    P_DATA()
    {
        pscore = 0;
    }

    void P_GET()
    {
        cout << "Input your name ";
        gets(name);
        cout << "Input password ";
        gets(password);
    }

    ~P_DATA()
    {
    }
};

////////////////////////////////////////////////////////////////////////////
<commit_msg>Update register.cpp<commit_after>/*

☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä
*    MIT License
*
*     Copyright (c) 2016 Sreyas
*
*     Permission is hereby granted, free of charge, to any person obtaining a copy
*     of this software and associated documentation files (the "Software"), to deal
*     in the Software without restriction, including without limitation the rights
*     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
*     copies of the Software, and to permit persons to whom the Software is
*     furnished to do so, subject to the following conditions:
*
*     The above copyright notice and this permission notice shall be included in all
*     copies or substantial portions of the Software.
*
*     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
*     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
*     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
*     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
*     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
*     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
*     SOFTWARE.
*
//☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä☻☻☻Ä
|||Register system for console games by Sreyas||||||||||||

*/
// global vars
int data_size, _logined = 0, _connected = 0,
               P_INDEX; // saving data size in a var is much more optimised than use tellg()
// global functions
void Register();

void Login();

void Save();

void connect();

// class for storing player data

class P_DATA
{
public:
    char name[24], password[24];
    int pscore;

    P_DATA()
    {
        pscore = 0;
    }

    void P_GET()
    {
        cout << "Input your name ";
        gets(name);
        cout << "Input password ";
        gets(password);
    }

    ~P_DATA()
    {
    }
};

////////////////////////////////////////////////////////////////////////////
<|endoftext|>