Beispiel #1
0
/*===========================================================================
   This function fits the text within the IStatic rectangle so that the
   scroll bar is not drawn.
===========================================================================*/
void TS_FitStaticText(IDisplay * pd, IStatic * ps, AEEFont font, AECHAR * pszText)
{
   int      nFits;
   AEERect  rect;
   int      nLen = WSTRLEN(pszText);
   AECHAR   chSave = (AECHAR)0;

   ISTATIC_GetRect(ps, &rect);
   IDISPLAY_MeasureTextEx(pd, font, pszText, -1, rect.dx,  &nFits);
   if (nFits < nLen)
   {
      chSave = pszText[nFits];
      pszText[nFits] = (AECHAR)0;
   }
   ISTATIC_SetText(ps, NULL, pszText, AEE_FONT_NORMAL, font);
   if (nFits < nLen)
      pszText[nFits] = chSave;

   ISTATIC_Redraw(ps);
}
Beispiel #2
0
void COMMON_Draw(Common* common)
{
    IDisplay* d = common->display;
    int i = 0;
    int j = 0;
    int len = WSTRLEN(common->message);

    IDISPLAY_ClearScreen(d);
    common->lines = 0;
    while ((i < len - 1) && ((common->lines - common->start_line) * common->font_height < common->height)) {
        AECHAR t;
        int l;

        IDISPLAY_MeasureTextEx(d, AEE_FONT_NORMAL, common->message + i, len - i, common->width, &j);
        for (l = 0; l < j; l++) {
            if (common->message[i + l] == 0x0D || common->message[i + l] == '\n') {
                j = l;
                break;
            }
        }
        t = common->message[i + j];
        common->message[i + j] = 0;
        if (common->start_line <= common->lines) {
            IDISPLAY_DrawText(d, AEE_FONT_NORMAL, common->message + i, -1, 0, (common->lines - common->start_line) * common->font_height, NULL, IDF_ALIGN_LEFT);
        }
        common->message[i + j] = t;
        i += j;
        if (t == 0x0D) {
            i += 2;
        }
        if (t == '\n') {
            i++;
        }
        common->lines++;
    }
    IDISPLAY_Update(d);
    return;
}
Beispiel #3
0
/*===========================================================================

FUNCTION: DisplayOutput

DESCRIPTION
    This function displays an output string at a given line number on the
    screen. If the nline parameter is a negative value (-1) the string
    is displayed in the middle of the screen. If the "nline" value is larger
    than or equal to zero the "nline" value is multiplied by 15 and the 
    resulting value in pixels is set to the y-coordinate of the start of 
    the string display on the screen. If the string does not fit on one line
    the string wraps around to the next line (spaced rougly 10-15 pixels apart).
    By default 5 is used as the starting the x-coordinate of a displayed 
    string.

    How many characters that fit on one line is calculated for each line 
    that is wrapped around to the next line.

    Note: depending on the phone screen size and the fonts used for characters 
          the output might differ on different handsets (devices). Where some 
          handsets will have a smaller screen and large default fonts which will 
          cause partial overlapping of lines. This function does not try to address
          these issues (this is meant as a simple display function).
    
PROTOTYPE:
   int DisplayOutput(IShell *pIShell, IDisplay *pDisplay, int nline, char *pszStr, AECHAR *pszwStr, boolean isWideChar)

PARAMETERS:
   pIShell:   [in]: Contains a pointer to the IShell interface.
   pIDisplay: [in]: Contains a pointer to the IDisplay interface.
   nline:     [in]: Contains the line number to start displaying the text. The line
        numbers are by default spaced 15 pixels apart along the y-axis.
   pszStr:    [in]: The character string to be displayed on the screen.

DEPENDENCIES
  None

RETURN VALUE
  Number of lines written to the screen.

SIDE EFFECTS
  None

===========================================================================*/
static int DisplayOutput(IShell *pIShell, IDisplay *pIDisplay, int nline, char *pszStr, AECHAR *pszwStr, boolean isWideChar)
{
  AEEDeviceInfo di; // Device Info
  AECHAR * szBuf;     // a buffer that supports 200 char string
  AECHAR * psz = NULL;
  int charHeight = 0;      // Stores the char height in pixels for given font
  int pnAscent = 0;        // Stores the ascent in number of pixels
  int pnDescent = 0;       // Stores the descent in number of pixels
  int pixelWidth;
  AEEFont font = AEE_FONT_NORMAL;
  int pnFits = 0, dy;
  int totalCh = 0;
  int numLinesPrinted = 0;

  // Make sure the pointers we'll be using are valid
  if (pIShell == NULL || pIDisplay == NULL)
  {
    return 0;
  }
  
  if ((szBuf = (AECHAR *) MALLOC(TEXT_BUFFER_SIZE)) == NULL)
  {
    return 0;
  }
  // Get device information
  ISHELL_GetDeviceInfo(pIShell,&di);

  // Get the font metrics info
  charHeight = IDISPLAY_GetFontMetrics (pIDisplay, AEE_FONT_NORMAL,
     &pnAscent, &pnDescent);
  if(isWideChar)
  {
       WSTRCPY(szBuf,pszwStr);
  }
  else
  {
   // Convert to wide string (unicode)
   STR_TO_WSTR ((char *)pszStr, szBuf, TEXT_BUFFER_SIZE);
  }
  // If nlines is zero then print this string starting around the middle of 
  // the screen. Or else multiply nlines by charheight to decide the y coordinate of
  // the start of the string.
  if (nline < 0) {
     dy = di.cyScreen*2/5;
  }
  else{
     dy = nline * charHeight + 5;
  }

  // psz keeps track of the point from which to write from the string buffer
  // in case the string does not fit one line and needs to wrap around in the
  // next line.
  psz = szBuf;
     
  // Need to calculate the lotal string length to decide if any wrapping
  // around is needed.
  if(isWideChar)
  {
       totalCh = 2*WSTRLEN (pszwStr);
  }
  else
  {
       totalCh = STRLEN ((char *)pszStr);
  }

  // Keep displaying text string on multiple lines if the string can't be displayed
  // on one single line. Lines are spaced 15 pixels apart.
  while ((totalCh > 0) && (*psz != NULL))
  { 
     // Get information on how many characters will fit in a line.
     // Give the pointer to the buffer to be displayed, and the number of
     // pixels along the x axis you want to display the string in (max number)
     // pnFits will have the max number of chars that will fit in the maxWidth
     // number of pixels (given string can't fit in one line), or the number of 
     // chars in the string (if it does fit in one line). pnWidth gives the
     // number of pixels that will be used to display pnFits number of chars.
     pixelWidth = IDISPLAY_MeasureTextEx(pIDisplay,
                     font, 
                     (AECHAR *) psz,  // Start of the buffer to display,
                     -1,
                     di.cxScreen - 5, // maxWidth
                     &pnFits);         // Number of chars that will fit a line

     // If pnFits is zero there is something wrong in the input to above function. 
     // Normally this scenario should not occur. But, have the check anyway.
     if (pnFits == 0)
     {
       FREE(szBuf);
       return 0;
     }

     IDISPLAY_DrawText(pIDisplay, AEE_FONT_NORMAL, psz, pnFits, 5 /*start dx*/, 
        dy, 0 /* use default rectangle coordinates */, 0);

     psz += pnFits;      // move pointer to the next segment to be displayed
     totalCh -= pnFits;  // reduce the total number of characters to still display
     dy += charHeight;   // Place next line charHeight pixels below the 
                         // previous line.
     ++numLinesPrinted;

     IDISPLAY_Update(pIDisplay); //, TRUE);
     if (totalCh < pnFits)
        pnFits = totalCh;  // if total number is less than pnFits, adjust pnFits
  }

  FREE(szBuf);

  return numLinesPrinted;   
} // End of DisplayOutput