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

📄 gpcdraw.c

📁 使用键盘上的上、下、左、右四个按键
💻 C
📖 第 1 页 / 共 2 页
字号:
///////////////////////////////////////////////////////////////////////////////////
//
//        Copyright (C) 1999 SEIKO EPSON Corp.
//        All Rights Reserved
//
//        File name :gpcdraw.c
//        Function  :
//            This is a primitive graphic program
//        Revision history
//            Ver 0.10 1999/06/29  H.Matsuoka           Start
//            Ver 0.11 1999/10/01  SungYoung Shin       Update        
//            Ver 0.12 1999/11/05  SungYoung Shin       Delete gpcDrawArc's Lines
//            Ver 0.13 1999/11/10  SungYoung Shin       Add check that over screen size
//            Ver 0.14 1999/11/26  SungYoung Shin       Add check that over screen size
//                                                      (gpcGetImage, gpcPutImage)
//            Ver 0.15 1999/12/14  SungYoung Shin       Update Function point process
//            Ver 0.20 2000/06/07  SungYoung Shin       Update length to display
//            Ver 0.30 2000/06/08  SungYoung Shin       Update 2byte font check for out of the screen
//            Ver 0.40 2000/06/28  SungYoung Shin       Add gpcDrawArc, gpcDrawCircle, gpcFillCircle for radius <= 0
//            Ver 1.90 2001/06/01  CYu                  customize to plus version
//
///////////////////////////////////////////////////////////////////////////////////
#include <string.h>
#include <stdlib.h>
#include <gpc.h>

static void ellipse( S16 , S16, S16, S16 );
static void FillEllipse( S16 , S16, S16, S16 );
void DrawBLine( S16, S16, S16, S16 );
extern S16 gpcLines( S16 x1, S16 y1, S16 x2, S16 y2 );
extern S16 gpcInverts( S16 left, S16 top, S16 right, S16 bottom );
extern U16 gpcText( S16 x, S16 y, U8 *text, S16 length );

extern gpcGCValues gpcGC;

//-------------------------------------------------------------------------
//    gpcDrawPoint()
//
//  Write point in the x, y with current color.
//
//  Parameters:
//      x    - Position X to draw.
//      y    - Position Y to draw.
//    Returns:
//      GPC_ERR_OK
//-------------------------------------------------------------------------
U16 gpcDrawPoint( S16 x, S16 y )
{
    // 1999.11.10 Add by shin :: check over screen size
    if(x < 0 || x > gpcGC.GCScreenWidth) return GPC_ERR_OK;
    if(y < 0 || y > gpcGC.GCScreenHeight) return GPC_ERR_OK;

    seSetPixel( x, y, gpcGC.GCColorIndex );

    return GPC_ERR_OK;
}

//-------------------------------------------------------------------------
//    gpcDrawLine()
//
//  Draw line in the x1, y1, x2, y2 with current color.
//
//  Parameters:
//      x1    - Position X of Start Line.
//      y1    - Position Y of Start Line.
//      x2    - Position X of End Line.
//      y2    - Position Y of End Line.
//    Returns:
//      GPC_ERR_OK
//-------------------------------------------------------------------------
U16 gpcDrawLine( S16 x1, S16 y1, S16 x2, S16 y2 )
{
    // 1999.11.10 Add by shin :: check over screen size
    // left the screen
    if( x1<0 && x2<0 )
        return GPC_ERR_OK;
    // right the screen
    if( x1>gpcGC.GCScreenWidth && x2>gpcGC.GCScreenWidth )
        return GPC_ERR_OK;
    // over the screen
    if( y1<0 && y2<0 )
        return GPC_ERR_OK;
    // under the screen
    if( y1>gpcGC.GCScreenHeight && y2>gpcGC.GCScreenHeight )
        return GPC_ERR_OK;

    if( x1==x2 )
    {
        if( y1<0 )
            y1 = 0;
        if( y2>gpcGC.GCScreenHeight)
            y2 = gpcGC.GCScreenHeight;
    }

    if( y1==y2)
    {
        if( x1<0 )
            x1 = 0;
        if( x2>gpcGC.GCScreenWidth )
            x2 = gpcGC.GCScreenWidth;
    }

    return gpcLines(x1, y1, x2, y2);
}

