static pos translate_pos(int x, int y) { return (pos){ .x = floorf((x - PADDING) / (float)font_width ), .y = floorf((y - PADDING) / (float)font_height), }; } static pos get_mouse_pos(LPARAM lp) { return translate_pos(GET_X_LPARAM(lp), GET_Y_LPARAM(lp)); } static mouse_button clicked_button; static pos last_pos; void win_mouse_click(mouse_button b, LPARAM lp) { static mouse_button last_button; static uint last_time, count; static pos last_click_pos; win_show_mouse(); mod_keys mods = get_mods(); pos p = get_mouse_pos(lp); if (clicked_button) { term_mouse_release(b, mods, p); clicked_button = 0; } uint t = GetMessageTime(); if (b != last_button || p.x != last_click_pos.x || p.y != last_click_pos.y || t - last_time > GetDoubleClickTime() || ++count > 3) count = 1; term_mouse_click(b, mods, p, count); last_pos = last_click_pos = p; last_time = t; clicked_button = last_button = b; if (alt_state > ALT_NONE) alt_state = ALT_CANCELLED; } void win_mouse_release(mouse_button b, LPARAM lp) { win_show_mouse(); if (b == clicked_button) { term_mouse_release(b, get_mods(), get_mouse_pos(lp)); clicked_button = 0; ReleaseCapture(); } }
/* parse_leftclick: the mouse was leftclicked */ void parse_leftclick(void) { LIST_ELEMENT *old_selection = selection; if ((mouse_b & 1) && !left_down) { /* mouse clicked */ left_down = 1; if (point_in_rec(get_mouse_pos(), TILE_WIN)) { /* within the TILE_LIST */ selection = list_element_clicked(get_mouse_pos(), tile_elem_lst, tile_elem_lst_sz); if (selection) { /* select in this list and disselect in the other list */ set_pressed_element(selection, tile_elem_lst, tile_elem_lst_sz); set_pressed_element(selection, spr_elem_lst, spr_elem_lst_sz); /*set_mouse_sprite(selection->bmp); */ mode = TILE_MODE; } else { selection = old_selection; old_selection = NULL; } } else if (point_in_rec(get_mouse_pos(), SPRITE_WIN)) { /* within SPRITE_LIST */ selection = list_element_clicked(get_mouse_pos(), spr_elem_lst, spr_elem_lst_sz); if (selection) { /* select in this list and disselect in the other list */ set_pressed_element(selection, spr_elem_lst, spr_elem_lst_sz); set_pressed_element(selection, tile_elem_lst, tile_elem_lst_sz); /*set_mouse_sprite(selection->bmp); */ mode = SPRITE_MODE; } else { selection = old_selection; old_selection = NULL; } } else if (point_in_rec(get_mouse_pos(), MAP_WIN)) { /* mouse clicked on the map! */ parse_leftmouse_on_map(); } else if (point_in_rec(get_mouse_pos(), SPRITE_FRW)) { list_elem_switch_page(1, SPRITE_WIN.y, spr_elem_lst, spr_elem_lst_sz); } else if (point_in_rec(get_mouse_pos(), SPRITE_REW)) { list_elem_switch_page(0, SPRITE_WIN.y, spr_elem_lst, spr_elem_lst_sz); } else if (point_in_rec(get_mouse_pos(), TILE_FRW)) { list_elem_switch_page(1, TILE_WIN.y, tile_elem_lst, tile_elem_lst_sz); } else if (point_in_rec(get_mouse_pos(), TILE_REW)) { list_elem_switch_page(0, TILE_WIN.y, tile_elem_lst, tile_elem_lst_sz); } else { set_mouse_sprite(NULL); } } else if (!(mouse_b & 1) && left_down) { /* reset mouse */ left_down = 0; } }
void win_mouse_click(mouse_button b, LPARAM lp) { static mouse_button last_button; static uint last_time, count; static pos last_click_pos; win_show_mouse(); mod_keys mods = get_mods(); pos p = get_mouse_pos(lp); uint t = GetMessageTime(); if (b != last_button || p.x != last_click_pos.x || p.y != last_click_pos.y || t - last_time > GetDoubleClickTime() || ++count > 3) count = 1; SetFocus(wnd); // in case focus was in search bar term_mouse_click(b, mods, p, count); last_pos = (pos){INT_MIN, INT_MIN}; last_click_pos = p; last_time = t; last_button = b; if (alt_state > ALT_NONE) alt_state = ALT_CANCELLED; }
void win_mouse_release(mouse_button b, LPARAM lp) { if (tab_bar_click(lp)) return; term_mouse_release(win_active_terminal(), b, get_mods(), get_mouse_pos(lp)); ReleaseCapture(); }
void win_mouse_click(mouse_button b, LPARAM lp) { static mouse_button last_button; static uint last_time, count; static pos last_click_pos; win_show_mouse(); if (tab_bar_click(lp)) return; mod_keys mods = get_mods(); pos p = get_mouse_pos(lp); uint t = GetMessageTime(); if (b != last_button || p.x != last_click_pos.x || p.y != last_click_pos.y || t - last_time > GetDoubleClickTime() || ++count > 3) count = 1; term_mouse_click(win_active_terminal(), b, mods, p, count); last_pos = (pos){INT_MIN, INT_MIN}; last_click_pos = p; last_time = t; last_button = b; if (alt_state > ALT_NONE) alt_state = ALT_CANCELLED; }
/* parse_leftmouse_on_map: what happens when we leftclick the map? * Read below!! */ void parse_leftmouse_on_map(void) { POINT p; size_t x, y; p = get_mouse_pos(); if (selection) { x = p.x - (p.x % TILE_W); y = p.y - (p.y % TILE_H) + map_offset; if (mode == TILE_MODE) { /* add the tile as non-passable */ modify_map_coord(x, y, selection->passable, selection->name, 0, 0, maptree); /* we wanna be able to draw on the map without clicking on * each square */ left_down = 0; } else if (mode == SPRITE_MODE) { modify_map_coord(x, y, -1, selection->name, 1, 0, maptree); } } else { /* we should do some fun here :P */ } }
void win_mouse_move(bool nc, LPARAM lp) { pos p = get_mouse_pos(lp); if (p.x == last_pos.x && p.y == last_pos.y) return; last_pos = p; win_show_mouse(); if (!nc) term_mouse_move(clicked_button, get_mods(), p); }
/* get_grid_item: updates the grid_item with fresh data */ void get_grid_item(void) { int x, y; scew_attribute *a = NULL; scew_element *e = NULL; scew_element *sub_e = NULL; scew_element *r = NULL; POINT p; if (!maptree) return; p = get_mouse_pos(); x = p.x - (p.x % TILE_W); y = p.y - (p.y % TILE_H) + map_offset; r = scew_tree_root(maptree); if (mode == TILE_MODE) { e = scew_element_by_name(r, "Tiles"); } else if (mode == SPRITE_MODE) { e = scew_element_by_name(r, "Sprites"); } else return; sub_e = scew_element_next(e, sub_e); while (sub_e) { a = scew_attribute_by_name(sub_e, "x"); if (x == atoi(scew_attribute_value(a))) { a = scew_attribute_by_name(sub_e, "y"); if (y == atoi(scew_attribute_value(a))) { grid_item.x = x; grid_item.y = y; grid_item.mode = mode; a = scew_attribute_by_name(sub_e, "name"); strncpy(grid_item.name, scew_attribute_value(a), NAME_LN); if (mode == TILE_MODE) { a = scew_attribute_by_name(sub_e, "passable"); grid_item.passable = atoi(scew_attribute_value(a)); } else { grid_item.passable = -1; } break; } } sub_e = scew_element_next(e, sub_e); } }
void win_mouse_move(bool nc, LPARAM lp) { if (lp == last_lp) return; win_show_mouse(); pos p = get_mouse_pos(lp); if (nc || (p.x == last_pos.x && p.y == last_pos.y)) return; last_pos = p; term_mouse_move(get_mods(), p); }
void win_mouse_move(bool nc, LPARAM lp) { if (lp == last_lp) return; win_show_mouse(); pos p = get_mouse_pos(lp); if (nc || (p.x == last_pos.x && p.y == last_pos.y)) return; if (p.y < 0) { set_app_cursor(true); } else { win_update_mouse(); } last_pos = p; term_mouse_move(win_active_terminal(), get_mods(), p); }
void mfb_update_with_buffer(void* window_info, void* buffer) { WindowInfo* info = (WindowInfo*)window_info; int width = info->width; int height = info->height; int scale = info->scale; if (info->update && buffer) { switch (scale) { case 1: { memcpy(info->draw_buffer, buffer, width * height * 4); break; } case 2: { scale_2x(info->draw_buffer, buffer, width, height, scale); break; } case 4: { scale_4x(info->draw_buffer, buffer, width, height, scale); break; } } XPutImage(s_display, info->window, s_gc, info->ximage, 0, 0, 0, 0, width, height); XFlush(s_display); } // clear before processing new events if (info->shared_data) { info->shared_data->scroll_x = 0.0f; info->shared_data->scroll_y = 0.0f; } get_mouse_pos(info); process_events(); }
void update_game(float dt) { if (is_key_down('a')) camera.moveLeft(dt); else if (is_key_down('d')) camera.moveRight(dt); if (is_key_down('w')) camera.moveForward(dt); else if (is_key_down('s')) camera.moveBackward(dt); if (is_key_down(SDLK_LCTRL)) camera.moveDown(dt); else if (is_key_down(SDLK_SPACE)) camera.moveUp(dt); if (is_mouse_down(MouseButtonLeft)) { vec2i m = get_mouse_pos(); float dx = (m.x - window_width / 2) / (float)window_width; float dy = (m.y - window_height / 2) / (float)window_height; float speed = 5.0f; camera.rotateHorizontal(speed * sqrt(abs(dx)) * dx * dt); camera.rotateVertical(speed * sqrt(abs(dy)) * dy * dt); } mat_view = camera.getViewMatrix(); float t = get_elapsed_time(); mat_projection = perspective(PI / 4.0f, window_width / float(window_height), 0.2f, 20.0f); //mat_view = translate(0.0f, -0.7f, -2.0f) * rotateX(-0.13f) * rotateY(t); }
void win_mouse_release(mouse_button b, LPARAM lp) { term_mouse_release(b, get_mods(), get_mouse_pos(lp)); ReleaseCapture(); }
/* Purpose: animate and run the game with the clock Input : a char length pointer to the frame buffer and a long length pointer to the frame buffer Returns: nothing, but constantly runs the game and its functions Assume : nothing */ void animate_main(char *base,long *iBase) { long *back,*temp; int musicCounter = 0; int enMisCount = 0; int plMisCount = 0; int x,y = 0; long clock; long newClock; int mouseClicked = 0; unsigned short mouseX,mouseY; int i= 0,j = 0,k = 0,l = 0; int randX,randY,randX2; int fire = 0; int s = 0; int done = 0; int render = 0; struct missile friendlyMis[NUM_MISSILES]; struct missile enemyMis[NUM_MISSILES]; struct explosion explosions[NUM_EXPLOSIONS]; struct missile_Silo silo; struct city city1; struct city city2; struct city city3; struct city city4; struct city city5; struct city city6; int *music = get_music(); Vector original_Vector; /*start the music*/ stop_sound(); start_music(); /*init ther model*/ initialize_model(&city1,&city2,&city3,&city4,&city5,&city6,&silo,friendlyMis,enemyMis,explosions); /*create the backbuffer*/ back = (long *)(buffer + (256 -((long)&buffer)%256)); init_VBL_ISR(original_Vector); while(done == 0) { /*random values for enemy missiles*/ randX = rand() % BORDER_RIGHT + 16; randX2 = rand() % BORDER_RIGHT + 16; randY = rand() % GROUND_LEVEL - 200; /* needs to fire a player missile at the mouse click coordinates */ if (mouseClicked == TRUE) { /* process on input */ if (k > NUM_MISSILES-1) { k = 0; } if (friendlyMis[k].destroyed == TRUE) { friendlyMis[k].destroyed = FALSE; friendlyMis[k].currentY = GROUND_LEVEL-20; friendly_Missile_Fired(mouseX,mouseY, &friendlyMis[k],MISSILE_SILO_FIRING_POINT); missile_fired_sound(); k++; } } clock = clockGet(); if (clock != newClock) { /* process on clock change */ fire++; if(fire == MISSILE_FIRED_TIME) { enemyMis[j].destroyed = FALSE; enemy_Missile_Fired(randX, GROUND_LEVEL, &enemyMis[j],randX2); j++; if(fire == MISSILE_FIRED_TIME) { fire = 0; } if (j == NUM_MISSILES-1) { j = 0; } } mouseClicked = get_mouse_pos(&mouseX,&mouseY); if(render == 1) { render_main(back, city1, city2, city3, city4, city5, city6, silo, enemyMis,friendlyMis, explosions,mouseX,mouseY,render); } /* T */ temp = iBase; iBase = back; back = temp; /* wait for sync and then set the screen to the current buffer */ set_video_base_wrap((char *)iBase); /* process missiles might need to change to be able to handle more */ for (i = 0; i < NUM_MISSILES; i++) { if (enemyMis[i].destroyed == FALSE && explosions[i].exists == FALSE) { processEnemyMissiles(&enemyMis[i],&explosions[i],clock,ENEMY_SPEED); } if (friendlyMis[i].destroyed == FALSE && explosions[i+NUM_MISSILES].exists == FALSE) { processEnemyMissiles(&friendlyMis[i],&explosions[i+NUM_MISSILES],clock,FRIENDLY_SPEED); } } /* process explosions might need to change to be able to handle more */ for (i = 0; i < NUM_EXPLOSIONS; i++) { if (explosions[i].exists == TRUE) { processExplosions(&explosions[i]); } } /* process missile -> explosion collisions */ for (i = NUM_MISSILES; i < NUM_EXPLOSIONS; i++) { if (explosions[i].exists == TRUE) { processCollisions(friendlyMis,enemyMis,explosions[i]); } } /* process explosion -> city explosions */ for (i = 0; i < NUM_MISSILES; i++) { if (explosions[i].hit_city != FALSE) { city_collision(explosions[i].hit_city,&city1,&city2,&city3,&city4,&city5,&city6); } } if (musicCounter < SONG_LENGTH){ if (fire % 4 == 0) { play_music(music[musicCounter]); musicCounter++; } } else { musicCounter = 0; } } newClock = clockGet(); done = game_over(city1,city2,city3,city4,city5,city6); } stop_sound(); }
void main() { float x,y,p1,p2; int i,j,cop_x,cop_y,cop_z,plane_x,plane_y,choice,ch,dist,pass=-1; int mouse_x1,mouse_y1,button; clrscr(); initgraph(&gd,&gm,"c://tc//bgi"); initmouse(); showmouseptr(); resetviewport(); restore(); DrawCube(); get_mouse_pos(&mouse_x1,&mouse_y1,&button); getch(); while(!kbhit()) { while(button!=1) { //showmouseptr(); get_mouse_pos(&mouse_x1,&mouse_y1,&button); button=1; mouse_x1=541;mouse_y1=35; } if(button==1) { if(mouse_x1>=540&&mouse_x1<=620) { if(mouse_y1>=30&&mouse_y1<=55) { choice=0; pass=1; } } else if(mouse_x1>=540&&mouse_x1<=620) { if(mouse_y1>=60&&mouse_y1<=80) { choice=1; ch=1; pass=1; } } else if(mouse_x1>=540&&mouse_x1<=620) { if(mouse_y1>=85&&mouse_y1<=105) { choice=1; ch=2; pass=1; } } else if(mouse_x1>=540&&mouse_x1<=620) { if(mouse_y1>=110&&mouse_y1<=130) { choice=1; ch=3; pass=1; } } else if(mouse_x1>=540&&mouse_x1<=620) { if(mouse_y1>=135&&mouse_y1<=155) { choice=2; pass=1; } } else if(mouse_x1>=540&&mouse_x1<=620) { if(mouse_y1>=160&&mouse_y1<=180) { choice=3; pass=1; } } else if(mouse_x1>=540&&mouse_x1<=620) { if(mouse_y1>=185&&mouse_y1<=205) { choice=4; pass=1; } } restore(); if(pass==1) { switch(choice) { case 0: restore(); DrawCube(); choice=-1; pass=-1; break; case 1: if(ch==1) { closegraph(); printf("enter the distance\n"); scanf("%d",&dist); initgraph(&gd,&gm,"c://tc//bgi"); resetviewport(); x_perspective(dist); restore(); } else if(ch==2) { closegraph(); printf("enter the distance\n"); scanf("%d",&dist); initgraph(&gd,&gm,"c://tc//bgi"); resetviewport(); y_perspective(dist); restore(); } else if(ch==3) { closegraph(); printf("enter the distance\n"); scanf("%d",&dist); initgraph(&gd,&gm,"c://tc//bgi"); resetviewport(); z_perspective(dist); restore(); } pass=-1; choice=-1; break; case 2: closegraph(); printf("enter the center of projection(x,y,z)\n"); scanf("%d%d%d",&cop_x,&cop_y,&cop_z); initgraph(&gd,&gm,"c://tc//bgi"); resetviewport(); rotate_x(atan(cop_x/cop_z)); z_perspective(cop_z); restore(); choice=-1; pass=-1; break; case 3: closegraph(); printf("enter the center of projection(x,y,z)\n"); scanf("%d%d%d",&cop_x,&cop_y,&cop_z); initgraph(&gd,&gm,"c://tc//bgi"); resetviewport(); rotate_x(atan(cop_x/cop_z)); rotate_y(atan(cop_y/cop_z)); z_perspective(cop_z); restore(); choice=-1; pass=-1; break; case 4: exit(0); } } button=-1; } } //closegraph(); }