Exemplo n.º 1
0
/**************************************************************************
  ...
**************************************************************************/
static int redraw_icon(struct widget *pIcon)
{
  int ret;
  SDL_Rect src, area = pIcon->size;

  ret = (*checkbox_baseclass_redraw)(pIcon);
  if (ret != 0) {
    return ret;
  }
  
  if (!pIcon->theme) {
    return -3;
  }

  src.x = (pIcon->theme->w / 4) * (Uint8) (get_wstate(pIcon));
  src.y = 0;
  src.w = (pIcon->theme->w / 4);
  src.h = pIcon->theme->h;

  if (pIcon->size.w != src.w) {
    area.x += (pIcon->size.w - src.w) / 2;
  }

  if (pIcon->size.h != src.h) {
    area.y += (pIcon->size.h - src.h) / 2;
  }

  return alphablit(pIcon->theme, &src, pIcon->dst->surface, &area);
}
Exemplo n.º 2
0
/**************************************************************************
  ...
**************************************************************************/
static int redraw_textcheckbox(struct widget *pCBox)
{
  int ret;
  SDL_Surface *pTheme_Surface, *pIcon;

  ret = (*textcheckbox_baseclass_redraw)(pCBox);
  if (ret != 0) {
    return ret;
  }

  if(!pCBox->string16) {
    return widget_redraw(pCBox);
  }

  pTheme_Surface = pCBox->theme;
  pIcon = create_icon_from_theme(pTheme_Surface, get_wstate(pCBox));
  
  if (!pIcon) {
    return -3;
  }
  
  pCBox->theme = pIcon;

  /* redraw icon label */
  ret = redraw_iconlabel(pCBox);

  FREESURFACE(pIcon);
  pCBox->theme = pTheme_Surface;

  return ret;
}
Exemplo n.º 3
0
/**************************************************************************
  Main mouse click handler.
**************************************************************************/
static Uint16 main_mouse_button_down_handler(SDL_MouseButtonEvent *pButtonEvent, void *pData)
{
    struct widget *pWidget;

    if ((pWidget = find_next_widget_at_pos(NULL,
                                           pButtonEvent->x,
                                           pButtonEvent->y)) != NULL) {
        if (!(get_wstate(pWidget) == FC_WS_DISABLED)) {
            return widget_pressed_action(pWidget);
        }
    } else {
        /* no visible widget at this position -> map click */
#ifdef UNDER_CE
        if (!check_scroll_area(pButtonEvent->x, pButtonEvent->y)) {
#endif
            if (!button_behavior.counting) {
                /* start counting */
                button_behavior.counting = TRUE;
                button_behavior.button_down_ticks = SDL_GetTicks();
                *button_behavior.event = *pButtonEvent;
                button_behavior.hold_state = MB_HOLD_SHORT;
                button_behavior.ptile = canvas_pos_to_tile(pButtonEvent->x, pButtonEvent->y);
            }
#ifdef UNDER_CE
        }
#endif
    }
    return ID_ERROR;
}
Exemplo n.º 4
0
/**************************************************************************
  ...
**************************************************************************/
static int redraw_icon2(struct widget *pIcon)
{
  int ret;
  SDL_Rect dest;
  Uint32 state;

  ret = (*baseclass_redraw)(pIcon);
  if (ret != 0) {
    return ret;
  }

  if(!pIcon) {
    return -3;
  }
  
  if(!pIcon->theme) {
    return -4;
  }
  
  state = get_wstate(pIcon);
    
  dest.x = pIcon->size.x;
  dest.y = pIcon->size.y;
  dest.w = pIcon->theme->w;
  dest.h = pIcon->theme->h;

  if (state == FC_WS_SELLECTED) {
    putframe(pIcon->dst->surface,
             dest.x + 1, dest.y + 1,
             dest.x + dest.w + adj_size(2), dest.y + dest.h + adj_size(2),
             get_theme_color(COLOR_THEME_CUSTOM_WIDGET_SELECTED_FRAME));
  }

  if (state == FC_WS_PRESSED) {
    putframe(pIcon->dst->surface,
             dest.x + 1, dest.y + 1,
             dest.x + dest.w + adj_size(2), dest.y + dest.h + adj_size(2),
             get_theme_color(COLOR_THEME_CUSTOM_WIDGET_SELECTED_FRAME));

    putframe(pIcon->dst->surface,
             dest.x, dest.y,
             dest.x + dest.w + adj_size(3), dest.y + dest.h + adj_size(3),
             get_theme_color(COLOR_THEME_CUSTOM_WIDGET_PRESSED_FRAME));
  }

  if (state == FC_WS_DISABLED) {
    putframe(pIcon->dst->surface,
             dest.x + 1, dest.y + 1,
             dest.x + dest.w + adj_size(2), dest.y + dest.h + adj_size(2),
             get_theme_color(COLOR_THEME_WIDGET_DISABLED_TEXT));
  }
  dest.x += adj_size(2);
  dest.y += adj_size(2);
  ret = alphablit(pIcon->theme, NULL, pIcon->dst->surface, &dest);
  if (ret) {
    return ret;
  }

  return 0;
}
Exemplo n.º 5
0
/**************************************************************************
  ...
**************************************************************************/
int draw_icon(struct widget *pIcon, Sint16 start_x, Sint16 start_y)
{
  pIcon->size.x = start_x;
  pIcon->size.y = start_y;

  if (get_wflags(pIcon) & WF_RESTORE_BACKGROUND) {
    refresh_widget_background(pIcon);
  }

  return draw_icon_from_theme(pIcon->theme, get_wstate(pIcon), pIcon->dst,
			      pIcon->size.x, pIcon->size.y);
}
Exemplo n.º 6
0
/**************************************************************************
  Main handler for mouse movement handling.
**************************************************************************/
static Uint16 main_mouse_motion_handler(SDL_MouseMotionEvent *pMotionEvent, void *pData)
{
    static struct widget *pWidget;
    struct tile *ptile;

    /* stop evaluating button hold time when moving to another tile in medium
     * hold state or above */
    if (button_behavior.counting && (button_behavior.hold_state >= MB_HOLD_MEDIUM)) {
        ptile = canvas_pos_to_tile(pMotionEvent->x, pMotionEvent->y);
        if (tile_index(ptile) != tile_index(button_behavior.ptile)) {
            button_behavior.counting = FALSE;
        }
    }

    if(draw_goto_patrol_lines) {
        update_line(pMotionEvent->x, pMotionEvent->y);
    }

#ifndef UNDER_CE
    if (gui_sdl_fullscreen) {
        check_scroll_area(pMotionEvent->x, pMotionEvent->y);
    }
#endif /* UNDER_CE */

    if ((pWidget = find_next_widget_at_pos(NULL,
                                           pMotionEvent->x,
                                           pMotionEvent->y)) != NULL) {
        update_mouse_cursor(CURSOR_DEFAULT);
        if (!(get_wstate(pWidget) == FC_WS_DISABLED)) {
            widget_sellected_action(pWidget);
        }
    } else {
        if (pSellected_Widget) {
            unsellect_widget_action();
        } else {
            control_mouse_cursor(canvas_pos_to_tile(pMotionEvent->x, pMotionEvent->y));
        }
    }

    draw_mouse_cursor();

    return ID_ERROR;
}
Exemplo n.º 7
0
/**************************************************************************
  Unsellect (sellected) widget and redraw this widget;
**************************************************************************/
void unsellect_widget_action(void)
{
  if (pSellected_Widget && (get_wstate(pSellected_Widget) != FC_WS_DISABLED)) {
    
      set_wstate(pSellected_Widget, FC_WS_NORMAL);
  
      if (!(get_wflags(pSellected_Widget) & WF_HIDDEN)) {
        pSellected_Widget->unselect(pSellected_Widget);
        
        /* turn off quick info timer/counter */ 
        widget_info_counter = 0;
      }
  }

  if (pInfo_Area) {
    flush_rect(*pInfo_Area, FALSE);
    FC_FREE(pInfo_Area);
    FREESURFACE(pInfo_Label);    
  }

  pSellected_Widget = NULL;
}
Exemplo n.º 8
0
/**************************************************************************
  Find the next enabled and visible widget in the widget list starting
  with pStartWidget that handles the given key. If pStartWidget is NULL,
  the search starts with the first entry of the main widget list.
  NOTE: This function ignores CapsLock and NumLock Keys.
**************************************************************************/
struct widget *find_next_widget_for_key(struct widget *pStartWidget,
                                        SDL_keysym key)
{
  struct widget *pWidget;
  
  pWidget = pStartWidget ? pStartWidget : pBeginMainWidgetList;
  
  key.mod &= ~(KMOD_NUM | KMOD_CAPS);
  while (pWidget) {
    if ((pWidget->key == key.sym ||
      (pWidget->key == SDLK_RETURN && key.sym == SDLK_KP_ENTER) ||
      (pWidget->key == SDLK_KP_ENTER && key.sym == SDLK_RETURN)) &&
	((pWidget->mod & key.mod) || (pWidget->mod == key.mod))) {
      if (!((get_wstate(pWidget) == FC_WS_DISABLED) ||
	    ((get_wflags(pWidget) & WF_HIDDEN) == WF_HIDDEN))) {
	return (struct widget *) pWidget;
      }
    }
    pWidget = pWidget->next;
  }
  return NULL;
}
Exemplo n.º 9
0
/**************************************************************************
  Create Icon Button image with text and Icon then blit to Dest(ination)
  on positon pTIButton->size.x , pTIButton->size.y. WARRING: pDest must
  exist.

  Text with atributes is taken from pTIButton->string16 parameter.

  Graphic for button is taken from pTIButton->theme surface 
  and blit to new created image.

  Graphic for Icon Theme is taken from pTIButton->theme2 surface 
  and blit to new created image.

  function return (-1) if there are no Icon and Text.  Else return 0.
**************************************************************************/
static int redraw_tibutton(struct widget *pTIButton)
{
  int iRet = 0;
  SDL_Surface *pIcon;
  SDL_Surface *pCopy_Of_Icon_Theme;

  iRet = (*baseclass_redraw)(pTIButton);
  if (iRet != 0) {
    return iRet;
  }
  
  pIcon = create_icon_from_theme(pTIButton->theme2, get_wstate(pTIButton));
  pCopy_Of_Icon_Theme = pTIButton->theme2;

  pTIButton->theme2 = pIcon;

  iRet = redraw_ibutton(pTIButton);

  FREESURFACE(pTIButton->theme2);
  pTIButton->theme2 = pCopy_Of_Icon_Theme;

  return iRet;
}
Exemplo n.º 10
0
/**************************************************************************
  Create Icon Button image with text and Icon then blit to Dest(ination)
  on positon pIButton->size.x , pIButton->size.y.
  WARRING: pDest must exist.

  Text with atributes is taken from pIButton->string16 parameter.

  Graphic for button is taken from pIButton->theme surface 
  and blit to new created image.

  Graphic for Icon is taken from pIButton->theme2 surface and blit to new
  created image.

  function return (-1) if there are no Icon and Text.
  Else return 0.
**************************************************************************/
static int redraw_ibutton(struct widget *pIButton)
{
  SDL_Rect dest = { 0, 0, 0, 0 };
  SDL_String16 TMPString;
  SDL_Surface *pButton = NULL, *pText = NULL, *pIcon = pIButton->theme2;
  Uint16 Ix, Iy, x;
  Uint16 y = 0; /* FIXME: possibly uninitialized */
  int ret;
  
  ret = (*baseclass_redraw)(pIButton);
  if (ret != 0) {
    return ret;
  }

  if (pIButton->string16) {

    /* make copy of string16 */
    TMPString = *pIButton->string16;

    if (get_wstate(pIButton) == FC_WS_NORMAL) {
      TMPString.fgcol = *get_theme_color(COLOR_THEME_WIDGET_NORMAL_TEXT);
    } else if (get_wstate(pIButton) == FC_WS_SELLECTED) {
      TMPString.fgcol = *get_theme_color(COLOR_THEME_WIDGET_SELECTED_TEXT);
      TMPString.style |= TTF_STYLE_BOLD;
    } else if (get_wstate(pIButton) == FC_WS_PRESSED) {
      TMPString.fgcol = *get_theme_color(COLOR_THEME_WIDGET_PRESSED_TEXT);
    } else if (get_wstate(pIButton) == FC_WS_DISABLED) {
      TMPString.fgcol = *get_theme_color(COLOR_THEME_WIDGET_DISABLED_TEXT);
    }

    pText = create_text_surf_from_str16(&TMPString);
  }

  if (!pText && !pIcon) {
    return -1;
  }

  /* create Button graphic */
  pButton = create_bcgnd_surf(pIButton->theme, get_wstate(pIButton),
			      pIButton->size.w, pIButton->size.h);

  clear_surface(pIButton->dst->surface, &pIButton->size);
  alphablit(pButton, NULL, pIButton->dst->surface, &pIButton->size);
  FREESURFACE(pButton);

  if (pIcon) {			/* Icon */
    if (pText) {
      if (get_wflags(pIButton) & WF_ICON_CENTER_RIGHT) {
	Ix = pIButton->size.w - pIcon->w - 5;
      } else {
	if (get_wflags(pIButton) & WF_ICON_CENTER) {
	  Ix = (pIButton->size.w - pIcon->w) / 2;
	} else {
	  Ix = 5;
	}
      }

      if (get_wflags(pIButton) & WF_ICON_ABOVE_TEXT) {
	Iy = 3;
	y = 3 + pIcon->h + 3 + (pIButton->size.h -
				(pIcon->h + 6) - pText->h) / 2;
      } else {
	if (get_wflags(pIButton) & WF_ICON_UNDER_TEXT) {
	  y = 3 + (pIButton->size.h - (pIcon->h + 3) - pText->h) / 2;
	  Iy = y + pText->h + 3;
	} else {		/* center */
	  Iy = (pIButton->size.h - pIcon->h) / 2;
	  y = (pIButton->size.h - pText->h) / 2;
	}
      }
    } else {			/* no text */
      Iy = (pIButton->size.h - pIcon->h) / 2;
      Ix = (pIButton->size.w - pIcon->w) / 2;
    }

    if (get_wstate(pIButton) == FC_WS_PRESSED) {
      Ix += 1;
      Iy += 1;
    }


    dest.x = pIButton->size.x + Ix;
    dest.y = pIButton->size.y + Iy;

    ret = alphablit(pIcon, NULL, pIButton->dst->surface, &dest);
    if (ret) {
      FREESURFACE(pText);
      return ret - 10;
    }
  }

  if (pText) {

    if (pIcon) {
      if (!(get_wflags(pIButton) & WF_ICON_ABOVE_TEXT) &&
	  !(get_wflags(pIButton) & WF_ICON_UNDER_TEXT)) {
	if (get_wflags(pIButton) & WF_ICON_CENTER_RIGHT) {
	  if (pIButton->string16->style & SF_CENTER) {
	    x = (pIButton->size.w - (pIcon->w + 5) - pText->w) / 2;
	  } else {
	    if (pIButton->string16->style & SF_CENTER_RIGHT) {
	      x = pIButton->size.w - (pIcon->w + 7) - pText->w;
	    } else {
	      x = 5;
	    }
	  }
	} /* end WF_ICON_CENTER_RIGHT */
	else {
	  if (get_wflags(pIButton) & WF_ICON_CENTER) {
	    /* text is blit on icon */
	    goto Alone;
	  } /* end WF_ICON_CENTER */
	  else {		/* icon center left - default */
	    if (pIButton->string16->style & SF_CENTER) {
	      x = 5 + pIcon->w + ((pIButton->size.w -
				   (pIcon->w + 5) - pText->w) / 2);
	    } else {
	      if (pIButton->string16->style & SF_CENTER_RIGHT) {
		x = pIButton->size.w - pText->w - 5;
	      } else {		/* text center left */
		x = 5 + pIcon->w + 3;
	      }
	    }

	  }			/* end icon center left - default */

	}
	/* 888888888888888888 */
      } else {
	goto Alone;
      }
    } else {
      /* !pIcon */
      y = (pIButton->size.h - pText->h) / 2;
    Alone:
      if (pIButton->string16->style & SF_CENTER) {
	x = (pIButton->size.w - pText->w) / 2;
      } else {
	if (pIButton->string16->style & SF_CENTER_RIGHT) {
	  x = pIButton->size.w - pText->w - 5;
	} else {
	  x = 5;
	}
      }
    }

    if (get_wstate(pIButton) == FC_WS_PRESSED) {
      x += 1;
    } else {
      y -= 1;
    }

    dest.x = pIButton->size.x + x;
    dest.y = pIButton->size.y + y;

    ret = alphablit(pText, NULL, pIButton->dst->surface, &dest);
  }

  FREESURFACE(pText);

  return 0;
}
Exemplo n.º 11
0
/**************************************************************************
  Create Edit Field surface ( with Text) and blit them to Main.screen,
  on position 'pEdit_Widget->size.x , pEdit_Widget->size.y'

  Graphic is taken from 'pEdit_Widget->theme'
  Text is taken from	'pEdit_Widget->sting16'

  if flag 'FW_DRAW_THEME_TRANSPARENT' is set theme will be blit
  transparent ( Alpha = 128 )

  function return Hight of created surfaces or (-1) if theme surface can't
  be created.
**************************************************************************/
static int redraw_edit(struct widget *pEdit_Widget)
{
  int ret;
  
  if (get_wstate(pEdit_Widget) == FC_WS_PRESSED) {
    return redraw_edit_chain((struct EDIT *)pEdit_Widget->data.ptr);
  } else {
    int iRet = 0;
    SDL_Rect rDest = {pEdit_Widget->size.x, pEdit_Widget->size.y, 0, 0};
    SDL_Surface *pEdit = NULL;
    SDL_Surface *pText;

    ret = (*baseclass_redraw)(pEdit_Widget);
    if (ret != 0) {
      return ret;
    }
    
    if (pEdit_Widget->string16->text &&
    	get_wflags(pEdit_Widget) & WF_PASSWD_EDIT) {
      Uint16 *backup = pEdit_Widget->string16->text;
      size_t len = unistrlen(backup) + 1;
      char *cBuf = fc_calloc(1, len);
    
      memset(cBuf, '*', len - 1);
      cBuf[len - 1] = '\0';
      pEdit_Widget->string16->text = convert_to_utf16(cBuf);
      pText = create_text_surf_from_str16(pEdit_Widget->string16);
      FC_FREE(pEdit_Widget->string16->text);
      FC_FREE(cBuf);
      pEdit_Widget->string16->text = backup;
    } else {
      pText = create_text_surf_from_str16(pEdit_Widget->string16);
    }
  
    pEdit = create_bcgnd_surf(pEdit_Widget->theme, get_wstate(pEdit_Widget),
                              pEdit_Widget->size.w, pEdit_Widget->size.h);

    if (!pEdit) {
      return -1;
    }
    
    /* blit theme */
    alphablit(pEdit, NULL, pEdit_Widget->dst->surface, &rDest);

    /* set position and blit text */
    if (pText) {
      rDest.y += (pEdit->h - pText->h) / 2;
      /* blit centred text to botton */
      if (pEdit_Widget->string16->style & SF_CENTER) {
        rDest.x += (pEdit->w - pText->w) / 2;
      } else {
        if (pEdit_Widget->string16->style & SF_CENTER_RIGHT) {
	  rDest.x += pEdit->w - pText->w - adj_size(5);
        } else {
	  rDest.x += adj_size(5);		/* cennter left */
        }
      }

      alphablit(pText, NULL, pEdit_Widget->dst->surface, &rDest);
    }
    /* pText */
    iRet = pEdit->h;

    /* Free memory */
    FREESURFACE(pText);
    FREESURFACE(pEdit);
    return iRet;
  }
  return 0;
}