Logo Search packages:      
Sourcecode: adesklets version File versions

int imlib_text_get_index_and_location ( const char *  text,
int  x,
int  y,
int *  char_x_return,
int *  char_y_return,
int *  char_width_return,
int *  char_height_return 
)

Parameters:
text A string.
x The x offset.
y The y offset.
char_x_return The x coordinate of the character.
char_y_return The x coordinate of the character.
char_width_return The width of the character.
char_height_return The height of the character.
Returns:
-1 if no character found.
Returns the character number in the string text using the current font at the (x, y) pixel location which is an offset relative to the top left of that string. -1 is returned if there is no character there. If there is a character, char_x_return, char_y_return, char_width_return and char_height_return (respectively the character x, y, width and height) are also filled in.

Definition at line 3836 of file imlib2.c.

References imlib_get_text_size().

{
   ImlibFont          *fn;
   int                 w, h, cx, cy, cw, ch, cp, xx, yy;
   int                 dir;

   if (!ctx)
      ctx = imlib_context_new();
   CHECK_PARAM_POINTER_RETURN("imlib_text_get_index_and_location", "font",
                              ctx->font, -1);
   CHECK_PARAM_POINTER_RETURN("imlib_text_get_index_and_location", "text",
                              text, -1);
   fn = (ImlibFont *) ctx->font;

   dir = ctx->direction;
   if (ctx->direction == IMLIB_TEXT_TO_ANGLE && ctx->angle == 0.0)
      dir = IMLIB_TEXT_TO_RIGHT;

   imlib_get_text_size(text, &w, &h);

   switch (dir)
     {
       case IMLIB_TEXT_TO_RIGHT:
          xx = x;
          yy = y;
          break;
       case IMLIB_TEXT_TO_LEFT:
          xx = w - x;
          yy = h - y;
          break;
       case IMLIB_TEXT_TO_DOWN:
          xx = y;
          yy = w - x;
          break;
       case IMLIB_TEXT_TO_UP:
          xx = h - y;
          yy = x;
          break;
       default:
          return -1;
     }

   cp = imlib_font_query_text_at_pos(fn, text, xx, yy, &cx, &cy, &cw, &ch);

   switch (dir)
     {
       case IMLIB_TEXT_TO_RIGHT:
          if (char_x_return)
             *char_x_return = cx;
          if (char_y_return)
             *char_y_return = cy;
          if (char_width_return)
             *char_width_return = cw;
          if (char_height_return)
             *char_height_return = ch;
          return cp;
          break;
       case IMLIB_TEXT_TO_LEFT:
          cx = 1 + w - cx - cw;
          if (char_x_return)
             *char_x_return = cx;
          if (char_y_return)
             *char_y_return = cy;
          if (char_width_return)
             *char_width_return = cw;
          if (char_height_return)
             *char_height_return = ch;
          return cp;
          break;
       case IMLIB_TEXT_TO_DOWN:
          if (char_x_return)
             *char_x_return = cy;
          if (char_y_return)
             *char_y_return = cx;
          if (char_width_return)
             *char_width_return = ch;
          if (char_height_return)
             *char_height_return = cw;
          return cp;
          break;
       case IMLIB_TEXT_TO_UP:
          cy = 1 + h - cy - ch;
          if (char_x_return)
             *char_x_return = cy;
          if (char_y_return)
             *char_y_return = cx;
          if (char_width_return)
             *char_width_return = ch;
          if (char_height_return)
             *char_height_return = cw;
          return cp;
          break;
       default:
          return -1;
          break;
     }
   return -1;
}


Generated by  Doxygen 1.6.0   Back to index