- SDLKey key;
- SDLMod keymod;
- button_type* pbutton;
- int x,y;
-
- keymod = SDL_GetModState();
-
- while(SDL_PollEvent(&event))
- {
- /* testing SDL_KEYDOWN, SDL_KEYUP and SDL_QUIT events*/
- if(event.type == SDL_KEYDOWN || ((event.type == SDL_MOUSEBUTTONDOWN || SDL_MOUSEMOTION) && (event.motion.x > 0 && event.motion.x < screen->w - 64 &&
- event.motion.y > 0 && event.motion.y < screen->h)))
- {
-
- switch(event.type)
- {
- case SDL_KEYDOWN: // key pressed
- key = event.key.keysym.sym;
- if(show_menu)
- {
- menu_event(&event.key.keysym);
- if(key == SDLK_ESCAPE)
- {
- show_menu = NO;
- menu_set_current(&leveleditor_menu);
- }
- break;
- }
- switch(key)
- {
- case SDLK_ESCAPE:
- if(!show_menu)
- show_menu = YES;
- else
- show_menu = NO;
- break;
- case SDLK_LEFT:
- if(fire == DOWN)
- cursor_x -= KEY_CURSOR_SPEED;
- else
- cursor_x -= KEY_CURSOR_FASTSPEED;
-
- if(cursor_x < pos_x + MOUSE_LEFT_MARGIN)
- pos_x = cursor_x - MOUSE_LEFT_MARGIN;
-
- break;
- case SDLK_RIGHT:
- if(fire == DOWN)
- cursor_x += KEY_CURSOR_SPEED;
- else
- cursor_x += KEY_CURSOR_FASTSPEED;
-
- if(cursor_x > pos_x + MOUSE_RIGHT_MARGIN-32)
- pos_x = cursor_x - MOUSE_RIGHT_MARGIN+32;
-
- break;
- case SDLK_UP:
- if(fire == DOWN)
- cursor_y -= KEY_CURSOR_SPEED;
- else
- cursor_y -= KEY_CURSOR_FASTSPEED;
-
- if(cursor_y < 0)
- cursor_y = 0;
- break;
- case SDLK_DOWN:
- if(fire == DOWN)
- cursor_y += KEY_CURSOR_SPEED;
- else
- cursor_y += KEY_CURSOR_FASTSPEED;
-
- if(cursor_y > screen->h-32)
- cursor_y = screen->h-32;
- break;
- case SDLK_LCTRL:
- fire =UP;
- break;
- case SDLK_F1:
- le_showhelp();
- break;
- case SDLK_HOME:
- cursor_x = 0;
- pos_x = cursor_x;
- break;
- case SDLK_END:
- cursor_x = (le_current_level->width * 32) - 32;
- pos_x = cursor_x;
- break;
- case SDLK_F9:
- le_show_grid = !le_show_grid;
- break;
- default:
- break;
- }
- break;
- case SDL_KEYUP: /* key released */
- switch(event.key.keysym.sym)
- {
- case SDLK_LCTRL:
- fire = DOWN;
- break;
- default:
- break;
- }
- break;
- case SDL_MOUSEBUTTONDOWN:
- if(event.button.button == SDL_BUTTON_LEFT)
- {
- le_mouse_pressed[LEFT] = YES;
-
- selection.x1 = event.motion.x + pos_x;
- selection.y1 = event.motion.y;
- selection.x2 = event.motion.x + pos_x;
- selection.y2 = event.motion.y;
- }
- else if(event.button.button == SDL_BUTTON_RIGHT)
- le_mouse_pressed[RIGHT] = YES;
- break;
- case SDL_MOUSEBUTTONUP:
- if(event.button.button == SDL_BUTTON_LEFT)
- le_mouse_pressed[LEFT] = NO;
- else if(event.button.button == SDL_BUTTON_RIGHT)
- le_mouse_pressed[RIGHT] = NO;
- break;
- case SDL_MOUSEMOTION:
- if(!show_menu)
- {
- x = event.motion.x;
- y = event.motion.y;
-
- cursor_x = ((int)(pos_x + x) / 32) * 32;
- cursor_y = ((int) y / 32) * 32;
-
- if(le_mouse_pressed[LEFT] == YES)
- {
- selection.x2 = x + pos_x;
- selection.y2 = y;
- }
-
- if(le_mouse_pressed[RIGHT] == YES)
- {
- pos_x += -1 * event.motion.xrel;
- }
- }
- break;
- case SDL_QUIT: // window closed
- done = DONE_QUIT;
- break;
- default:
- break;
- }
- }
-
- if(le_current_level != NULL)
- {
- if(event.type == SDL_KEYDOWN || event.type == SDL_KEYUP || ((event.type == SDL_MOUSEBUTTONDOWN || SDL_MOUSEMOTION) && (event.motion.x > screen->w-64 && event.motion.x < screen->w &&
- event.motion.y > 0 && event.motion.y < screen->h)))
- {
- le_mouse_pressed[LEFT] = NO;
- le_mouse_pressed[RIGHT] = NO;
-
- if(show_menu == NO)
- {
- /* Check for button events */
- button_event(&le_test_level_bt,&event);
- if(button_get_state(&le_test_level_bt) == BN_CLICKED)
- le_testlevel();
- button_event(&le_save_level_bt,&event);
- if(button_get_state(&le_save_level_bt) == BN_CLICKED)
- level_save(le_current_level,le_level_subset.name.c_str(),le_level);
- button_event(&le_next_level_bt,&event);
- if(button_get_state(&le_next_level_bt) == BN_CLICKED)
- {
- if(le_level < le_level_subset.levels)
- {
- le_goto_level(++le_level);
- }
- else
- {
- st_level new_lev;
- char str[1024];
- int d = 0;
- sprintf(str,"Level %d doesn't exist.",le_level+1);
- text_drawf(&white_text,str,0,-18,A_HMIDDLE,A_VMIDDLE,2,NO_UPDATE);
- text_drawf(&white_text,"Do you want to create it?",0,0,A_HMIDDLE,A_VMIDDLE,2,NO_UPDATE);
- text_drawf(&red_text,"(Y)es/(N)o",0,20,A_HMIDDLE,A_VMIDDLE,2,NO_UPDATE);
- flipscreen();
- while(d == 0)
- {
- while(SDL_PollEvent(&event))
- switch(event.type)
- {
- case SDL_KEYDOWN: // key pressed
- switch(event.key.keysym.sym)
- {
- case SDLK_y:
- level_default(&new_lev);
- level_save(&new_lev,le_level_subset.name.c_str(),++le_level);
- le_level_subset.levels = le_level;
- le_goto_level(le_level);
- d = 1;
- break;
- case SDLK_n:
- d = 1;
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
- SDL_Delay(50);
- }
- }
- }
- button_event(&le_previous_level_bt,&event);
- if(button_get_state(&le_previous_level_bt) == BN_CLICKED)
- {
- if(le_level > 1)
- le_goto_level(--le_level);
- }
- button_event(&le_rubber_bt,&event);
- if(button_get_state(&le_rubber_bt) == BN_CLICKED)
- le_current_tile = '.';
- button_event(&le_select_mode_one_bt,&event);
- if(button_get_state(&le_select_mode_one_bt) == BN_CLICKED)
- le_selection_mode = CURSOR;
- button_event(&le_select_mode_two_bt,&event);
- if(button_get_state(&le_select_mode_two_bt) == BN_CLICKED)
- le_selection_mode = SQUARE;
-
- button_event(&le_bad_bt,&event);
- if(button_get_state(&le_bad_bt) == BN_CLICKED)
- {
- le_bad_panel.hidden = NO;
- le_fgd_panel.hidden = YES;
- le_bkgd_panel.hidden = YES;
- }
-
- button_event(&le_fgd_bt,&event);
- if(button_get_state(&le_fgd_bt) == BN_CLICKED)
- {
- le_bad_panel.hidden = YES;
- le_fgd_panel.hidden = NO;
- le_bkgd_panel.hidden = YES;
- }
- button_event(&le_bkgd_bt,&event);
- if(button_get_state(&le_bkgd_bt) == BN_CLICKED)
- {
- le_bad_panel.hidden = YES;
- le_fgd_panel.hidden = YES;
- le_bkgd_panel.hidden = NO;
- }
- button_event(&le_settings_bt,&event);
- if(button_get_state(&le_settings_bt) == BN_CLICKED)
- {
- if(show_menu == NO)
- {
- update_level_settings_menu();
- menu_set_current(&level_settings_menu);
- show_menu = YES;
- }
- else
- {
- menu_set_current(&leveleditor_menu);
- show_menu = NO;
- }
- }
- if((pbutton = button_panel_event(&le_bkgd_panel,&event)) != NULL)
- {
- if(button_get_state(pbutton) == BN_CLICKED)
- {
- char c = '\0';
- if(pbutton->tag >= 0 && pbutton->tag <= 3)
- c = 'G' + pbutton->tag;
- else if(pbutton->tag >= 4 && pbutton->tag <= 7)
- c = 'g' + pbutton->tag - 4;
- else if(pbutton->tag >= 8 && pbutton->tag <= 11)
- c = 'C' + pbutton->tag - 8;
- else if(pbutton->tag >= 12 && pbutton->tag <= 15)
- c = 'c' + pbutton->tag - 12;
- if(c != '\0')
- le_current_tile = c;
- }
- }
- if((pbutton = button_panel_event(&le_fgd_panel,&event)) != NULL)
- {
- if(button_get_state(pbutton) == BN_CLICKED)
- {
- char c = '\0';
- if(pbutton->tag == 0)
- c = '#' ;
- else if(pbutton->tag == 1)
- c = '[';
- else if(pbutton->tag == 2)
- c = '=';
- else if(pbutton->tag == 3)
- c = ']';
- else if(pbutton->tag == 4)
- c = '^';
- else if(pbutton->tag == 5)
- c = '&';
- else if(pbutton->tag == 6)
- c = '|';
- else if(pbutton->tag == 7)
- c = '*';
- else if(pbutton->tag == 8)
- c = '\\';
- else if(pbutton->tag == 9)
- c = 'a';
- else if(pbutton->tag == 10)
- c = 'B';
- else if(pbutton->tag == 11)
- c = 'A';
- else if(pbutton->tag == 12)
- c = '!';
- else if(pbutton->tag == 13)
- c = '$';
- else if(pbutton->tag == 14)
- c = 'X';
- else if(pbutton->tag == 15)
- c = 'Y';
- else if(pbutton->tag == 16)
- c = 'x';
- else if(pbutton->tag == 17)
- c = 'y';
- if(c != '\0')
- le_current_tile = c;
- }
- }
- if((pbutton = button_panel_event(&le_bad_panel,&event)) != NULL)
- {
- if(button_get_state(pbutton) == BN_CLICKED)
- {
- char c = '\0';
- if(pbutton->tag >= 0 && pbutton->tag <= 2)
- c = '0' + pbutton->tag;
- if(c != '\0')
- le_current_tile = c;
- }
- }
- }
- else
- {
- button_event(&le_settings_bt,&event);
- if(button_get_state(&le_settings_bt) == BN_CLICKED)
- {
- if(show_menu == NO)
- {
- update_level_settings_menu();
- menu_set_current(&level_settings_menu);
- show_menu = YES;
- }
- else
- {
- menu_set_current(&leveleditor_menu);
- show_menu = NO;
- }
- }
- }
- }
- if(show_menu == NO)
- {
- button_event(&le_move_left_bt,&event);
- button_event(&le_move_right_bt,&event);
-
- if(le_mouse_pressed[LEFT])
- {
- le_change(cursor_x, cursor_y, le_current_tile);
- }
- }
- }
- }
- if(show_menu == NO)
- {
- if(button_get_state(&le_move_left_bt) == BN_PRESSED)
- {
- pos_x -= 192;
- }
- else if(button_get_state(&le_move_left_bt) == BN_HOVER)
- {
- pos_x -= 96;
- }
-
- if(button_get_state(&le_move_right_bt) == BN_PRESSED)
- {
- pos_x += 192;
- }
- else if(button_get_state(&le_move_right_bt) == BN_HOVER)
- {
- pos_x += 96;
- }
- }
-