added a relative mode to a window. Currently only does anything in osx

This commit is contained in:
Zachary Pavlov 2006-11-03 02:33:22 +00:00
parent eeacc3fb26
commit f6e37779e4
6 changed files with 160 additions and 3 deletions

View File

@ -43,3 +43,8 @@ INLINE bool GraphicsWindow::
is_fullscreen() const {
return _properties.get_fullscreen();
}

View File

@ -634,6 +634,25 @@ set_properties_now(WindowProperties &properties) {
// Fullscreen property specified, but unchanged.
properties.clear_fullscreen();
}
if (properties.has_mouse_mode() ) {
if (properties.get_mouse_mode() == _properties.get_mouse_mode()) {
properties.clear_mouse_mode();
}
else {
if(properties.get_mouse_mode() == WindowProperties::MOUSE_absolute) {
_properties.set_mouse_mode(WindowProperties::MOUSE_absolute);
mouse_mode_absolute();
properties.clear_mouse_mode();
}
else
{
_properties.set_mouse_mode(WindowProperties::MOUSE_relative);
mouse_mode_relative();
properties.clear_mouse_mode();
}
}
}
}
////////////////////////////////////////////////////////////////////
@ -778,3 +797,25 @@ parse_color_mask(const string &word) {
return result;
}
////////////////////////////////////////////////////////////////////
// Function: GraphicsWindow::mouse_mode_relative
// Access: Protected, Virtual
// Description: detaches mouse. Only mouse delta from now on.
//
////////////////////////////////////////////////////////////////////
void GraphicsWindow::
mouse_mode_relative() {
}
////////////////////////////////////////////////////////////////////
// Function: GraphicsWindow::mouse_mode_absolute
// Access: Protected, Virtual
// Description: reattaches mouse to location
//
////////////////////////////////////////////////////////////////////
void GraphicsWindow::
mouse_mode_absolute() {
}

View File

@ -71,6 +71,7 @@ PUBLISHED:
string get_input_device_name(int device) const;
bool has_pointer(int device) const;
bool has_keyboard(int device) const;
MouseData get_pointer(int device) const;
virtual bool move_pointer(int device, int x, int y);
@ -102,6 +103,9 @@ protected:
virtual bool do_reshape_request(int x_origin, int y_origin, bool has_origin,
int x_size, int y_size);
virtual void mouse_mode_absolute();
virtual void mouse_mode_relative();
// It is an error to call any of the following methods from any
// thread other than the window thread.
void system_changed_properties(const WindowProperties &properties);
@ -109,7 +113,7 @@ protected:
private:
static unsigned int parse_color_mask(const string &word);
protected:
typedef vector_GraphicsWindowInputDevice InputDevices;
InputDevices _input_devices;

View File

@ -701,8 +701,54 @@ clear_z_order() {
_z_order = Z_normal;
}
////////////////////////////////////////////////////////////////////
// Function: WindowProperties::set_mouse_mode
// Access: Published
// Description: Removes the z_order specification from the properties.
////////////////////////////////////////////////////////////////////
INLINE void WindowProperties::
set_mouse_mode(MouseMode mode) {
_mouse_mode=mode;
_specified |= S_mouse_mode;
}
////////////////////////////////////////////////////////////////////
// Function: WindowProperties::get_mouse_mode
// Access: Published
// Description: Removes the z_order specification from the properties.
////////////////////////////////////////////////////////////////////
INLINE WindowProperties::MouseMode WindowProperties::
get_mouse_mode() const {
return _mouse_mode;
}
////////////////////////////////////////////////////////////////////
// Function: WindowProperties::has_moude_mode
// Access: Published
// Description: Removes the z_order specification from the properties.
////////////////////////////////////////////////////////////////////
INLINE bool WindowProperties::
has_mouse_mode() const {
return ((_specified & S_mouse_mode)!=0);
}
////////////////////////////////////////////////////////////////////
// Function: WindowProperties::clear_mouse_mode
// Access: Published
// Description: Removes the z_order specification from the properties.
////////////////////////////////////////////////////////////////////
INLINE void WindowProperties::
clear_mouse_mode() {
_specified &= ~S_mouse_mode;
_mouse_mode=MOUSE_absolute;
}
INLINE ostream &
operator << (ostream &out, const WindowProperties &properties) {
properties.output(out);
return out;
}