//-------------------------------------------------------------------------
//    gpcInvertRect()
//
//  Invert rectangle in the left, top, right, bottom.
//
//  Parameters:
//      left    - Position left of Rectangle.
//      top     - Position top of Rectangle.
//      right   - Position right of Rectangle.
//      bottom  - Position bottom of Rectangle.
//    Returns:
//      GPC_ERR_OK
//-------------------------------------------------------------------------
/*U16 gpcInvertRect(S16 left, S16 top, S16 right, S16 bottom)
{
    // 1999.11.12 Add by shin :: check over screen size
    // left the screen
    if(left < 0 && right < 0)
        return GPC_ERR_OK;
    // right the screen
    if(left > gpcGC.GCScreenWidth && right > gpcGC.GCScreenWidth)
        return GPC_ERR_OK;
    // over the screen
    if(top < 0 && bottom < 0)
        return GPC_ERR_OK;
    // under the screen
    if(top > gpcGC.GCScreenHeight && bottom > gpcGC.GCScreenHeight)
        return GPC_ERR_OK;

    if(left < 0)
        left = 0;
    if(right > gpcGC.GCScreenWidth)
        right = gpcGC.GCScreenWidth;

    if(top < 0)
        top = 0;
    if(bottom > gpcGC.GCScreenHeight)
        bottom = gpcGC.GCScreenHeight;

    return gpcInverts(left, top, right, bottom);
}
*/
//-------------------------------------------------------------------------
//    gpcDrawText()
//
//  Draw text in the x, y with text's length.
//
//  Parameters:
//      x       - Position X of start text.
//      y       - Position Y of start text.
//      text   - Point to text.
//      length - length of text.
//    Returns:
//      GPC_ERR_OK
//-------------------------------------------------------------------------
U16 gpcDrawText(S16 x, S16 y, U8 *text, S16 length)
{
    S16 left_size;
    U16 iFontByteFlag;   // Font Byte Flag (1:1Byte, 2:2Byte)

    // 1999.11.12 Add by shin :: check over screen size
    // left the screen
    if(x < 0 && (x+(8*length)) < 0) return GPC_ERR_OK;
    // right the screen
    if(x > gpcGC.GCScreenWidth ) return GPC_ERR_OK;
    // over the screen
    if(y < 0 && (y+gpcGC.GCFont1Height) < 0) return GPC_ERR_OK;
    // under the screen
    if(y > gpcGC.GCScreenHeight ) return GPC_ERR_OK;

    if(x < 0) { 
        // Check Font Byte ( 1:1Byte, 2:2Byte )
        iFontByteFlag = gpcCheckFontByte(text);
        if(iFontByteFlag == 1) {
            left_size = (-x) >> 3;
        }
        else {
            left_size = ((-x) >> 4)*2;
        }
        x = 0;
        text = text + left_size;
        length = length - left_size;
    }

    // 2000.06.07 Update by shin :: count length to display
    // 2000.06.08 Update by shin :: 2byte font check for out of the screen
/*    if((x+(8*length)) > gpcGC.GCScreenWidth)  {
        length = (gpcGC.GCScreenWidth - x) / 8 ;
        // Check Font Byte ( 1:1Byte, 2:2Byte )
        iFontByteFlag = gpcCheckFontByte(text+(length-1));
        if(iFontByteFlag == 2) {
            length = length - 1;
        }
        
    }
*/
    
    // 1999.11.30 Add by shin :: check over screen size
    if(y < 0)  y = 0;
    if((y + gpcGC.GCFont1Height) > gpcGC.GCScreenHeight)  y = gpcGC.GCScreenHeight - gpcGC.GCFont1Height;

    return gpcText(x, y, text, length);
}

//-------------------------------------------------------------------------
//    gpcGetImage()
//
//  Read image data to buffer in the x, y, w, h.
//
//  Parameters:
//      x   - Position X of start image.
//      y   - Position Y of start image.
//      w   - Width of image.
//      h   - Height of image.
//      buf - Point to image buf.
//    Returns:
//      GPC_ERR_OK
//-------------------------------------------------------------------------
U16 gpcGetImage(S16 x, S16 y, S16 w, S16 h, unsigned short *buf)
{
    // 1999.11.26 Add by shin :: check over screen size
    // left the screen
    if((x + w) < 0 || x < 0)
        return GPC_ERR_OK;
    // right the screen
    if(x > gpcGC.GCScreenWidth)
        return GPC_ERR_OK;
    // over the screen
    if((y + h) < 0 || y < 0)
        return GPC_ERR_OK;
    // under the screen
    if(y > gpcGC.GCScreenHeight)
        return GPC_ERR_OK;

    seGetImage(x, y, w, h, buf);
    return GPC_ERR_OK;
}

