void mouse_draw( INSTANCE * i, REGION * clip ) { int r ; REGION region; r = GLOINT32( libmouse, MOUSEREGION ) ; if ( r < 0 || r > 31 ) r = 0 ; region = regions[r]; if ( clip ) region_union( ®ion, clip ); if ( GLOINT32( libmouse, MOUSEANGLE ) || GLOINT32( libmouse, MOUSESIZE ) != 100 ) gr_rotated_blit( 0, ®ion, GLOINT32( libmouse, MOUSEX ), GLOINT32( libmouse, MOUSEY ), GLODWORD( libmouse, MOUSEFLAGS ), GLOINT32( libmouse, MOUSEANGLE ), GLOINT32( libmouse, MOUSESIZE ), GLOINT32( libmouse, MOUSESIZE ), mouse_map ) ; else gr_blit( 0, ®ion, GLOINT32( libmouse, MOUSEX ), GLOINT32( libmouse, MOUSEY ), GLODWORD( libmouse, MOUSEFLAGS ), mouse_map ) ; mouse_map->modified = 0; }
int gr_text_new( int fontid, int x, int y, int alignment, const char * text ) { return gr_text_new2( fontid, x, y, GLOINT32( libtext, TEXTZ ), alignment, text ); }
static int check_collision_with_mouse( INSTANCE * proc1, int colltype ) { REGION bbox1, bbox2 ; int x, y, mx, my ; static GRAPH * bmp = NULL; switch ( colltype ) { case COLLISION_BOX: case COLLISION_CIRCLE: if ( !get_bbox( &bbox2, proc1 ) ) return 0 ; case COLLISION_NORMAL: break; default: return 0; } mx = GLOINT32( mod_grproc, MOUSEX ) ; my = GLOINT32( mod_grproc, MOUSEY ) ; /* Checks the process's bounding box to optimize checking (only for screen-type objects) */ if ( LOCDWORD( mod_grproc, proc1, CTYPE ) == C_SCREEN ) { switch ( colltype ) { case COLLISION_NORMAL: if ( !get_bbox( &bbox2, proc1 ) ) return 0 ; if ( bbox2.x > mx || bbox2.x2 < mx || bbox2.y > my || bbox2.y2 < my ) return 0 ; break; case COLLISION_BOX: if ( bbox2.x <= mx && bbox2.x2 >= mx && bbox2.y <= my && bbox2.y2 >= my ) return 1; return 0; break; case COLLISION_CIRCLE: { int cx1, cy1, dx1, dy1; cx1 = bbox2.x + ( dx1 = ( bbox2.x2 - bbox2.x + 1 ) ) / 2 ; cy1 = bbox2.y + ( dy1 = ( bbox2.y2 - bbox2.y + 1 ) ) / 2 ; if ( get_distance( cx1, cy1, 0, mx, my, 0 ) < ( dx1 + dy1 ) / 4 ) return 1; return 0; break; } } } /* Creates a temporary bitmap (only once) */ if ( colltype == COLLISION_NORMAL ) { /* maybe must force this to 32 bits */ if ( bmp && bmp->format->depth != sys_pixel_format->depth ) { bitmap_destroy( bmp ); bmp = NULL; } if ( !bmp ) bmp = bitmap_new( 0, 2, 1, sys_pixel_format->depth ) ; if ( !bmp ) return 0 ; memset( bmp->data, 0, bmp->pitch * bmp->height ) ; } /* Retrieves process information */ bbox1.x = 0 ; bbox1.x2 = 1 ; bbox1.y = 0 ; bbox1.y2 = 0 ; x = LOCINT32( mod_grproc, proc1, COORDX ) ; y = LOCINT32( mod_grproc, proc1, COORDY ) ; RESOLXY( mod_grproc, proc1, x, y ); /* Scroll-type process: check for each region */ if ( LOCDWORD( mod_grproc, proc1, CTYPE ) == C_SCROLL ) { SCROLL_EXTRA_DATA * data; scrolldata * scroll; int i; if ( GLOEXISTS( mod_grproc, SCROLLS ) ) { int cnumber = LOCDWORD( mod_grproc, proc1, CNUMBER ); if ( !cnumber ) cnumber = 0xffffffff ; for ( i = 0 ; i < 10 ; i++ ) { data = &(( SCROLL_EXTRA_DATA * ) & GLODWORD( mod_grproc, SCROLLS ) )[i] ; scroll = ( scrolldata * ) data->reserved[0]; if ( scroll && scroll->active && ( cnumber & ( 1 << i ) ) ) { REGION * r = scroll->region; switch ( colltype ) { case COLLISION_NORMAL: if ( r->x > mx || r->x2 < mx || r->y > my || r->y2 < my ) continue; draw_at( bmp, x + r->x - mx - scroll->posx0, y + r->y - my - scroll->posy0, &bbox1, proc1 ); switch ( sys_pixel_format->depth ) { case 8: if ( *( uint8_t * )bmp->data ) return 1; break; case 16: if ( *( uint16_t * )bmp->data ) return 1; break; case 32: if ( *( uint32_t * )bmp->data ) return 1; break; } break; case COLLISION_BOX: if ( bbox2.x <= scroll->posx0 + r->x + mx && bbox2.x2 >= scroll->posx0 + r->x + mx && bbox2.y <= scroll->posy0 + r->y + my && bbox2.y2 >= scroll->posy0 + r->y + my ) return 1; break; case COLLISION_CIRCLE: { int cx1, cy1, dx1, dy1; cx1 = bbox2.x + ( dx1 = ( bbox2.x2 - bbox2.x + 1 ) ) / 2 ; cy1 = bbox2.y + ( dy1 = ( bbox2.y2 - bbox2.y + 1 ) ) / 2 ; if ( get_distance( cx1, cy1, 0, r->x + mx + scroll->posx0, r->y + my + scroll->posy0, 0 ) < ( dx1 + dy1 ) / 4 ) return 1; break; } } } } } return 0; } switch ( colltype ) { case COLLISION_NORMAL: /* Collision check (blits into temporary space and checks the resulting pixel) */ draw_at( bmp, x - mx, y - my, &bbox1, proc1 ) ; switch ( sys_pixel_format->depth ) { case 8: if ( *( uint8_t * )bmp->data ) return 1; break; case 16: if ( *( uint16_t * )bmp->data ) return 1; break; case 32: if ( *( uint32_t * )bmp->data ) return 1; break; } break; case COLLISION_BOX: if ( bbox2.x <= mx && bbox2.x2 >= mx && bbox2.y <= my && bbox2.y2 >= my ) return 1; break; case COLLISION_CIRCLE: { int cx1, cy1, dx1, dy1; cx1 = bbox2.x + ( dx1 = ( bbox2.x2 - bbox2.x + 1 ) ) / 2 ; cy1 = bbox2.y + ( dy1 = ( bbox2.y2 - bbox2.y + 1 ) ) / 2 ; if ( get_distance( cx1, cy1, 0, mx, my, 0 ) < ( dx1 + dy1 ) / 4 ) return 1; break; } } return 0 ; }
void __bgdexport( libmouse, module_initialize )() #endif { gr_new_object( GLOINT32( libmouse, MOUSEZ ), mouse_info, mouse_draw, 0 ); }
int mouse_info( INSTANCE * i, REGION * clip, int * z, int * drawme ) { int mousex ; int mousey ; int mousez ; int mousefile ; int mousegraph ; int mouseangle; int mousesize; int mouseflags; int mouseregion; int changed; * z = mousez = GLOINT32( libmouse, MOUSEZ ); mousefile = GLODWORD( libmouse, MOUSEFILE ); mousegraph = GLODWORD( libmouse, MOUSEGRAPH ); mouse_map = ( mousegraph > 0 ) ? bitmap_get( mousefile, mousegraph ) : NULL ; if ( !mouse_map ) { * drawme = 0; /* clip->x = clip->x2 = -2; clip->y = clip->y2 = -2; */ return 0; } mousex = GLOINT32( libmouse, MOUSEX ); mousey = GLOINT32( libmouse, MOUSEY ); // mousez = GLODWORD( libmouse, MOUSEZ ); mouseangle = GLOINT32( libmouse, MOUSEANGLE ); mousesize = GLOINT32( libmouse, MOUSESIZE ); mouseflags = GLODWORD( libmouse, MOUSEFLAGS ); mouseregion = GLOINT32( libmouse, MOUSEREGION ); * drawme = 1; changed = ( mouse_map && mouse_map->modified ) || last_mousex != mousex || last_mousey != mousey || last_mousez != mousez || last_mousefile != mousefile || last_mousegraph != mousegraph || last_mouseangle != mouseangle || last_mousesize != mousesize || last_mouseflags != mouseflags || last_mouseregion != mouseregion || ( mouse_map->ncpoints && ( last_mousecenterx != mouse_map->cpoints[0].x || last_mousecentery != mouse_map->cpoints[0].y ) ) ; if ( changed ) { last_mousex = mousex ; last_mousey = mousey ; last_mousez = mousez ; last_mousefile = mousefile ; last_mousegraph = mousegraph ; last_mouseangle = mouseangle ; last_mousesize = mousesize ; last_mouseflags = mouseflags ; last_mouseregion = mouseregion ; if ( mouse_map->ncpoints ) { last_mousecenterx = mouse_map->cpoints[0].x; last_mousecentery = mouse_map->cpoints[0].y; } else { last_mousecenterx = CPOINT_UNDEFINED; last_mousecentery = CPOINT_UNDEFINED; } gr_get_bbox( clip, 0, mousex, mousey, mouseflags, mouseangle , mousesize , mousesize , mouse_map ) ; } return changed; }
void do_mouse_events() { SDL_Event e ; static int last_mouse_x = -1, last_mouse_y = -1 ; /* Update events */ /* Mouse.x/y change affects the cursor directly */ if ( ( last_mouse_x != -1 && GLOINT32( libmouse, MOUSEX ) != last_mouse_x ) || ( last_mouse_y != -1 && GLOINT32( libmouse, MOUSEY ) != last_mouse_y ) ) { if ( scale_resolution != 0 ) { SDL_WarpMouse( GLOINT32( libmouse, MOUSEX ) / ( (double)screen->w / (double)scale_screen->w ), GLOINT32( libmouse, MOUSEY ) / ( (double)screen->h / (double)scale_screen->h ) ) ; } else if ( enable_scale || scale_mode != SCALE_NONE ) { SDL_WarpMouse( GLOINT32( libmouse, MOUSEX ) * 2 , GLOINT32( libmouse, MOUSEY ) * 2 ) ; } else { SDL_WarpMouse( GLOINT32( libmouse, MOUSEX ), GLOINT32( libmouse, MOUSEY ) ) ; } } /* Process the independant mouse events */ GLODWORD( libmouse, MOUSEWHEELUP ) = 0 ; GLODWORD( libmouse, MOUSEWHEELDOWN ) = 0 ; while ( SDL_PeepEvents( &e, 1, SDL_GETEVENT, SDL_MOUSEEVENTMASK ) > 0 ) { switch ( e.type ) { case SDL_MOUSEMOTION: if ( scale_resolution != 0 ) { GLOINT32( libmouse, MOUSEX ) = e.motion.x * ( (double)screen->w / (double)scale_screen->w ); GLOINT32( libmouse, MOUSEY ) = e.motion.y * ( (double)screen->h / (double)scale_screen->h ); } else if ( enable_scale || scale_mode != SCALE_NONE ) { GLOINT32( libmouse, MOUSEX ) = e.motion.x / 2 ; GLOINT32( libmouse, MOUSEY ) = e.motion.y / 2 ; } else { GLOINT32( libmouse, MOUSEX ) = e.motion.x ; GLOINT32( libmouse, MOUSEY ) = e.motion.y ; } break ; case SDL_MOUSEBUTTONDOWN: if ( e.button.button == SDL_BUTTON_LEFT ) GLODWORD( libmouse, MOUSELEFT ) = 1 ; if ( e.button.button == SDL_BUTTON_MIDDLE ) GLODWORD( libmouse, MOUSEMIDDLE ) = 1 ; if ( e.button.button == SDL_BUTTON_RIGHT ) GLODWORD( libmouse, MOUSERIGHT ) = 1 ; if ( e.button.button == SDL_BUTTON_WHEELUP ) GLODWORD( libmouse, MOUSEWHEELUP )++ ; if ( e.button.button == SDL_BUTTON_WHEELDOWN ) GLODWORD( libmouse, MOUSEWHEELDOWN )++ ; break ; case SDL_MOUSEBUTTONUP: if ( e.button.button == SDL_BUTTON_LEFT ) GLODWORD( libmouse, MOUSELEFT ) = 0 ; if ( e.button.button == SDL_BUTTON_MIDDLE ) GLODWORD( libmouse, MOUSEMIDDLE ) = 0 ; if ( e.button.button == SDL_BUTTON_RIGHT ) GLODWORD( libmouse, MOUSERIGHT ) = 0 ; break ; } } last_mouse_x = GLOINT32( libmouse, MOUSEX ) ; last_mouse_y = GLOINT32( libmouse, MOUSEY ) ; }