/*
    ORPP Client

    (C) 2005 Jason Hunt

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

    Contact: huntjas2@msu.edu

    Compile with -lwsock32

    FILE: mouse.cpp
    
    Deal with mouse
    
*/

#include <windows.h>

#pragma hdrstop

#include "display.h"
#include "network.h"
#include "mouse.h"

bool camera_mouse = false; // true if the camera follows the mouse

/* handle mouse movement */
void process_mouse( LPARAM lParam )
{
    if (!camera_mouse) return;

    unsigned int pos_x = lParam & 0xffff; // decode position
    unsigned int pos_y = lParam >> 16; 
     
    // range check

    if (pos_x < 0) pos_x = 0;
    if (pos_x > display_x - 1) pos_x = display_x - 1;

    if (pos_y < 0) pos_y = 0;
    if (pos_y > display_y - 1) pos_y = display_y - 1;
     
    // scale into servo pos
    pan = 255 - (unsigned char)((255 / double(display_x)) * pos_x);
    tilt = 255 - (unsigned char)((255 / double(display_y)) * pos_y);

    if (window_active)
        send_controller_values();
}
/* end of process_mouse */

