comparison src/video/photon/SDL_ph_mouse.c @ 283:3d8b6b9f1e18

Date: Mon, 18 Feb 2002 16:46:59 +1200 From: Julian Kinraid <jkinraid@clear.net.nz> Subject: Patches for photon port of SDL Hi, A couple more patches for photon and the nto audio. Adds mouse grabbing support, fixed cursor images, unicode keyboard events (though no unicode data on kye release, is that a problem?), hopefully fixing some audio lag problems, and a few other fixes. Thanks, Julian Kinraid
author Sam Lantinga <slouken@libsdl.org>
date Wed, 20 Feb 2002 01:05:51 +0000
parents c6abdda2f666
children f6ffac90895c
comparison
equal deleted inserted replaced
282:b42d80e73896 283:3d8b6b9f1e18
60 WMcursor *ph_CreateWMCursor(_THIS, 60 WMcursor *ph_CreateWMCursor(_THIS,
61 Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y) 61 Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
62 { 62 {
63 WMcursor* cursor; 63 WMcursor* cursor;
64 int clen, i; 64 int clen, i;
65 unsigned char bit, databit, maskbit;
65 66
66 /* Allocate and initialize the cursor memory */ 67 /* Allocate and initialize the cursor memory */
67 if ((cursor = (WMcursor*)malloc(sizeof(WMcursor))) == NULL) 68 if ((cursor = (WMcursor*)malloc(sizeof(WMcursor))) == NULL)
68 { 69 {
69 SDL_OutOfMemory(); 70 SDL_OutOfMemory();
70 return(NULL); 71 return(NULL);
71 } 72 }
72 memset(cursor,0,sizeof(WMcursor)); 73 memset(cursor,0,sizeof(WMcursor));
73 74
74 cursor->ph_cursor = (PhCursorDef_t *) malloc(sizeof(PhCursorDef_t) + 32*4*2); 75 cursor->ph_cursor = (PhCursorDef_t *) malloc(sizeof(PhCursorDef_t) + 32*4*2);
75 if(cursor->ph_cursor == NULL) 76 if(cursor->ph_cursor == NULL)
76 printf("cursor malloc failed\n"); 77 printf("cursor malloc failed\n");
77 78
78 memset(cursor->ph_cursor,0,(sizeof(PhCursorDef_t) + 32*4*2)); 79 memset(cursor->ph_cursor,0,(sizeof(PhCursorDef_t) + 32*4*2));
79 80
80 cursor->ph_cursor->hdr.type =Ph_RDATA_CURSOR; 81 cursor->ph_cursor->hdr.type =Ph_RDATA_CURSOR;
81 cursor->ph_cursor->size1.x = (short)w; 82 cursor->ph_cursor->size1.x = (short)w;
82 cursor->ph_cursor->size1.y = (short)h; 83 cursor->ph_cursor->size1.y = (short)h;
83 cursor->ph_cursor->offset1.x = (short)hot_x; 84 cursor->ph_cursor->offset1.x = (short)hot_x;
84 cursor->ph_cursor->offset1.y = (short)hot_y; 85 cursor->ph_cursor->offset1.y = (short)hot_y;
88 cursor->ph_cursor->size2.y = (short)h; 89 cursor->ph_cursor->size2.y = (short)h;
89 cursor->ph_cursor->offset2.x = (short)hot_x; 90 cursor->ph_cursor->offset2.x = (short)hot_x;
90 cursor->ph_cursor->offset2.y = (short)hot_y; 91 cursor->ph_cursor->offset2.y = (short)hot_y;
91 cursor->ph_cursor->bytesperline2 = (char)w/8; 92 cursor->ph_cursor->bytesperline2 = (char)w/8;
92 cursor->ph_cursor->color2 = Pg_BLACK; 93 cursor->ph_cursor->color2 = Pg_BLACK;
93 94
94 clen = (w/8)*h; 95 clen = (w/8)*h;
95 96
96 /* Copy the mask and the data to different 97 /* Copy the mask and the data to different
97 bitmap planes */ 98 bitmap planes */
98 for ( i=0; i<clen; ++i ) 99 for ( i=0; i<clen; ++i )
99 { 100 {
100 cursor->ph_cursor->images[i] = data[i]; 101 for ( bit = 0; bit < 8; bit++ )
101 cursor->ph_cursor->images[i+clen] = mask[i]; 102 {
102 } 103 databit = data[i] & (1 << bit);
103 104 maskbit = mask[i] & (1 << bit);
104 //#bytes following the hdr struct 105
106 cursor->ph_cursor->images[i] |=
107 (databit == 0) ? maskbit : 0;
108 /* If the databit != 0, treat it as a black pixel and
109 * ignore the maskbit (can't do an inverted color) */
110 cursor->ph_cursor->images[i+clen] |= databit;
111 }
112 }
113
114 /* #bytes following the hdr struct */
105 cursor->ph_cursor->hdr.len =sizeof(PhCursorDef_t) + clen*2 - sizeof(PhRegionDataHdr_t); 115 cursor->ph_cursor->hdr.len =sizeof(PhCursorDef_t) + clen*2 - sizeof(PhRegionDataHdr_t);
106 116
107 return (cursor); 117 return (cursor);
108 } 118 }
109 119
110 120
111 PhCursorDef_t ph_GetWMPhCursor(WMcursor *cursor) 121 PhCursorDef_t ph_GetWMPhCursor(WMcursor *cursor)
112 { 122 {
113 return(*cursor->ph_cursor); 123 return(*cursor->ph_cursor);
114 } 124 }
115
116 125
117 int ph_ShowWMCursor(_THIS, WMcursor *cursor) 126 int ph_ShowWMCursor(_THIS, WMcursor *cursor)
118 { 127 {
119 PtArg_t args[3]; 128 PtArg_t args[3];
120 int nargs = 0; 129 int nargs = 0;
128 /* Set the photon cursor cursor, or blank if cursor is NULL */ 137 /* Set the photon cursor cursor, or blank if cursor is NULL */
129 if ( window ) { 138 if ( window ) {
130 139
131 if ( cursor != NULL ) { 140 if ( cursor != NULL ) {
132 PtSetArg( &args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0 ); 141 PtSetArg( &args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0 );
133 // Could set next to any PgColor_t value 142 /* Could set next to any PgColor_t value */
134 PtSetArg( &args[1], Pt_ARG_CURSOR_COLOR,Ph_CURSOR_DEFAULT_COLOR , 0 ); 143 PtSetArg( &args[1], Pt_ARG_CURSOR_COLOR,Ph_CURSOR_DEFAULT_COLOR , 0 );
135 PtSetArg( &args[2], Pt_ARG_BITMAP_CURSOR, cursor->ph_cursor, (cursor->ph_cursor->hdr.len + sizeof(PhRegionDataHdr_t)) ); 144 PtSetArg( &args[2], Pt_ARG_BITMAP_CURSOR, cursor->ph_cursor, (cursor->ph_cursor->hdr.len + sizeof(PhRegionDataHdr_t)) );
136 nargs = 3; 145 nargs = 3;
137 cursor_is_defined = 1; 146 cursor_is_defined = 1;
138 } 147 }
139 else // Ph_CURSOR_NONE 148 else /* Ph_CURSOR_NONE */
140 { 149 {
141 PtSetArg( &args[0], Pt_ARG_CURSOR_TYPE,Ph_CURSOR_NONE, 0); 150 PtSetArg( &args[0], Pt_ARG_CURSOR_TYPE,Ph_CURSOR_NONE, 0);
142 nargs = 1; 151 nargs = 1;
143 cursor_is_defined = 1; 152 cursor_is_defined = 1;
144 } 153 }
159 return(1); 168 return(1);
160 } 169 }
161 170
162 void ph_WarpWMCursor(_THIS, Uint16 x, Uint16 y) 171 void ph_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
163 { 172 {
164 SDL_Lock_EventThread(); 173 short abs_x, abs_y;
165 PhMoveCursorRel( PhInputGroup(NULL), x, y ); 174
166 SDL_Unlock_EventThread(); 175 SDL_Lock_EventThread();
176 PtGetAbsPosition( window, &abs_x, &abs_y );
177 PhMoveCursorAbs( PhInputGroup(NULL), x + abs_x, y + abs_y );
178 SDL_Unlock_EventThread();
167 } 179 }
168 180
169 181
170 void ph_CheckMouseMode(_THIS) 182 void ph_CheckMouseMode(_THIS)
171 { 183 {
172 mouse_relative = 1; 184 /* If the mouse is hidden and input is grabbed, we use relative mode */
185 if ( !(SDL_cursorstate & CURSOR_VISIBLE) &&
186 (this->input_grab != SDL_GRAB_OFF) ) {
187 mouse_relative = 1;
188 } else {
189 mouse_relative = 0;
190 }
173 } 191 }