static struct GadgetInfo *gi = NULL;
static unsigned long pressed_delay = 0;
-#if 0
- static boolean pressed = FALSE;
-#endif
-
struct GadgetInfo *new_gi;
boolean gadget_pressed;
boolean gadget_pressed_repeated;
- boolean gadget_moving_inside;
- boolean gadget_moving_outside;
+ boolean gadget_moving;
+ boolean gadget_moving_off_borders;
boolean gadget_released;
+ boolean gadget_released_off_borders;
if (gadget_list_first_entry == NULL)
return;
new_gi = getGadgetInfoFromMousePosition(mx,my);
gadget_pressed =
- (button != 0 && gi == NULL && new_gi != NULL);
+ (button != 0 && gi == NULL && new_gi != NULL && !motion_status);
gadget_pressed_repeated =
(button != 0 && gi != NULL && new_gi == gi);
- gadget_moving_inside =
+ gadget_moving =
(button != 0 && gi != NULL && new_gi == gi && motion_status);
- gadget_moving_outside =
+ gadget_moving_off_borders =
(button != 0 && gi != NULL && new_gi != gi && motion_status);
gadget_released =
(button == 0 && gi != NULL && new_gi == gi);
+ gadget_released_off_borders =
+ (button == 0 && gi != NULL && new_gi != gi);
if (gadget_pressed)
gi = new_gi;
gi->callback(gi);
}
- if (gadget_moving_inside)
+ if (gadget_moving)
{
if (gi->state == GD_BUTTON_UNPRESSED)
DrawGadget(gi, TRUE, TRUE);
gi->callback(gi);
}
- if (gadget_moving_outside)
+ if (gadget_moving_off_borders)
{
if (gi->state == GD_BUTTON_PRESSED)
DrawGadget(gi, FALSE, TRUE);
gi->event.type = GD_EVENT_MOVING;
gi->event.off_borders = TRUE;
- if (gi->event_mask & GD_EVENT_MOVING)
+ if (gi->event_mask & GD_EVENT_MOVING &&
+ gi->event_mask & GD_EVENT_OFF_BORDERS)
gi->callback(gi);
}
gi->callback(gi);
}
- if (button == 0)
- gi = NULL;
-
-
-
-#if 0
- if (button)
+ if (gadget_released_off_borders)
{
- if (!motion_status) /* mouse button just pressed */
- {
- if (new_gi != NULL)
- {
- gi = new_gi;
- gi->state = GD_BUTTON_PRESSED;
- gi->event.type = GD_EVENT_PRESSED;
- gi->event.button = button;
- DrawGadget(gi, TRUE, TRUE);
-
- /* initialize delay counter */
- pressed_delay = 0;
- DelayReached(&pressed_delay, GADGET_FRAME_DELAY);
-
-
- printf("new gadget pressed\n");
-
-
- if (gi->event_mask & GD_EVENT_PRESSED)
- gi->callback(gi);
-
- pressed = TRUE;
- }
- }
- else /* mouse movement with pressed mouse button */
- {
- if (new_gi != gi && gi != NULL)
- {
- if (pressed)
- DrawGadget(gi, FALSE, TRUE);
- gi->state = GD_BUTTON_UNPRESSED;
- gi->event.type = GD_EVENT_MOVING;
-
-
- printf("outside gadget\n");
-
-
-
-
- if (gi->event_mask & GD_EVENT_MOVING)
- gi->callback(gi);
-
- pressed = FALSE;
- }
- else if (new_gi == gi && gi != NULL)
- {
- if (!pressed)
- DrawGadget(gi, TRUE, TRUE);
- gi->state = GD_BUTTON_PRESSED;
- gi->event.type = GD_EVENT_MOVING;
-
-
- printf("inside gadget\n");
-
-
-
-
- if (gi->event_mask & GD_EVENT_MOVING)
- gi->callback(gi);
-
- pressed = TRUE;
- }
- }
-
- if (gi != NULL &&
- gi->event_mask & GD_EVENT_PRESSED_REPEATED &&
- gi->state == GD_BUTTON_PRESSED &&
- DelayReached(&pressed_delay, GADGET_FRAME_DELAY))
- {
- printf("gadget pressed (repeated)\n");
-
+ gi->event.type = GD_EVENT_RELEASED;
- gi->callback(gi);
- }
+ if (gi->event_mask & GD_EVENT_RELEASED &&
+ gi->event_mask & GD_EVENT_OFF_BORDERS)
+ gi->callback(gi);
}
- else /* mouse button just released */
- {
- if (new_gi == gi && gi != NULL && pressed)
- {
- gi->state = GD_BUTTON_UNPRESSED;
- gi->event.type = GD_EVENT_RELEASED;
- DrawGadget(gi, FALSE, TRUE);
-
-
- printf("gadget released\n");
-
-
-
- if (gi->event_mask & GD_EVENT_RELEASED)
- gi->callback(gi);
- }
+ if (button == 0)
gi = NULL;
- pressed = FALSE;
- }
-#endif
-
-
-
}
}
}
-
-
-#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;
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,
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)
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;
if (!started_inside_drawing_area)
return;
- printf("%d,%d, %d,%d, %d,%d.\n",
- gi->event.x, gi->event.y, sx, sy, lx, ly);
-
if ((!button && !button_release_event) ||
sx > lev_fieldx || sy > lev_fieldy ||
(sx == 0 && level_xpos<0) ||
}
}
-
-
-#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;