static void events(void) { SDL_Event event; static const int button_map[] = { [SDL_BUTTON_LEFT] = 1, [SDL_BUTTON_RIGHT] = 2, [SDL_BUTTON_MIDDLE] = 3, // SDL2 Additional buttons [SDL_BUTTON_X1] = 4, [SDL_BUTTON_X2] = 5, }; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT : loop_run = 0; break; case SDL_KEYDOWN : event_key(event.key.keysym.sym&511, 1); break; case SDL_KEYUP : event_key(event.key.keysym.sym&511, 0); break; case SDL_MOUSEMOTION : event_mouse(0, 0, event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel); break; case SDL_MOUSEBUTTONUP : case SDL_MOUSEBUTTONDOWN : event_mouse(button_map[event.button.button], event.button.type == SDL_MOUSEBUTTONDOWN ? 1:0, event.button.x, event.button.y, 0, 0); break; break; } } }
int event_parse(SDL_Event ev) { switch(ev.type) { case SDL_KEYDOWN: return event_key(ev.key, EVENT_PRESS); case SDL_KEYUP: return event_key(ev.key, EVENT_RELEASE); case SDL_MOUSEMOTION: return event_mouse(ev.motion); case SDL_MOUSEBUTTONDOWN: return event_button(ev.button, EVENT_PRESS); case SDL_MOUSEBUTTONUP: return event_button(ev.button, EVENT_RELEASE); case SDL_JOYAXISMOTION: return event_joystick(ev.jaxis); case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: return event_fire(ev.jbutton); case SDL_WINDOWEVENT: if(ev.window.windowID == screen_window_id) { if(ev.window.event == SDL_WINDOWEVENT_RESIZED) { if((ev.window.data1 % 512) == 0 && (ev.window.data2 % 314) == 0) screen_make_texture(SDL_SCALING_NEAREST); else screen_make_texture(SDL_SCALING_LINEAR); } } break; case SDL_QUIT: if(debugger) return EVENT_DEBUG; else { SDL_Quit(); exit(0); } } return EVENT_NONE; }
/** * Posts a sample cloudwatch event, based on command line input */ int main(int argc, char** argv) { if (argc != 4) { std::cout << "Usage:" << std::endl << " put_events " << "<resource_arn> <sample_key> <sample_value>" << std::endl; return 1; } Aws::SDKOptions options; Aws::InitAPI(options); { Aws::String resource_arn(argv[1]); Aws::String event_key(argv[2]); Aws::String event_value(argv[3]); Aws::CloudWatchEvents::CloudWatchEventsClient cwe; Aws::CloudWatchEvents::Model::PutEventsRequestEntry event_entry; event_entry.SetDetail(MakeDetails(event_key, event_value)); event_entry.SetDetailType("sampleSubmitted"); event_entry.AddResources(resource_arn); event_entry.SetSource("aws-sdk-cpp-cloudwatch-example"); Aws::CloudWatchEvents::Model::PutEventsRequest request; request.AddEntries(event_entry); auto outcome = cwe.PutEvents(request); if (!outcome.IsSuccess()) { std::cout << "Failed to post cloudwatch event: " << outcome.GetError().GetMessage() << std::endl; } else { std::cout << "Successfully posted cloudwatch event" << std::endl; } } Aws::ShutdownAPI(options); return 0; }
int main(void) { int count = 0; int G_pressed = 0, R_pressed = 1; char vstring[10], wstring[10]; double x1_old, y1_old; double x2_old, y2_old; double x1_new, y1_new; double x2_new, y2_new; double vx, vy, wx, wy; double v, w; posvel pv; x1_old = 100.0; y1_old = 100.0; vx = 10.0; vy = 5.0; x2_old = 250.0; y2_old = 250.0; wx = -8.0; wy = 4.0; v = sqrt(pow(wx,2)+pow(wy,2)); w = sqrt(pow(vx,2)+pow(vy,2)); /* open the graphics window */ initwindow(XWINDOW, YWINDOW); /* allow mouse operations */ initmouse(); /* allow keyboard operations */ initkeyboard(); /* create an event queue */ create_event_queue(); /* register display, mouse and keyboard as event sources */ reg_display_events(); reg_mouse_events(); reg_keyboard_events(); /* initialize the font */ initfont(); outtextxy(4,5,"To quit press left mouse button or close graphics window"); outtextxy(4,15,"To pause press right mouse button"); outtextxy(4,25,"To change ball speed use arrow keys (up/down = red, left/right = blue)"); outtextxy(4,35,"To make the red ball green press G or g "); do { if (check_if_event()) { /* wait for event */ wait_for_event(); if (event_close_display()) break; else if (event_mouse_button_down()) { if (event_mouse_left_button_down()) break; else if (event_mouse_right_button_down()) wait_for_event(); } else if (event_key_down()) { /* change speed of first ball */ if(event_key_up_arrow()) { vx = 1.25*vx; vy = 1.25*vy; } else if(event_key_down_arrow()) { vx = 0.75*vx; vy = 0.75*vy; } else if(event_key_left_arrow()) { wx = 0.75*wx; wy = 0.75*wy; } else if(event_key_right_arrow()) { wx = 1.25*wx; wy = 1.25*wy; } if (event_key('G')) { G_pressed = 1; R_pressed = 0; } else if (event_key('R')) { R_pressed = 1; G_pressed = 0; } } } v = sqrt(pow(wx,2)+pow(wy,2)); w = sqrt(pow(vx,2)+pow(vy,2)); /* calculate new ball positions */ x1_new = x1_old + vx*TICK; y1_new = y1_old + vy*TICK; x2_new = x2_old + wx*TICK; y2_new = y2_old + wy*TICK; /* handle what to do if balls hit boundaries */ pv = hit_boundary(x1_new, vx, 1); x1_new = pv.pos; vx = pv.vel; pv = hit_boundary(x2_new, wx, 1); x2_new = pv.pos; wx = pv.vel; pv = hit_boundary(y1_new, vy, 0); y1_new = pv.pos; vy = pv.vel; pv = hit_boundary(y2_new, wy, 0); y2_new = pv.pos; wy = pv.vel; /* draw balls on screen buffer in new positions */ filled_circle(x1_new, y1_new, RADIUS , BLUE); if (G_pressed) filled_circle(x2_new, y2_new, RADIUS , GREEN); else if (R_pressed) filled_circle(x2_new, y2_new, RADIUS , RED); /* make the balls visible on the screen display and remove the balls in the previous positions */ sprintf(vstring, "%4.2lf", v); sprintf(wstring, "%4.2lf", w); setcolor(RED); outtextxy(VEL_TEXT_X,VEL_TEXT_Y,"v = "); /* clear area for numeric output */ filled_rectangle(VEL_TEXT_X+40, VEL_TEXT_Y-10, VEL_TEXT_X+100, VEL_TEXT_Y+20, BLACK); outtextxy(VEL_TEXT_X+60,VEL_TEXT_Y,vstring); setcolor(BLUE); outtextxy(VEL_TEXT_X+120,VEL_TEXT_Y,"w = "); /* clear area for numeric output */ filled_rectangle(VEL_TEXT_X+160, VEL_TEXT_Y-10, VEL_TEXT_X+220, VEL_TEXT_Y+20, BLACK); outtextxy(VEL_TEXT_X+180,VEL_TEXT_Y,wstring); update_display(); /* remove the balls in the previous positions on the screen buffer */ filled_circle(x1_old, y1_old, RADIUS , BLACK); filled_circle(x2_old, y2_old, RADIUS , BLACK); /* update the old positions */ x1_old = x1_new; y1_old = y1_new; x2_old = x2_new; y2_old = y2_new; count++; pausefor(8); /* wait 8 miliseconds */ } while (count < MAXCOUNT); /* close the mouse */ closemouse(); /* remove the display */ closegraph(); return 0; }