View File

@ -47,6 +47,7 @@ operator = (const WindowProperties &copy) {
_cursor_filename = copy._cursor_filename;
_z_order = copy._z_order;
_flags = copy._flags;
_mouse_mode = copy._mouse_mode;
}
////////////////////////////////////////////////////////////////////
@ -85,7 +86,7 @@ get_default() {
props.set_z_order(z_order);
}
props.set_title(window_title);
props.set_mouse_mode(MOUSE_absolute);
return props;
}
@ -119,7 +120,9 @@ operator == (const WindowProperties &other) const {
_z_order == other._z_order &&
_title == other._title &&
_icon_filename == other._icon_filename &&
_cursor_filename == other._cursor_filename);
_cursor_filename == other._cursor_filename &&
_mouse_mode == other._mouse_mode);
}
////////////////////////////////////////////////////////////////////
@ -141,6 +144,7 @@ clear() {
_cursor_filename = Filename();
_z_order = Z_normal;
_flags = 0;
_mouse_mode = MOUSE_absolute;
}
////////////////////////////////////////////////////////////////////
@ -191,6 +195,9 @@ add_properties(const WindowProperties &other) {
if (other.has_z_order()) {
set_z_order(other.get_z_order());
}
if (other.has_mouse_mode()) {
set_mouse_mode(other.get_mouse_mode());
}
}
////////////////////////////////////////////////////////////////////
@ -241,6 +248,9 @@ output(ostream &out) const {
if (has_z_order()) {
out << get_z_order() << " ";
}
if (has_mouse_mode()) {
out << get_mouse_mode() << " ";
}
}
ostream &
@ -281,3 +291,36 @@ operator >> (istream &in, WindowProperties::ZOrder &z_order) {
return in;
}
//
// MouseMode operators
//
ostream &
operator << (ostream &out, WindowProperties::MouseMode mode) {
switch (mode) {
case WindowProperties::MOUSE_absolute:
return out << "absolute";
case WindowProperties::MOUSE_relative:
return out << "relative";
}
return out << "**invalid WindowProperties::MouseMode(" << (int)mode << ")**";
}
istream &
operator >> (istream &in, WindowProperties::MouseMode &mode) {
string word;
in >> word;
if (word == "absolute") {
mode = WindowProperties::MOUSE_absolute;
} else if (word == "relative") {
mode = WindowProperties::MOUSE_relative;
} else {
display_cat.warning()
<< "Unknown mouse mode: " << word << "\n";
mode = WindowProperties::MOUSE_absolute;
}
return in;
}

View File

@ -37,6 +37,11 @@ PUBLISHED:
Z_normal,
Z_top,
};
enum MouseMode {
MOUSE_absolute,
MOUSE_relative,
};
WindowProperties();
INLINE WindowProperties(const WindowProperties &copy);
@ -64,6 +69,11 @@ PUBLISHED:
INLINE bool has_size() const;
INLINE void clear_size();
INLINE bool has_mouse_mode() const;
INLINE void set_mouse_mode(MouseMode mode);
INLINE MouseMode get_mouse_mode() const;
INLINE void clear_mouse_mode();
INLINE void set_title(const string &title);
INLINE const string &get_title() const;
INLINE bool has_title() const;
@ -141,6 +151,7 @@ private:
S_z_order = 0x0400,
S_icon_filename = 0x0800,
S_cursor_filename = 0x1000,
S_mouse_mode = 0x2000,
};
// This bitmask represents the true/false settings for various
@ -161,6 +172,7 @@ private:
int _y_origin;
int _x_size;
int _y_size;
MouseMode _mouse_mode;
string _title;
Filename _cursor_filename;
Filename _icon_filename;
@ -173,6 +185,12 @@ operator << (ostream &out, WindowProperties::ZOrder z_order);
EXPCL_PANDA istream &
operator >> (istream &in, WindowProperties::ZOrder &z_order);
EXPCL_PANDA ostream &
operator << (ostream &out, WindowProperties::MouseMode mode);
EXPCL_PANDA istream &
operator >> (istream &in, WindowProperties::MouseMode &mode);
INLINE ostream &operator << (ostream &out, const WindowProperties &properties);
#include "windowProperties.I"