//-------------------------------------------------------------------------
//    gpcPutImage()
//
//  Write image data to buffer in the x, y, w, h.
//
//  Parameters:
//      x   - Position X of start image.
//      y   - Position Y of start image.
//      w   - Width of image.
//      h   - Height of image.
//      buf - Point to image buf.
//      op  - Option .
//    Returns:
//      GPC_ERR_OK
//-------------------------------------------------------------------------
U16 gpcPutImage(S16 x, S16 y, S16 w, S16 h, U16 *buf, U8 op)
{
    // 1999.11.26 Add by shin :: check over screen size
    // left the screen
    if((x + w) < 0 || x < 0)
        return GPC_ERR_OK;
    // right the screen
    if(x > gpcGC.GCScreenWidth)
        return GPC_ERR_OK;
    // over the screen
    if((y + h) < 0 || y < 0)
        return GPC_ERR_OK;
    // under the screen
    if(y > gpcGC.GCScreenHeight)
        return GPC_ERR_OK;

    seSetImage(x, y, w, h, buf, op);
    return GPC_ERR_OK;
}

//-------------------------------------------------------------------------
//    gpcDrawRect()
//
//  Draw Rectangle in the left, top, right, bottom.
//
//  Parameters:
//      left    - Position left of Rectangle.
//      top     - Position top of Rectangle.
//      right   - Position right of Rectangle.
//      bottom  - Position bottom of Rectangle.
//    Returns:
//      GPC_ERR_OK
//-------------------------------------------------------------------------
U16 gpcDrawRect(S16 left, S16 top, S16 right, S16 bottom)
{
    gpcDrawLine(left, top, right, top);
    gpcDrawLine(left, bottom, right, bottom);
    gpcDrawLine(left, top, left, bottom);
    gpcDrawLine(right, top, right, bottom);

    return GPC_ERR_OK;
}

//-------------------------------------------------------------------------
//    gpcFillRect()
//
//  Draw Fill Rectangle in the left, top, right, bottom.
//
//  Parameters:
//      left    - Position left of Rectangle.
//      top     - Position top of Rectangle.
//      right   - Position right of Rectangle.
//      bottom  - Position bottom of Rectangle.
//    Returns:
//      GPC_ERR_OK
//-------------------------------------------------------------------------
U16 gpcFillRect(S16 left, S16 top, S16 right, S16 bottom)
{
    S16 i;
    bottom++;
    gpcGC.GCLineStyle = GPC_SOLID_LINE;
    for(i=top; i<bottom; i++)
        gpcDrawLine(left, i, right, i);
        
    return GPC_ERR_OK;
}

//-------------------------------------------------------------------------
//    gpcDrawEllipse()
//
//  Draw Ellipse's Line in the left, top, right, bottom.
//
//  Parameters:
//      left    - Position left of Ellipse.
//      top     - Position top of Ellipse.
//      right   - Position right of Ellipse.
//      bottom  - Position bottom of Ellipse.
//    Returns:
//      GPC_ERR_OK
//-------------------------------------------------------------------------
U16 gpcDrawEllipse(S16 left, S16 top, S16 right, S16 bottom)
{
    S16 x0=(right+left)>>1;
    S16 y0=(bottom+top)>>1;

    S16 a0 = abs(right - x0);
    S16 b0 = abs(bottom - y0);

    ellipse (x0,y0,a0,b0);

    return GPC_ERR_OK;
}

//-------------------------------------------------------------------------
//    ellipse()
//
//  Draw ellipse's Line in the x0, y0, a0, b0.
//
//  Parameters:
//      x0    - Position x0 of Ellipse.
//      y0    - Position y0 of Ellipse.
//      a0    - Position width of Ellipse.
//      b0    - Position height of Ellipse.
//    Returns:
//      GPC_ERR_OK
//-------------------------------------------------------------------------
static void ellipse (S16 x0, S16 y0, S16 a0, S16 b0 )
{

    S16 x = 0;
    S16 y = b0;

    S16 a = a0;
    S16 b = b0;

    S16 asqr = a * a;
    S32 two_asqr = asqr<<1;
    S16 bsqr = b * b;
    S16 two_bsqr = bsqr<<1;

    S32 d, dx, dy;

    d = bsqr - asqr * b + (asqr >> 2);

    dx = 0;
    dy = (S32)two_asqr * b;

    gpcDrawPoint(x0, (S16)(y0+b0));
    gpcDrawPoint(x0, (S16)(y0-b0));
    gpcDrawPoint((S16)(x0+a0), y0);
    gpcDrawPoint((S16)(x0-a0), y0);

    do {
        gpcDrawPoint((S16)(x0+x),(S16)(y0+y));
        gpcDrawPoint((S16)(x0-x),(S16)(y0+y));
        gpcDrawPoint((S16)(x0+x),(S16)(y0-y));
        gpcDrawPoint((S16)(x0-x),(S16)(y0-y));
        if (d > 0) {
            y--;
            dy -= two_asqr;
            d  -= dy;
        }
        x++;
        dx += two_bsqr;
        d  += (bsqr+dx);
    } while (dx<dy);

    d += (3*(asqr-bsqr)/2 - (dx+dy))/2;

⌨️ 快捷键说明

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