⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abl_swim_font.c

📁 sharp触摸屏测试代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/***********************************************************************
 * $Workfile:   abl_swim_font.c  $
 * $Revision:   1.1  $
 * $Author:   WellsK  $
 * $Date:   Jun 25 2003 14:12:38  $
 *
 * Project: Font management for SWIM
 *
 * Description:
 *     See the sma_swim_font.h header file for a description of this
 *     package.
 *
 * Revision History:
 * $Log:   //smaicnt2/pvcs/VM/sharpmcu/archives/sharpmcu/software/abl/source/abl_swim_font.c-arc  $
 * 
 *    Rev 1.1   Jun 25 2003 14:12:38   WellsK
 * Changed swim_set_font function to accept a pointer to a font
 * data structure as an argument instead of an enumeration.
 * 
 *    Rev 1.0   Jun 09 2003 12:06:28   WellsK
 * Initial revision.
 * 
 *
 ***********************************************************************
 * SHARP MICROELECTRONICS OF THE AMERICAS MAKES NO REPRESENTATION
 * OR WARRANTIES WITH RESPECT TO THE PERFORMANCE OF THIS SOFTWARE,
 * AND SPECIFICALLY DISCLAIMS ANY RESPONSIBILITY FOR ANY DAMAGES, 
 * SPECIAL OR CONSEQUENTIAL, CONNECTED WITH THE USE OF THIS SOFTWARE.
 *
 * SHARP MICROELECTRONICS OF THE AMERICAS PROVIDES THIS SOFTWARE SOLELY 
 * FOR THE PURPOSE OF SOFTWARE DEVELOPMENT INCORPORATING THE USE OF A 
 * SHARP MICROCONTROLLER OR SYSTEM-ON-CHIP PRODUCT. USE OF THIS SOURCE
 * FILE IMPLIES ACCEPTANCE OF THESE CONDITIONS.
 *
 * COPYRIGHT (C) 2001 SHARP MICROELECTRONICS OF THE AMERICAS, INC.
 *     CAMAS, WA
 **********************************************************************/

#include "abl_swim_font.h"

/***********************************************************************
 * Public functions
 **********************************************************************/

/***********************************************************************
 *
 * Function: swim_get_word_len
 *
 * Purpose: Determines the length of the word (in pixels) up to the
 *          first whitespace character.
 *
 * Processing:
 *     The string is searched for the first whitespace occurance. For
 *     each non-whitespace character, the required length of that
 *     character in the window is computed. For the entire string up
 *     to the first whitespace character, the total length is returned.
 *
 * Parameters: 
 *     win  : Window identifier
 *     text : Text string to output in window
 *
 * Outputs: None
 *
 * Returns:
 *     The length of the word (with a stop at the first whitespace) in
 *     the passed string.
 *
 * Notes: None
 *
 **********************************************************************/
INT_16 swim_get_word_len(SWIM_WINDOW_T *win,
                         const CHAR *text)
{
    INT_32 i;
    INT_16 wlen = 0;

    /* Find the length in pixels of the next word (separated by
       whitespace) */
    i = 0;
    while (((UNS_8) text [i] > ' ') && ((UNS_8) text [i] <= 0x7E))
    {
        wlen = wlen + win->font->font_width_table
            [(UNS_8) text [i] - win->font->first_char];
        i++;
    }

    return wlen;
}

/***********************************************************************
 *
 * Function: swim_put_word
 *
 * Purpose: Puts a word in the window, but adds a newline to keep the
 *          word contiguous (without an edge break) if necessary.
 *
 * Processing:
 *     The first word in the string (up to the first whitespace
 *     character) has its total length (based on font) computed and
 *     compared to the right window edge. If the length exceeds the
 *     window edge, a newline occurs and then the word is output.
 *
 * Parameters: 
 *     win  : Window identifier
 *     text : Text string to output in window
 *
 * Outputs:  None
 *
 * Returns: The number of characters output to the display.
 *
 * Notes: None
 *
 **********************************************************************/
INT_32 swim_put_word(SWIM_WINDOW_T *win,
                     const CHAR *text)
{
    INT_32 i;

    /* Will the length of the next word exceed the window margin? */
    if ((swim_get_word_len(win, text) + win->xvpos) > win->xpvmax)
    {
        /* Do a newline */
        swim_put_newline(win);
    }

    /* Put just the word characters on the display up to the next
       non-whitespace character or the end of the string */
    i = 0;
    while (((UNS_8) text [i] > ' ') && ((UNS_8) text [i] <= 0x7E))
    {
        swim_put_char(win, text [i]);
        i++;
    }

    return i;
}

/***********************************************************************
 * Public functions
 **********************************************************************/

/***********************************************************************
 *
 * Function: swim_put_text_xy
 *
 * Purpose: Put text at x, y (char) position on screen
 *
 * Processing:
 *     Set the virtual (upper left) text position in the window and
 *     render the text string at this position.
 *
 * Parameters: 
 *     win  : Window identifier
 *     text : Text string to output in window
 *     x    : Virtual X position of start of text
 *     y    : Virtual Y position of start of text
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes:
 *     X, Y coords are in virtual pixels!
 *
 **********************************************************************/
