Example #1
0
void GameMouseButtonUp( const NimblePoint& point, int k ) {
	if( VisibleDialog ) {
		switch( Dialog::action a = VisibleDialog->mouseUp(point) ) {
			case Dialog::update:
				if( VisibleDialog==&TheGeologyDialog )
					CreateNewArea(/*recycle=*/true);
				else if( VisibleDialog==&TheShotDialog )
#if 0
					// Show example of shot
					GameKeyDown(' ');
#else
					(void)0;
#endif
				break;
			case Dialog::hide:
				VisibleDialog = NULL;
				break;
			default:
				break;
		}
	}
	for( Clickable** c=ClickableSet; c!=ClickableSetEnd; ++c ) 
	    (*c)->mouseUp(point);
}
Example #2
0
LRESULT CALLBACK WindowProc(HWND hwnd,
						    UINT msg, 
                            WPARAM wparam, 
                            LPARAM lparam)
{                       
    // this is the main message handler of the system
    PAINTSTRUCT	ps;		   // used in WM_PAINT
    HDC			hdc;	   // handle to a device context

    // what is the message
    switch(msg) {
        case WM_LBUTTONDOWN:
		case WM_LBUTTONUP: {
			NimblePoint p;
 	        p.x = (int)LOWORD(lparam);
		    p.y = (int)HIWORD(lparam);
	    	if( msg==WM_LBUTTONDOWN )
                GameMouseButtonDown( p, 0 );
            else
                GameMouseButtonUp( p, 0 );
            break;
		}
        case WM_MOUSELEAVE:
            RequestedTrackMouseEvent = false;
            HostShowCursor(true);
            break;

		case WM_MOUSEMOVE: {

            if (!RequestedTrackMouseEvent) {
                // First time mouse entered my window:
                // Request leave notification
                TRACKMOUSEEVENT tme;
                tme.cbSize = sizeof(tme);
                tme.hwndTrack = hwnd;
                tme.dwFlags = TME_LEAVE;
                TrackMouseEvent(&tme);
                RequestedTrackMouseEvent = true;
            }

	        NimblePoint p;
			p.x = (int)LOWORD(lparam);
		    p.y = (int)HIWORD(lparam);
	    	GameMouseMove( p );
            break;
		}
	    case WM_CREATE:
		    // Do initialization stuff here
		    return 0;

        case WM_PAINT:
            // Start painting
            hdc = BeginPaint(hwnd,&ps);

            // End painting
            EndPaint(hwnd,&ps);
            return 0;
        
        case WM_MOVE:
    	    return 0;
    	
	    case WM_SIZE:
		    // Extract new window size
		    // Round to multiple of four, because some of our loop unrollings depend upon such.
		    WindowWidth = RoundAndClip(LOWORD(lparam));
		    WindowHeight = HIWORD(lparam);
		    ResizeOrMove = true;
		    return 0;
		
	    case WM_COMMAND:
		    break;

	    case WM_DESTROY:
		    // Kill the application
		    PostQuitMessage(0);
	    	return 0;

		case WM_CHAR: {
 			if( GameKeyDown(wparam) )
				PostMessage(hwnd, WM_DESTROY,0,0);
			return 0;
		}
    	default:
            break;

    } // end switch

    // Process any messages that we didn't take care of
    return (DefWindowProc(hwnd, msg, wparam, lparam));

} // end WinProc
Example #3
0
void kol_main()
{

	BoardPuts("Hello, Heliothryx!\n");
	
	int    err;
    int    version =-1;
 
    if((err = InitSound(&version)) !=0 ){
        BoardPuts("Sound Error 1\n");
    };
 
    if( (SOUND_VERSION>(version&0xFFFF)) ||
        (SOUND_VERSION<(version >> 16))){
        BoardPuts("Sound Error 2\n");
    }


	unsigned event;
	unsigned key;
	unsigned key_up;
	
	unsigned btn, btn_state;	
	unsigned pos, x, y;
	int gx, gy;

	//srand(kol_system_time_get());

	kol_event_mask(0xC0000027); // mouse and keyboard
	
	kol_key_mode_set(1);
	
	area_width = 512;
	area_height = 512;

	// Initializing variables
	window_width = FIX_MENUETOS_LEGACY_ONE_PIXEL_BORDER_GAP_BUG + area_width + 10; // 2 x 5px border
	window_height = FIX_MENUETOS_LEGACY_ONE_PIXEL_BORDER_GAP_BUG + kol_skin_height() + area_height + 5; // bottom 5px border

	//rs_main_init();
	
	GameInit();

	wnd_draw();

	fps = 0;
	
	unsigned int tick_start = kol_time_tick();
	unsigned int tick_current = tick_start;
	unsigned int tick_last = tick_start;
	
	unsigned int fps_counter = 0;
	int wait_time;
	int already_drawn = 0;
	
	float xf; 
	float xfs;
	int xfs_i;
	
	while (1) {
		tick_last = tick_current;
		tick_current = kol_time_tick();
		dt = tick_current - tick_last;
		tick_last = tick_current;
		
		already_drawn = 0;
		
		while (( event = kol_event_wait_time(1) )) {
		//while (( event = kol_event_wait() )) {  
		
			switch (event) {
		
				case 1:
					wnd_draw(); // <--- need to clear event!
					already_drawn = 1;
					break;

				case 2:
					key = kol_key_get();
					key = (key & 0xff00)>>8;	
					key_up = key & 0x80;				
					key = key & 0x7F;
					
					if (key_up) {
						GameKeyUp(key);
						//rs_app.OnKeyUp(key);
					}
					else {
						GameKeyDown(key);
						//rs_app.OnKeyDown(key, 1);
					};
				
					break;
			
				case 3:
					switch ((kol_btn_get() & 0xff00)>>8)
						{
						case 1: // close button
							kol_exit();
						case 2: // 'new' button 
							//init_board();
							//wnd_draw();
							break;
						}
					break;
			
				case 6:
					btn = kol_mouse_btn() & 1; // read mouse button (only left)
					pos = kol_mouse_posw(); // read mouse position
					x = pos / 65536;
					y = pos % 65536;
					/*if (x > window_width)
						x=0;
					if (y > window_height)
						y=0;*/
						
					if (btn && (!btn_state)) {
						//rs_app.OnMouseDown(x,y);
						GameMouseDown(x, y);
						
						BoardPuts("MouseDown!\n");
						
					}
					else if ( (!btn) && btn_state ) {
						//rs_app.OnMouseUp(x,y);
						GameMouseUp(x, y);
					}
					else {
						//GameMouseMove(x, y);
					};
					
					btn_state = btn;
				
					break;
			}
			
		};
		
		
		if (!already_drawn) {
			wnd_draw();
		};
		
		
		fps_counter++;		
		
		tick_current = kol_time_tick();
		
		if (tick_current > tick_start+100) {
			fps = fps_counter;
			fps_counter = 0;
			tick_start += 100;
		};
	
		draw_dt = tick_current - tick_last;
		
		wait_time = (100/GAME_REQUIRED_FPS) - draw_dt;
		if (wait_time <= 0) {
			wait_time = 1;
		};
		kol_sleep(wait_time);


	}

	GameTerm();

	kol_exit();
}