Пример #1
0
/**************************************************************************
  ...
**************************************************************************/
static void widget_core_mark_dirty(struct widget *pwidget)
{
  SDL_Rect rect = {
    pwidget->dst->dest_rect.x + pwidget->size.x,
    pwidget->dst->dest_rect.y + pwidget->size.y,
    pwidget->size.w,
    pwidget->size.h
  };

  sdl_dirty_rect(rect);
}
Пример #2
0
/**************************************************************************
  Do default Widget action when pressed, and then call widget callback
  function.

  example for Button:
    set flags FW_Pressed
    redraw button ( pressed )
    refresh screen ( to see result )
    wait 300 ms	( to see result :)
    If exist (button callback function) then
      call (button callback function)

    Function normal return Widget ID.
    NOTE: NOZERO return of this function deterninate exit of
        MAIN_SDL_GAME_LOOP
    if ( pWidget->action )
      if ( pWidget->action(pWidget)  ) ID = 0;
    if widget callback function return = 0 then return NOZERO
    I default return (-1) from Widget callback functions.
**************************************************************************/
Uint16 widget_pressed_action(struct widget * pWidget)
{
  Uint16 ID = 0;

  if (!pWidget) {
    return 0;
  }
  
  widget_info_counter = 0;
  if (pInfo_Area) {
    sdl_dirty_rect(*pInfo_Area);
    FC_FREE(pInfo_Area);
    FREESURFACE(pInfo_Label);
  }

  switch (get_wtype(pWidget)) {
    case WT_TI_BUTTON:
    case WT_I_BUTTON:    
    case WT_ICON:
    case WT_ICON2:
      if (Main.event.button.button == SDL_BUTTON_LEFT) {
        set_wstate(pWidget, FC_WS_PRESSED);
        widget_redraw(pWidget);
        widget_mark_dirty(pWidget);
        flush_dirty();
        set_wstate(pWidget, FC_WS_SELLECTED);
        SDL_Delay(300);
      }
      ID = pWidget->ID;
      if (pWidget->action) {
        if (pWidget->action(pWidget)) {
          ID = 0;
        }
      }
      break;

    case WT_EDIT:
    {
      if (Main.event.button.button == SDL_BUTTON_LEFT) {
        bool ret, loop = ((get_wflags(pWidget) & WF_EDIT_LOOP) == WF_EDIT_LOOP);
        enum Edit_Return_Codes change;
        do {
          ret = FALSE;
          change = edit_field(pWidget);
          if (change != ED_FORCE_EXIT && (!loop || change != ED_RETURN)) {
            widget_redraw(pWidget);
            widget_mark_dirty(pWidget);
            flush_dirty();
          }
          if (change != ED_FORCE_EXIT && change != ED_ESC && pWidget->action) {
            if (pWidget->action(pWidget)) {
              ID = 0;
            }
          }
          if (loop && change == ED_RETURN) {
            ret = TRUE;
          }
        } while(ret);
        ID = 0;
      }
      break;
    }
    case WT_VSCROLLBAR:
    case WT_HSCROLLBAR:
      if (Main.event.button.button == SDL_BUTTON_LEFT) {
        set_wstate(pWidget, FC_WS_PRESSED);
        widget_redraw(pWidget);
        widget_mark_dirty(pWidget);
        flush_dirty();
      }
      ID = pWidget->ID;
      if (pWidget->action) {
        if (pWidget->action(pWidget)) {
          ID = 0;
        }
      }
      break;
    case WT_CHECKBOX:
    case WT_TCHECKBOX:
      if (Main.event.button.button == SDL_BUTTON_LEFT) {
        set_wstate(pWidget, FC_WS_PRESSED);
        widget_redraw(pWidget);
        widget_mark_dirty(pWidget);
        flush_dirty();
        set_wstate(pWidget, FC_WS_SELLECTED);
        togle_checkbox(pWidget);
        SDL_Delay(300);
      }
      ID = pWidget->ID;  
      if (pWidget->action) {
        if (pWidget->action(pWidget)) {
          ID = 0;
        }
      }
      break;
    case WT_COMBO:
      if (Main.event.button.button == SDL_BUTTON_LEFT) {
        set_wstate(pWidget, FC_WS_PRESSED);
        combo_popup(pWidget);
      } else {
        combo_popdown(pWidget);
      }
      break;
    default:
      ID = pWidget->ID;
      if (pWidget->action) {
        if (pWidget->action(pWidget) != 0) {
          ID = 0;
        }
      }
      break;
  }

  return ID;
}