void swim_put_text_xy(SWIM_WINDOW_T *win,
                      const CHAR *text,
                      INT_32 x,
                      INT_32 y)
{
    /* Convert virtual x, y positon to physical position */
    swim_set_xy(win, x, y);

    /* Display text string */
    swim_put_text(win, text);
}

/***********************************************************************
 *
 * Function: swim_set_xy
 *
 * Purpose: Sets the X, Y pixel coordinates for the next text operation
 *
 * Processing:
 *     Update the X, Y text position pointers, limiting the position to
 *     the window dimensions.
 *
 * Parameters: 
 *     win  : Window identifier
 *     x    : Virtual X position of start of text
 *     y    : Virtual Y position of start of text
 *
 * Outputs:  None
 *
 * Returns: Nothing
 *
 * Notes:
 *     X, Y coords are in virtual pixels!
 *
 **********************************************************************/
void swim_set_xy(SWIM_WINDOW_T *win,
                 INT_32 x,
                 INT_32 y)
{
    win->xvpos = x + win->xpvmin;
    win->yvpos = y + win->ypvmin;

    /* Limit to window dimensions */
    if (win->xvpos < win->xpvmin)
    {
        win->xvpos = win->xpvmin;
    }
    else if (win->xvpos > win->xpvmax)
    {
        win->xvpos = win->xpvmax;
    }

    if (win->yvpos < win->ypvmin)
    {
        win->yvpos = win->ypvmin;
    }
    else if (win->yvpos > win->ypvmax)
    {
        win->yvpos = win->ypvmax;
    }
}

/***********************************************************************
 *
 * Function: swim_get_xy
 *
 * Purpose: Returns the X, Y pixel coordinates for the next text
 *          operation
 *
 * Processing:
 *     The logical X and Y positions are computed by subtracting the
 *     physical text position values by the physical minimum window
 *     limits.
 *
 * Parameters: 
 *     win  : Window identifier
 *     x    : Address of where to return virtual X value
 *     y    : Address of where to return virtual X value
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes:
 *     X, Y coords are in virtual pixels!
 *
 **********************************************************************/
void swim_get_xy(SWIM_WINDOW_T *win,
                 INT_32 *x,
                 INT_32 *y)
{
    *x = win->xvpos - win->xpvmin;
    *y = win->yvpos - win->ypvmin;
}

/***********************************************************************
 *
 * Function: swim_put_text
 *
 * Purpose: Puts a string of text in a window
 *
 * Processing:
 *     Each character will be routed to the swim_put_char function until
 *     a string terminator is reached. For newline characters, a newline
 *     will occur instead of a character output.
 *
 * Parameters: 
 *     win  : Window identifier
 *     text : Text string to output in window
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes:  None
 *
 **********************************************************************/
void swim_put_text(SWIM_WINDOW_T *win,
                   const CHAR *text)
{
    INT_32 i = 0;

    /* Continue until the entire string is output */
    while (text [i] != '\0')
    {
        if (text [i] == '\n')
        {
            swim_put_newline(win);
        }
        else if (((UNS_8) text [i] >= win->font->first_char)
            && ((UNS_8) text [i] <= win->font->last_char))
        {
            /* Put character on screen */
            swim_put_char(win, text [i]);
        }

        i++;
    }
}

/***********************************************************************
 *
 * Function: swim_put_ltext
 *
 * Purpose: Puts a string of text in a window, but will adjust the
 *          position of a word if the word length exceeds the edge of
 *          the display.
 *
 * Processing:
 *     While the string has data in it, check for the newline character.
 *     If it exists, output a newline. If the string data is inside the
 *     font character table, output the first word in the string (with
 *     support for generating a newline if the word will exceed the
 *     window edge). Continue until all words/characters are output.
 *
 * Parameters: 
 *     win  : Window identifier
 *     text : Text string to output in window
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes:  None
 *
 **********************************************************************/
void swim_put_ltext(SWIM_WINDOW_T *win,
                    const CHAR *text)
{
    INT_32 i = 0;

    /* Continue until the entire string is output */
    while (text [i] != '\0')
    {
        if (text [i] == '\n')
        {
            swim_put_newline(win);
            i++;
        }
        else if (((UNS_8) text [i] >= win->font->first_char)
            && ((UNS_8) text [i] <= win->font->last_char))
        {
            /* Check for entire words first */
            if (((UNS_8) text [i] > ' ') && ((UNS_8) text [i] <= 0x7E))
            {
                /* Put entire word on screen */
                i = i + swim_put_word(win, &text [i]);
            }
            else
            {
                swim_put_char(win, text [i]);
                i++;
            }
        }
        else
        {
            /* Put a space out */
            swim_put_char(win, ' ');
            i++;
        }
    }
}

/***********************************************************************
 *
 * Function: swim_window_scroll
 *
 * Purpose: Scrolls the window up one line
 *
 * Processing:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -