rnd-19981217-3
[rocksndiamonds.git] / src / editor.c
index d19c8c26083e0b20cc1fe9a87dbcfe1e3f0b63b0..bf3704bdf94cc097f9d691b3f58d06a0c7184d99 100644 (file)
@@ -527,7 +527,7 @@ static void CreateControlButtons()
        i == ED_CTRL_ID_WRAP_RIGHT ||
        i == ED_CTRL_ID_WRAP_UP ||
        i == ED_CTRL_ID_WRAP_DOWN)
-      event_mask = GD_EVENT_PRESSED_REPEATED;
+      event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
     else
       event_mask = GD_EVENT_RELEASED;
 
@@ -551,32 +551,6 @@ static void CreateControlButtons()
   }
 }
 
-
-
-#if 0
-
-static void test1(struct GadgetInfo *gi)
-{
-  int event_type = gi->event.type;
-
-  printf("HandleControlButtons: (%d,%d) (%d,%d) [%d] ",
-        gi->x, gi->y,
-        gi->event.x, gi->event.y, gi->event.button);
-
-  if (event_type == GD_EVENT_PRESSED)
-    printf("GD_EVENT_PRESSED\n");
-  else if (event_type == GD_EVENT_RELEASED)
-    printf("GD_EVENT_RELEASED\n");
-  else if (event_type == GD_EVENT_MOVING)
-    printf("GD_EVENT_MOVING\n");
-  else
-    printf("?\n");
-}
-
-#endif
-
-
-
 static void CreateCounterButtons(int counter_id)
 {
   int i;
@@ -588,6 +562,9 @@ static void CreateCounterButtons(int counter_id)
     int gd_xoffset;
     int gd_x1, gd_x2, gd_y;
     int id = counter_info[counter_id].gadget_id + i;
+    unsigned long event_mask;
+
+    event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
 
     gd_xoffset = (i == 0 ? ED_BUTTON_MINUS_XPOS : ED_BUTTON_PLUS_XPOS);
     gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
@@ -603,7 +580,7 @@ static void CreateCounterButtons(int counter_id)
                      GDI_STATE, GD_BUTTON_UNPRESSED,
                      GDI_DESIGN_UNPRESSED, gd_pixmap, gd_x1, gd_y,
                      GDI_DESIGN_PRESSED, gd_pixmap, gd_x2, gd_y,
-                     GDI_EVENT_MASK, GD_EVENT_PRESSED_REPEATED,
+                     GDI_EVENT_MASK, event_mask,
                      GDI_CALLBACK, HandleCounterButtons,
                      GDI_END);
 
@@ -619,7 +596,9 @@ static void CreateDrawingAreas()
   struct GadgetInfo *gi;
   unsigned long event_mask;
 
-  event_mask = GD_EVENT_PRESSED | GD_EVENT_RELEASED | GD_EVENT_MOVING;
+  event_mask =
+    GD_EVENT_PRESSED | GD_EVENT_RELEASED | GD_EVENT_MOVING |
+    GD_EVENT_OFF_BORDERS;
 
   gi = CreateGadget(GDI_CUSTOM_ID, ED_CTRL_ID_DRAWING_LEVEL,
                    GDI_X, SX,
@@ -1923,12 +1902,6 @@ static void CopyLevelToUndoBuffer()
   for(x=0; x<lev_fieldx; x++)
     for(y=0; y<lev_fieldy; y++)
       UndoBuffer[undo_buffer_position][x][y] = Feld[x][y];
-
-
-
-  /*
-    printf("state saved to undo buffer %d\n", undo_buffer_position);
-  */
 }
 
 static void RandomPlacement(int button)
@@ -1967,45 +1940,34 @@ static void RandomPlacement(int button)
   DrawMiniLevel(level_xpos, level_ypos);
 }
 
