void WindowInputSource::handleRawInput(WPARAM wParam, LPARAM lParam)
{
	// Only process input when the application is on the foreground.
	if (wParam != RIM_INPUT)
		return;

	RAWINPUT input;
	UINT szData = sizeof(input), szHeader = sizeof(RAWINPUTHEADER);
	HRAWINPUT handle = reinterpret_cast<HRAWINPUT>(lParam);

	UINT bytesWritten = 
		GetRawInputData(handle, RID_INPUT, &input, &szData, szHeader);

	ASSERT(bytesWritten <= szData, "Unexpected return value from GetRawInputData.");
	ASSERT(bytesWritten != UINT(-1), "GetRawInputData returned error.");

	switch (input.header.dwType)
	{
		case RIM_TYPEMOUSE:
			mouseInput(input.data.mouse);
			break;
		case RIM_TYPEKEYBOARD:
			keyboardInput(input.data.keyboard);
			break;
	}
}
Beispiel #2
0
void clip_cs_menu() {
    cleardevice();
    outtext((char*)"Click and drag mouse to define rectangular clipping region");

    mouseInput(x1, y1, x2, y2);

    Point2D pMin(std::min(x1,x2), std::min(y1,y2)), pMax(std::max(x1,x2), std::max(y1,y2));
    std::vector<Point2D> rect;
    rect.push_back(pMin); rect.push_back(Point2D(pMin.x, pMax.y));
    rect.push_back(pMax); rect.push_back(Point2D(pMax.x, pMin.y));

    cleardevice();

    mypoly(rect);
    outtext((char*)"Click and drag mouse to make lines to be clipped, right click to EXIT");
    clearmouseclick(WM_RBUTTONDOWN);

    while(!ismouseclick(WM_RBUTTONDOWN)) {
        Point2D p1, p2;
        mouseLine(p1, p2);

        setcolor(RED);
        myline(p1, p2);

        setcolor(WHITE);
        clip_line_cs(pMin, pMax, p1, p2);
    }
}
Beispiel #3
0
void pendulum_menu() {
    cleardevice();
    outtext((char*)"Click and drag mouse to define anchor point and starting point for pendulum");
    do {
        mouseInput(x1, y1, x2, y2);
        if (y2 < y1)
            outtextxy(0, 20, (char*)"Please choose an anchor point higher than the starting point of pendulum");
    }while(y2 < y1);
    int l = (int) (sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)) + 0.5);
    Point2D a(x1, y1);
    float ang = atanf(((float)(x2-x1))/(y2-y1));
    cleardevice();
    pendulum(ang, l, a, 25);
}
Beispiel #4
0
int main( void )
{
	//debug:: lets find the path
#ifdef CRAP_COMPILER_MSVC
	crap::string256 data_path("../../../data/");
#else
	crap::string256 data_path("../data/");
#endif

	//logger
    crap::logger< crap::log_time_time, crap::log_channel_core, crap::log_type_debug, crap::log_target_cout, 512 > unit_logger;

    //system
    crap::System system;

	//lets config
	crap::string256 ini_path = data_path + "configuration.ini";
	crap::Configuration config( 1024*10, 100 );

	config.load( ini_path.c_str() );

	//set config as subsystem
	crap::SubSystem config_sys( "Configuration", &config, &system );

	//taskmanager
	const uint32_t tasksMaxNumber = config.getValue<uint32_t>("TASKS_MAX_NUM");
	const uint32_t tasksDeattachedMaxNumber = config.getValue<uint32_t>("TASKS_DEATTACHED_MAX_NUM");
	crap::TaskManager taskManager( tasksMaxNumber, tasksDeattachedMaxNumber );

	//set TaskManager as Subsystem
	crap::SubSystem tasks_sys( "TaskManager", &taskManager, &system );

	//eventsystem
	const uint32_t eventMaxNumber = config.getValue<uint32_t>("EVENTS_MAX_NUM");
	crap::EventSystem eventSystem( eventMaxNumber );

	//set EventSystem as SubSystem
	crap::SubSystem events_sys( "EventSystem", &eventSystem, &system );

	//resourcemanager
	const uint32_t resoureMemory = config.getValue<uint32_t>("RESOURCE_MEMORY");
	const uint32_t resoureNumber = config.getValue<uint32_t>("RESOURCE_NUMBER");
	const crap::string64 resourceFile = config.getValue<crap::string64>("RESOURCE_FILE");
	const bool resourceXML = config.getValue<uint32_t>("RESOURCE_XML") == 1;

	crap::ResourceManager resourceManager( resoureMemory, resoureNumber, data_path, &system );
	if( resourceXML )
		resourceManager.loadXML( resourceFile );
	else
		resourceManager.loadPackage( resourceFile );

	// set resourcemanager as subsystem
	crap::SubSystem resource_sys( "ResourceManager", &resourceManager, &system );

	//AudioSystem
	const uint32_t audioBufferNumber = config.getValue<uint32_t>("AUDIO_BUFFER_NUM");
	const uint32_t audioSourceNumber = config.getValue<uint32_t>("AUDIO_SOURCE_NUM");
	crap::AudioSystem AudioSystem(audioBufferNumber, audioSourceNumber);

	//set AudioSystem as subsystem
	crap::SubSystem audio_sys( "AudioSystem", &AudioSystem, &system );

	//componentsystem
	const uint32_t componentMemory = config.getValue<uint32_t>("COMPONENT_MEMORY");
	const uint32_t componentMaxNodes = config.getValue<uint32_t>("COMPONENT_MAX_NODES");
	crap::ComponentSystem componentSystem( componentMemory, componentMaxNodes , &system );

	//set componentsystem as subsystem
	crap::SubSystem component_sys( "ComponentSystem", &componentSystem, &system );

	//renderwindow
	const crap::string64 windowName = config.getValue<crap::string64>("RENDER_WINDOW_NAME");
	const uint32_t windowWidth = config.getValue<uint32_t>("RENDER_WINDOW_WIDTH");
	const uint32_t windowHeight = config.getValue<uint32_t>("RENDER_WINDOW_HEIGHT");
	const bool windowFullscreen = config.getValue<uint32_t>("RENDER_WINDOW_FULLSCREEN") == 1;
	const uint32_t windowMaxCallbacks = config.getValue<uint32_t>("RENDER_WINDOW_MAX_CALLBACKS");
	crap::RenderWindow renderWindow( windowMaxCallbacks );
	renderWindow.create( windowName.c_str(), windowWidth, windowHeight, windowFullscreen );

	//renderer
	crap::RenderSystem renderer( &renderWindow );
	renderer.init();

	//set renderer as subsystem
	crap::SubSystem renderer_sys("Renderer", &renderer, &system );

	//inputmanager
	const uint32_t inputMemory = config.getValue<uint32_t>("INPUT_MEMORY");
	crap::InputManager inputManager( inputMemory, renderWindow.getHandle() );

	//add keyboard
	crap::KeyboardInput keyboardInput("Keyboard", 20, &inputManager );
	keyboardInput.addListener<&exitFunc>( thekey, 0, true );

	//add mouse
	crap::MouseInput mouseInput("Mouse", 20, 20, 20, 20, &inputManager );
	mouseInput.addButtonListener<&clickFunc>( 0, 0, true );
	mouseInput.addPositionListener<&posFunc>( true );
	mouseInput.addScrollListener<&scrollFunc>( true );
	mouseInput.addEnterListener<&enterFunc>( true );

	//controller
	crap::ControllerInput controllerInput("Controller", 8, &inputManager );
	uint32_t joyID = controllerInput.leaseJoystickID();
	controllerInput.addAxisListener<&joyAxis>( joyID );
	controllerInput.addButtonListener<&joyButton>( joyID );

	/* Add directory update to taskmanager */
	taskManager.addTask<crap::InputManager, &crap::InputManager::update>("InputPolling", &inputManager, 50, true, false );

	/* Physic system 2D */
	crap::PhysicSystem2D physicSystem2D( 1000, 0.f, 10.f, 8, 2, 1.f/200.f );
	crap::SubSystem physic_sys2d( "PhysicSystem2D", &physicSystem2D, &system );

	taskManager.addTask< crap::PhysicSystem2D, &crap::PhysicSystem2D::update>( "Physic2DUpdate", &physicSystem2D, 20, true, false );

	//pluginmanager
	const uint32_t pluginNumber = config.getValue<uint32_t>("PLUGIN_NUMBER");
	const uint32_t pluginMemory = config.getValue<uint32_t>("PLUGIN_MEMORY");
	crap::PluginManager pluginManager(pluginNumber, pluginMemory, &system );

	//set pluginmanager as subsystem
	crap::SubSystem plugin_sys( "PluginManager", &pluginManager, &system );

	//set Directory listener
	const uint32_t pluginFunctionNumber = config.getValue<uint32_t>("PLUGIN_FUNCTION_NUM");
	const uint32_t pluginFileNumber = config.getValue<uint32_t>("PLUGIN_FILES_NUM");
	const crap::string256 pluginDir = data_path + config.getValue<crap::string64>("PLUGIN_SUBDIRECTORY");
	crap::DirectoryListener pluginDirectoryListener( pluginFunctionNumber, pluginFileNumber, pluginDir, false );
	pluginDirectoryListener.addCallback<crap::PluginManager, &crap::PluginManager::callbackFunction>( &pluginManager );

	/* Add directory update to taskmanager */
	taskManager.addTask<crap::DirectoryListener, &crap::DirectoryListener::update>("PluginPath", &pluginDirectoryListener, 1000, true, false );

	//init this.. (do that at last)
	pluginDirectoryListener.init();

	crap::Configuration* testconf = system.getSubSystem<crap::Configuration>( "Configuration" );
	if( testconf != 0 )
	{
		std::cout << "I've worked! " << testconf->getValue<crap::string64>("SOUND_VOLUME") << std::endl;
	}

	float32_t zero[3] = {0.f, 0.f, 0.f};
	float32_t one[3] = {1.f, 1.f, 1.f};
	float32_t dir[6] = {0.f, 0.f, 1.f, 0.f, 1.f, 0.f };

	crap::AudioSystem* am = system.getSubSystem<crap::AudioSystem>( "AudioSystem" );

	resourceManager.loadResource( "Nagut" );
	uint32_t sid = am->leaseSource( "Nagut" );

	am->setListenerData( zero, zero, dir );
	am->playSource( sid );

//	while( am->getIsPlaying(sid) )
//		crap::sleep_mil_sec(100);

	crap::log( LOG_CHANNEL_CORE | LOG_TYPE_INFO | LOG_TARGET_COUT, "We're done!" );

	crap::Renderer2D renderer2D( &renderWindow, 10, 10, 100 );
	crap::SubSystem renderer2d_sys( "Renderer2D", &renderer2D, &system );

	crap::Context2D* gc = renderer2D.getContext();
	resourceManager.loadResource( "Hasi" );
	resourceManager.loadResource( "Mieze" );
	uint32_t guiImage = renderer2D.getImage2D("Hasi");
	uint32_t guiImage2 = renderer2D.getImage2D("Mieze");

	resourceManager.loadResource("CalcFont");
	crap::Font2D font2d = renderer2D.getFont2D("CalcFont");

	crap::Node* cnode = componentSystem.createNode();
	crap::Component* trans2d = componentSystem.createComponent("Attributes2D", cnode );
	componentSystem.setComponentMember( trans2d, "posX", "600" );
	componentSystem.setComponentMember( trans2d, "posY", "600" );
	componentSystem.setComponentMember( trans2d, "rotation", "20" );
	componentSystem.setComponentMember( trans2d, "scale", "1.f" );
	trans2d->init( &system );


	crap::color_argb colorf;
	colorf.r = 0;
	colorf.b = 0;
	colorf.g = 255;
	colorf.a = 128;

	crap::color_argb colorb;

	//black
	colorb.r = 0;
	colorb.b = 0;
	colorb.g = 0;
	colorb.a = 255;

	crap::color_argb col = crap::argb::black;

	crap::string64 colstr("AABBCCDD");
	uint32_t lolali = strtol("AABBCCDD", 0, 16 );
	crap::color_argb colorino = crap::convert<crap::string64, crap::color_argb>( colstr );

	crap::string64 popo = crap::convert<crap::color_argb, crap::string64>( crap::argb::orange );

	crap::string64 buff = crap::convert<crap::color_argb, crap::string64>(colorf);
	crap::string64 bufb = crap::convert<crap::color_argb, crap::string64>(colorb);

	crap::Component* circle2d = componentSystem.createComponent("RoundedRectangle2D", cnode );

	componentSystem.setComponentMember( circle2d, "width", "150" );
	componentSystem.setComponentMember( circle2d, "height", "200" );
	componentSystem.setComponentMember( circle2d, "corner", "20" );
	componentSystem.setComponentMember( circle2d, "color", buff );
	componentSystem.setComponentMember( circle2d, "border", "5" );
	componentSystem.setComponentMember( circle2d, "borderColor", bufb );

	circle2d->init(&system);

	crap::Node* tnode = componentSystem.createNode();


	crap::Component* trans2dt = componentSystem.createComponent("Attributes2D", tnode );
	componentSystem.setComponentMember( trans2dt, "posX", "200" );
	componentSystem.setComponentMember( trans2dt, "posY", "600" );
	componentSystem.setComponentMember( trans2dt, "rotation", "0" );
	componentSystem.setComponentMember( trans2dt, "scale", "1.f" );
	trans2d->init( &system );

	crap::Component* text2d = componentSystem.createComponent("Text2D", tnode );
	componentSystem.setComponentMember( text2d, "fontName", "CalcFont" );
	componentSystem.setComponentMember( text2d, "text", "Hallo ich bin ein Test" );
	componentSystem.setComponentMember( text2d, "fontSize", "50" );
	componentSystem.setComponentMember( text2d, "color", bufb );
	componentSystem.setComponentMember( text2d, "blur", "1" );

	text2d->init(&system);

	//physic test
	crap::Node* pnode = componentSystem.createNode();
	crap::Component* ptrans2d = componentSystem.createComponent("Attributes2D", pnode );
	componentSystem.setComponentMember( ptrans2d, "posX", "770" );
	componentSystem.setComponentMember( ptrans2d, "posY", "550" );
	componentSystem.setComponentMember( ptrans2d, "rotation", "-0.3f" );
	componentSystem.setComponentMember( ptrans2d, "scale", "1.f" );

	crap::Component* rect2d = componentSystem.createComponent("Rectangle2D", pnode );
	componentSystem.setComponentMember( rect2d, "width", "300" );
	componentSystem.setComponentMember( rect2d, "height", "50" );
	componentSystem.setComponentMember( rect2d, "color", buff );
	componentSystem.setComponentMember( rect2d, "border", "0" );
	componentSystem.setComponentMember( rect2d, "borderColor", bufb );

	crap::Component* phys2d = componentSystem.createComponent("Rectangle2DPhysic", pnode );
	componentSystem.setComponentMember( phys2d, "width", "300" );
	componentSystem.setComponentMember( phys2d, "height", "50" );
	componentSystem.setComponentMember( phys2d, "density", "1.f" );
	componentSystem.setComponentMember( phys2d, "friction", "1.f" );
	componentSystem.setComponentMember( phys2d, "dynamic", "0" );

	ptrans2d->init(&system);
	rect2d->init(&system);
	phys2d->init(&system);

	//solid
	crap::Node* pnode2 = componentSystem.createNode();
	crap::Component* ptrans2d2 = componentSystem.createComponent("Attributes2D", pnode2 );
	componentSystem.setComponentMember( ptrans2d2, "posX", "550" );
	componentSystem.setComponentMember( ptrans2d2, "posY", "400" );
	componentSystem.setComponentMember( ptrans2d2, "rotation", "0.2" );
	componentSystem.setComponentMember( ptrans2d2, "scale", "1.f" );

	crap::Component* rect2d2 = componentSystem.createComponent("Rectangle2D", pnode2 );
	componentSystem.setComponentMember( rect2d2, "width", "300" );
	componentSystem.setComponentMember( rect2d2, "height", "50" );
	componentSystem.setComponentMember( rect2d2, "color", bufb );
	componentSystem.setComponentMember( rect2d2, "border", "0" );
	componentSystem.setComponentMember( rect2d2, "borderColor", bufb );

	crap::Component* phys2d2 = componentSystem.createComponent("Rectangle2DPhysic", pnode2 );
	componentSystem.setComponentMember( phys2d2, "width", "300" );
	componentSystem.setComponentMember( phys2d2, "height", "50" );
	componentSystem.setComponentMember( phys2d2, "density", "1.f" );
	componentSystem.setComponentMember( phys2d2, "friction", "1.f" );
	componentSystem.setComponentMember( phys2d2, "dynamic", "0" );

	ptrans2d2->init(&system);
	rect2d2->init(&system);
	phys2d2->init(&system);

	//circle
	crap::Node* pnode3 = componentSystem.createNode();
	crap::Component* ptrans2d3 = componentSystem.createComponent("Attributes2D", pnode3 );
	componentSystem.setComponentMember( ptrans2d3, "posX", "600" );
	componentSystem.setComponentMember( ptrans2d3, "posY", "50" );
	componentSystem.setComponentMember( ptrans2d3, "rotation", "0" );
	componentSystem.setComponentMember( ptrans2d3, "scale", "1.f" );

	crap::Component* rect2d3 = componentSystem.createComponent("Circle2D", pnode3 );
	componentSystem.setComponentMember( rect2d3, "radius", "20" );
	componentSystem.setComponentMember( rect2d3, "color", "FF0080FF" );
	componentSystem.setComponentMember( rect2d3, "border", "0" );
	componentSystem.setComponentMember( rect2d3, "borderColor", "FF0000F" );

	crap::Component* phys2d3 = componentSystem.createComponent("Cirlce2DPhysic", pnode3 );
	componentSystem.setComponentMember( phys2d3, "radius", "20" );
	componentSystem.setComponentMember( phys2d3, "density", "1.f" );
	componentSystem.setComponentMember( phys2d3, "friction", "1.f" );
	componentSystem.setComponentMember( phys2d3, "dynamic", "1" );

	ptrans2d3->init(&system);
	rect2d3->init(&system);
	phys2d3->init(&system);

	crap::color_argb bord;
	bord.value = 0;
	float32_t rot = 0.f;
	while( running && !renderWindow.shouldClose() )
	{
		renderer.drawBegin();
		renderer2D.drawBegin();
//		crap::drawColoredRectangle( gc, 100.f, 100.f, 100.f, 100.f, -rot*0.1, 255, 0, 255, 255 );
//		//crap::drawColoredCircle( gc, 500.f, (int32_t)(rot*100) % renderWindow.getHeight(), 50.f, 255, 0, 0, 255 );
//		rot += 0.1f;
//		crap::drawColoredRoundedRectangle( gc, 150.f, 150.f, 200.f, 200.f, rot, 0, 0, 255, 128, 20.f );
//
//		crap::drawColorTriangle( gc, 400, 400, 140, 100, 0.f, 0, 255, 0, 255 );
//
//		crap::drawImageRectangle( gc, (int32_t)(rot*10) % renderWindow.getWidth(), 400, 100, 100, rot*0.1, guiImage, 100.f, 100.f, 0.f, 0.f, 0.f, 1.f );
//
//		crap::drawImageCircle( gc, 600, 200, 50, guiImage2, 255, 100.f, 100.f, 0.f, -10,10-rot*2, 0.3f);
//
//		crap::drawText(gc, 400, 400, font2d, "Hallo, du Welt.", 30.f ,0.f , 0, 255, 0, 255, 0, 1, 10.f, crap::align::left);

		bord.value++;
		bord.value %= 100;
		componentSystem.setComponentMember( circle2d, "corner", crap::convert<crap::color_argb, crap::string64>(bord) );
		componentSystem.setComponentMember( text2d, "fontSize", "100" );

		renderer2D.render();

		renderer2D.drawEnd();
		renderer.drawEnd();
		//renderWindow.swap();
		taskManager.update();
	}

	renderer2D.removeImage2D( "Mieze" );
	renderer2D.removeImage2D( "Hasi" );

	renderWindow.destroy();

#ifdef CRAP_COMPILER_MSVC
//    std::cout << "Press a button" << std::endl;
//	getchar();
#endif

	pluginDirectoryListener.removeCallback<crap::PluginManager, &crap::PluginManager::callbackFunction>( &pluginManager );
	pluginManager.unloadAll();

	return 0;
}