~ubuntu-branches/debian/squeeze/freeciv/squeeze

« back to all changes in this revision

Viewing changes to client/gui-sdl/widget.c

  • Committer: Bazaar Package Importer
  • Author(s): Clint Adams
  • Date: 2008-11-29 22:25:59 UTC
  • mfrom: (1.2.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20081129222559-6sqqdum8qnhykm4l
Tags: 2.1.8-1
* New upstream release.  closes: #495740.
* Disable GGZ support (can be re-enabled when ggz 1.0 is available).
* Change maintainer to Debian Games Team.

Show diffs side-by-side

added added

removed removed

Lines of Context:
214
214
}
215
215
 
216
216
/* =================================================== */
217
 
/* ===================== GUI LIST ==================== */
 
217
/* ===================== WIDGET LIST ==================== */
218
218
/* =================================================== */
219
219
 
220
220
/**************************************************************************
221
 
  Simple "Search and De..." no search in 'pGUI_List' == "Widget's list" and
222
 
  return ( not Disabled and not Hiden ) widget under cursor 'pPosition'.
 
221
  Find the next visible widget in the widget list starting with
 
222
  pStartWidget that is drawn at position (x, y). If pStartWidget is NULL,
 
223
  the search starts with the first entry of the main widget list. 
223
224
**************************************************************************/
224
 
struct widget * WidgetListScaner(const struct widget *pGUI_List, int x, int y)
 
225
struct widget *find_next_widget_at_pos(struct widget *pStartWidget, int x, int y)
225
226
{
226
227
  SDL_Rect area = {0, 0, 0, 0};
227
 
 
228
 
  while (pGUI_List) {
229
 
    area.x = pGUI_List->dst->dest_rect.x + pGUI_List->size.x;
230
 
    area.y = pGUI_List->dst->dest_rect.y + pGUI_List->size.y;
231
 
    area.w = pGUI_List->size.w;
232
 
    area.h = pGUI_List->size.h;
 
228
  struct widget *pWidget;
 
229
  
 
230
  pWidget = pStartWidget ? pStartWidget : pBeginMainWidgetList;
 
231
  
 
232
  while (pWidget) {
 
233
    area.x = pWidget->dst->dest_rect.x + pWidget->size.x;
 
234
    area.y = pWidget->dst->dest_rect.y + pWidget->size.y;
 
235
    area.w = pWidget->size.w;
 
236
    area.h = pWidget->size.h;
233
237
    if (is_in_rect_area(x, y, area)
234
 
       && !((get_wflags(pGUI_List) & WF_HIDDEN) == WF_HIDDEN)) {
235
 
      return (struct widget *) pGUI_List;
 
238
       && !((get_wflags(pWidget) & WF_HIDDEN) == WF_HIDDEN)) {
 
239
      return (struct widget *) pWidget;
236
240
    }
237
 
    pGUI_List = pGUI_List->next;
 
241
    pWidget = pWidget->next;
238
242
  }
239
243
  return NULL;
240
244
}
241
245
 
242
246
/**************************************************************************
243
 
  Search in 'pGUI_List' == "Widget's list" and
244
 
  return ( not Disabled and not Hiden ) widget with 'Key' allias.
 
247
  Find the next enabled and visible widget in the widget list starting
 
248
  with pStartWidget that handles the given key. If pStartWidget is NULL,
 
249
  the search starts with the first entry of the main widget list.
245
250
  NOTE: This function ignores CapsLock and NumLock Keys.
246
251
**************************************************************************/
247
 
struct widget *WidgetListKeyScaner(const struct widget *pGUI_List, SDL_keysym Key)
 
252
struct widget *find_next_widget_for_key(struct widget *pStartWidget,
 
253
                                        SDL_keysym key)
248
254
{
249
 
  Key.mod &= ~(KMOD_NUM | KMOD_CAPS);
250
 
  while (pGUI_List) {
251
 
    if ((pGUI_List->key == Key.sym ||
252
 
      (pGUI_List->key == SDLK_RETURN && Key.sym == SDLK_KP_ENTER) ||
253
 
      (pGUI_List->key == SDLK_KP_ENTER && Key.sym == SDLK_RETURN)) &&
254
 
        ((pGUI_List->mod & Key.mod) || (pGUI_List->mod == Key.mod))) {
255
 
      if (!((get_wstate(pGUI_List) == FC_WS_DISABLED) ||
256
 
            ((get_wflags(pGUI_List) & WF_HIDDEN) == WF_HIDDEN))) {
257
 
        return (struct widget *) pGUI_List;
 
255
  struct widget *pWidget;
 
256
  
 
257
  pWidget = pStartWidget ? pStartWidget : pBeginMainWidgetList;
 
258
  
 
259
  key.mod &= ~(KMOD_NUM | KMOD_CAPS);
 
260
  while (pWidget) {
 
261
    if ((pWidget->key == key.sym ||
 
262
      (pWidget->key == SDLK_RETURN && key.sym == SDLK_KP_ENTER) ||
 
263
      (pWidget->key == SDLK_KP_ENTER && key.sym == SDLK_RETURN)) &&
 
264
        ((pWidget->mod & key.mod) || (pWidget->mod == key.mod))) {
 
265
      if (!((get_wstate(pWidget) == FC_WS_DISABLED) ||
 
266
            ((get_wflags(pWidget) & WF_HIDDEN) == WF_HIDDEN))) {
 
267
        return (struct widget *) pWidget;
258
268
      }
259
269
    }
260
 
    pGUI_List = pGUI_List->next;
 
270
    pWidget = pWidget->next;
261
271
  }
262
272
  return NULL;
263
273
}
264
274
 
265
275
/**************************************************************************
266
 
  Pointer to Main Widget list is declared staric in 'gui_stuff.c'
267
 
  This function only calls 'WidgetListScaner' in Main list
268
 
  'pBeginMainWidgetList'
269
 
**************************************************************************/
270
 
struct widget *MainWidgetListScaner(int x, int y)
271
 
{
272
 
  return WidgetListScaner(pBeginMainWidgetList, x, y);
273
 
}
274
 
 
275
 
/**************************************************************************
276
 
  ...
277
 
**************************************************************************/
278
 
struct widget *MainWidgetListKeyScaner(SDL_keysym Key)
279
 
{
280
 
  return WidgetListKeyScaner(pBeginMainWidgetList, Key);
281
 
}
282
 
 
283
 
/**************************************************************************
284
276
  Do default Widget action when pressed, and then call widget callback
285
277
  function.
286
278
 
398
390
    default:
399
391
      ID = pWidget->ID;
400
392
      if (pWidget->action) {
401
 
        if (pWidget->action(pWidget)) {
 
393
        if (pWidget->action(pWidget) != 0) {
402
394
          ID = 0;
403
395
        }
404
396
      }