-/*
-static void HandleDrawingAreas(int mx, int my, int button)
-*/
-
 static void HandleDrawingAreas(struct GadgetInfo *gi)
 {
-  static int last_button = 0;
-  static int last_element = 0;
   static boolean started_inside_drawing_area = FALSE;
-  boolean inside_drawing_area;
+  boolean inside_drawing_area = !gi->event.off_borders;
   boolean button_press_event;
   boolean button_release_event;
   int new_element;
   int button = gi->event.button;
-  int mx = SX + gi->event.x * MINI_TILEX;
-  int my = SX + gi->event.y * MINI_TILEY;
-  int min_mx = SX, max_mx = SX + SXSIZE -1;
-  int min_my = SY, max_my = SY + SYSIZE -1;
-  int sx, sy;
+  int sx = gi->event.x, sy = gi->event.y;
   int lx, ly;
   int x, y;
 
   if (edit_mode != ED_MODE_DRAWING)
     return;
 
-  button_press_event = (last_button == 0 && button != 0);
-  button_release_event = (last_button != 0 && button == 0);
-  last_button = button;
-
-  inside_drawing_area =
-    (mx >= min_mx && mx <= max_mx && my >= min_my && my <= max_my);
+  button_press_event = (gi->event.type == GD_EVENT_PRESSED);
+  button_release_event = (gi->event.type == GD_EVENT_RELEASED);
 
-  mx = (mx < min_mx ? min_mx : mx > max_mx ? max_mx : mx);
-  my = (my < min_my ? min_my : my > max_my ? max_my : my);
-  sx = (mx - SX) / MINI_TILEX; 
-  sy = (my - SY) / MINI_TILEY; 
+  sx = (sx < 0 ? 0 : sx > 2*SCR_FIELDX - 1 ? 2*SCR_FIELDX - 1 : sx);
+  sy = (sy < 0 ? 0 : sy > 2*SCR_FIELDY - 1 ? 2*SCR_FIELDY - 1 : sy);
   lx = sx + level_xpos;
   ly = sy + level_ypos;
 
+  lx = (lx < 0 ? 0 : lx > lev_fieldx - 1 ? lev_fieldx - 1 : lx);
+  ly = (ly < 0 ? 0 : ly > lev_fieldy - 1 ? lev_fieldy - 1 : ly);
+  sx = lx - level_xpos;
+  sy = ly - level_ypos;
+
   if (button_press_event)
     started_inside_drawing_area = inside_drawing_area;
 
@@ -2102,7 +2064,7 @@ static void HandleDrawingAreas(struct GadgetInfo *gi)
        }
        else if (button_release_event)
        {
-         draw_func(start_sx, start_sy, sx, sy, last_element, TRUE);
+         draw_func(start_sx, start_sy, sx, sy, new_element, TRUE);
          CopyLevelToUndoBuffer();
        }
        else if (last_sx != sx || last_sy != sy)
@@ -2127,131 +2089,8 @@ static void HandleDrawingAreas(struct GadgetInfo *gi)
     default:
       break;
   }
-
-  last_element = new_element;
 }
 
