// // CSE143, Summer 2001 // Homework 5 // Air Traffic Control Starter Code // ATCUI.cpp // #include "Simulator.h" #include "ATCUI.h" ATCUI::ATCUI(Simulator *aSim,GP142Display *aDisplay) { theSim = aSim; display = aDisplay; display->clear (White); display->setAnimation (Run); drawButtons(); } // Draws the buttons to the screen void ATCUI::drawButtons() { int i; int text_offset = MENU_LEFT+10; // offset of button text in button int font_size = 12; // size of button text // draw rectangles for each button for(i = 0; i < NUM_BUTTONS; i++) { display->drawRectangle(MENU_LEFT, MENU_TOP - i * BUTTON_HEIGHT, MENU_LEFT + BUTTON_WIDTH, MENU_TOP - (i + 1) * BUTTON_HEIGHT, Black, 1); } // display button text i = MENU_TOP - (BUTTON_HEIGHT/2) - (font_size/2); display->write(text_offset, i, "Increase Traffic", Black, font_size); i -= BUTTON_HEIGHT; display->write(text_offset, i, "Decrease Traffic", Black, font_size); i -= BUTTON_HEIGHT; display->write(text_offset, i, "Run Sim", Black, font_size); i -= BUTTON_HEIGHT; display->write(text_offset, i, "Stop Sim", Black, font_size); } // Classify mouse click at (mouse_x,mouse_y) and return kind void ATCUI::handle_mouse_click(int mouse_x, int mouse_y) { if ((mouse_x > MENU_LEFT) && (mouse_x < MENU_LEFT + BUTTON_WIDTH) && (mouse_y < MENU_TOP) && (mouse_y > (MENU_TOP - NUM_BUTTONS * BUTTON_HEIGHT))) handle_button(mouse_x,mouse_y); else handleScreenClick(mouse_x,mouse_y); } //Handles mouse clicks that occur outside of the menu box void ATCUI::handleScreenClick(int mouseX,int mouseY) { } // Process button click at location x, y void ATCUI::handle_button(int x, int y) { int buttonNum; // number of selected button // Convert y coordinate to button number from top. buttonNum = (MENU_TOP - y)/BUTTON_HEIGHT; switch(buttonNum) { case 0: //code to process 1st button break; case 1: //code to process 2nd button... break; case 2: break; case 3: break; default: break; } } void ATCUI::draw() { display->clear (White); drawButtons(); }