-
-
-#if 0
-
-static void HandlePressedControlButtons()
-{
-  static unsigned long button_delay = 0;
-  int i;
-
-  /* buttons with action when held pressed */
-  int gadget_id[] =
-  {
-    ED_CTRL_ID_WRAP_UP,
-    ED_CTRL_ID_WRAP_LEFT,
-    ED_CTRL_ID_WRAP_RIGHT,
-    ED_CTRL_ID_WRAP_DOWN,
-    ED_CTRL_ID_SCORE_DOWN,
-    ED_CTRL_ID_SCORE_UP,
-    -1
-  };
-
-  if (!DelayReached(&button_delay, GADGET_FRAME_DELAY))
-    return;
-
-  for (i=0; gadget_id[i] != -1; i++)
-  {
-    int id = gadget_id[i];
-    int state = level_editor_gadget[id]->state;
-    int button = level_editor_gadget[id]->event.button;
-    int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
-
-    if (state != GD_BUTTON_PRESSED)
-      continue;
-  
-    switch (id)
-    {
-      case ED_CTRL_ID_WRAP_LEFT:
-       if (level_xpos >= 0)
-       {
-         if (lev_fieldx < 2*SCR_FIELDX - 2)
-           break;
-  
-         level_xpos -= step;
-         if (level_xpos <- 1)
-           level_xpos = -1;
-         if (button == 1)
-           ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_RIGHT);
-         else
-           DrawMiniLevel(level_xpos, level_ypos);
-       }
-       break;
-  
-      case ED_CTRL_ID_WRAP_RIGHT:
-       if (level_xpos <= lev_fieldx - 2*SCR_FIELDX)
-       {
-         if (lev_fieldx < 2*SCR_FIELDX - 2)
-           break;
-  
-         level_xpos += step;
-         if (level_xpos > lev_fieldx - 2*SCR_FIELDX + 1)
-           level_xpos = lev_fieldx - 2*SCR_FIELDX + 1;
-         if (button == 1)
-           ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_LEFT);
-         else
-           DrawMiniLevel(level_xpos, level_ypos);
-       }
-       break;
-  
-      case ED_CTRL_ID_WRAP_UP:
-       if (level_ypos >= 0)
-       {
-         if (lev_fieldy < 2*SCR_FIELDY - 2)
-           break;
-  
-         level_ypos -= step;
-         if (level_ypos < -1)
-           level_ypos = -1;
-         if (button == 1)
-           ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_DOWN);
-         else
-           DrawMiniLevel(level_xpos, level_ypos);
-       }
-       break;
-  
-      case ED_CTRL_ID_WRAP_DOWN:
-       if (level_ypos <= lev_fieldy - 2*SCR_FIELDY)
-       {
-         if (lev_fieldy < 2*SCR_FIELDY - 2)
-           break;
-  
-         level_ypos += step;
-         if (level_ypos > lev_fieldy - 2*SCR_FIELDY + 1)
-           level_ypos = lev_fieldy - 2*SCR_FIELDY + 1;
-         if (button == 1)
-           ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_UP);
-         else
-           DrawMiniLevel(level_xpos, level_ypos);
-       }
-       break;
-
-      case ED_CTRL_ID_SCORE_DOWN:
-      case ED_CTRL_ID_SCORE_UP:
-       *gadget_score_value += (id == ED_CTRL_ID_SCORE_DOWN ? -step : step);
-       if (*gadget_score_value < 0)
-         *gadget_score_value = 0;
-       else if (*gadget_score_value > 255)
-         *gadget_score_value = 255;
-
-       DrawCounterValueField(ED_COUNTER_SCORE, *gadget_score_value);
-       break;
-  
-      default:
-       break;
-    }
-  }
-}
-
-#endif
-
-
-
 static void HandleCounterButtons(struct GadgetInfo *gi)
 {
   int id = gi->custom_id;
@@ -2279,7 +2118,6 @@ static void HandleCounterButtons(struct GadgetInfo *gi)
 static void HandleControlButtons(struct GadgetInfo *gi)
 {
   int id = gi->custom_id;
-  int event_type = gi->event.type;
   int button = gi->event.button;
   int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
   int new_element;
@@ -2522,11 +2360,11 @@ static void HandleControlButtons(struct GadgetInfo *gi)
       break;
 
     default:
-      if (event_type == GD_EVENT_PRESSED)
+      if (gi->event.type == GD_EVENT_PRESSED)
        printf("default: HandleControlButtons: GD_EVENT_PRESSED\n");
-      else if (event_type == GD_EVENT_RELEASED)
+      else if (gi->event.type == GD_EVENT_RELEASED)
        printf("default: HandleControlButtons: GD_EVENT_RELEASED\n");
-      else if (event_type == GD_EVENT_MOVING)
+      else if (gi->event.type == GD_EVENT_MOVING)
        printf("default: HandleControlButtons: GD_EVENT_MOVING\n");
       else
        printf("default: HandleControlButtons: ?\n");