ek_aip输入框窗体的创建

#include  < ek_api.h >
#include 
< time.h >

#define  PIC_FILE1    "/etc/pic/input.pic"
#define  PIC_FILE2    "/etc/pic/input2.pic"
#define  BASE_X 1
#define  BASE_Y 24
#define  SELECT_OK ek_sdc_select(81,24,95,32)
#define  SELECT_DEL ek_sdc_select(97,24,111,32)
#define  SELECT_PAGE ek_sdc_select(113,24,126,32)
int  _x, _y;                         // 坐标
int  _page;                         // 页码 0 || 1

EWin 
* win_main;

cstr 
*  charmap[ 4 =  {             // 第一页的字符集
     " 0123456789\n\010\033 " ,
    
" abcdefghijklmnop " ,
    
" qrstuvwxyz!@#$%& " ,
    
" *()-+{}|:\ " <>?= [] " ,
};
cstr 
*  charmap2[ 4 ] = {             // 第二页的字符集
     " 0123456789\n\010\033 " ,
    
" ABCDEFGHIJKLMNOP " ,
    
" QRSTUVWXYZ;,./\\_ " ,
    
"  \007\007\007\007\007\007\007\007\007\007\007\007\007\007\007\007 "
};
char  char_buffer[ 42 ];            // 字符集缓冲区
char  char_buf_1[ 22 ];            // 第一行的字符
char   * _p  =   & char_buffer[ 0 ];        // 指向当前的字符

static   int  on_key(EWin  * win, EKey key_val)
{
    
bool  refresh = false ;
    
switch (key_val.code)
    {
    
case  key_ok:
        refresh 
=   true ;
        
char  c;
        c 
=  ( 0   ==  _page) ? charmap[_y][_x]:charmap2[_y][_x];
        
switch  (c)
        {
        
case   ' \010 ' :
            
if (strlen(char_buffer)  >   0 )
                
*-- _p  =   ' \0 ' ;
            
break ;
        
case   ' \n ' :
            
break ;
        
case   ' \033 ' :
            _page 
=   ! _page;
            
break ;
        
case   ' \007 ' :
            
break ;
        
default :
            
if (strlen(char_buffer) < 42 )
                
* _p ++   =  c;
            
break ;
        }
        
break ;
    
case  key_right:
        refresh 
= true ;
        
if ( 13   ==   ++ _x  &&   0   == _y)
        {
            _x 
=   0 ;
            _y
++ ;
        }
        
else   if ( 16   ==  _x)
        {
            _x 
=   0 ;
            
if ( 3   ==  _y)
            {
                _y 
=   0 ;
                
break ;
            }
            _y
++ ;
        }
        
break ;
    
case  key_left:
        refresh 
=   true ;
        
if ( -- _x  <   0   &&   1   ==  _y)
        {
            _x 
=   12 ;
            _y
-- ;
        }
        
else   if ( - 1   ==  _x)
        {
            _x 
=   15 ;
            
if ( 0   ==  _y)
            {
                _y 
=   3 ;
                
break ;
            }
            _y
-- ;

        }
        
break ;
    
case  key_up:
        refresh 
=   true ;
        
if ( 0   ==  _y)
        {
            
switch (_x)
            {
            
case   11 :
                _x 
=   12 ;
                
break ;
            
case   12 :
                _x 
=   14 ;
                
break ;
            }
            _y 
=   3 ;
        }
        
else   if ( 1   ==  _y)
        {
            
switch (_x)
            {
            
case   10 :
                _x 
=   10 ;
                
break ;
            
case   11 :
                _x 
=   10 ;
                
break ;
            
case   12 :
                _x 
=   11 ;
                
break ;
            
case   13 :
                _x 
=   11 ;
                
break ;
            
case   14 :
                _x 
=   12 ;
                
break ;
            
case   15 :
                _x 
=   12 ;
            }
            _y
-- ;
        }
        
else  _y -- ;
        
break ;
    
case  key_down:
        refresh 
=   true ;
        
if ( 0   ==  _y)
        {
            
switch (_x)
            {
            
case   11 :
                _x  
=   12 ;
                
break ;
            
case   12 :
                _x  
=   14 ;
                
break ;
            }
        }
        
else   if ( 3   ==  _y)
        {
            
switch (_x)
            {
            
case   10 :
                _x 
=   10 ;
                
break ;
            
case   11 :
                _x 
=   10 ;
                
break ;
            
case   12 :
                _x 
=   11 ;
                
break ;
            
case   13 :
                _x 
=   11 ;
                
break ;
            
case   14 :
                _x 
=   12 ;
                
break ;
            
case   15 :
                _x 
=   12 ;
            }
            _y 
=   0 ;
            
break ;
        }
        _y
++ ;
        
break ;
    
case  key_cancel:
        refresh 
= true ;
        
if (strlen(char_buffer)  >   0 )
            
*-- _p  =   ' \0 ' ;
        
else   if ( 0   ==  strlen(char_buffer)) 
            ek_close_window(win);
    }
    
if  (refresh)
    {
        win_main
-> refresh(win);
    }
    
return   0 ;
}
int  refresh(EWin  * win)
{
    
int  len;
    
// 以下把图片内容写入缓冲
    FILE    * fp;
    
int  i  = 0 ;
    
static  uchar pic_page1[ 1024 ];
    
static  uchar pic_page2[ 1024 ];
    fp 
=  fopen(PIC_FILE2, " r " );
    
while ( ! feof(fp))   
    {
        pic_page2[i]
= fgetc(fp);
        i
++ ;
    }
    fclose(fp);
    fp 
=  fopen(PIC_FILE1, " r " );
    i 
=   0 ;
    
while ( ! feof(fp))
    {
        pic_page1[i]
= fgetc(fp);
        i
++ ;
    }
    fclose(fp);
    ek_sdc_clear();
    
// 根据页码绘制图片
     if  ( 0   ==  _page) 
        ek_sdc_draw_pic(pic_page1);
    
else  
        ek_sdc_draw_pic(pic_page2);
    
// 绘制当前位置
     if (_x > 9   &&  _y == 0 )
    {
        
switch (_x)
        {
        
case   10 :
            SELECT_OK;
            
break ;
        
case   11 :
            SELECT_DEL;
            
break ;
        
case   12 :
            SELECT_PAGE;
            
break ;
        }
    }
    
else
        ek_sdc_select(BASE_X 
+  _x * 8 , BASE_Y + _y * 10 , BASE_X  +  (_x + 1 ) * 8 - 2 , BASE_Y + (_y + 1 ) * 10 - 2 );

    ek_sdc_setcur(
2 , 2 , true );
    len
= strlen(char_buffer);
    
if (len  <   22 )
        ek_sdc_draw_ascii_raw(char_buffer);
    
else
    {
        memcpy(char_buf_1,char_buffer,
21 );
        char_buf_1[
21 ] = ' \0 ' ;
        ek_sdc_draw_ascii_raw(char_buf_1);
        _p
-= (len - 21 );
        ek_sdc_setcur(
2 , 11 , true );
        ek_sdc_draw_ascii_raw(_p);
        _p
+= (len - 21 );
    }
    ek_sdc_flush();

}
int  main( int  argc,  char   ** argv)
{
    win_main 
=  ek_create_picture_window(PIC_FILE1,  0 , NULL, NULL);
    win_main 
-> on_key   =  on_key;
    win_main 
-> refresh  =  refresh;
    ek_show_window(win_main,SW_SHOW);
    ek_mio_loop();
    
return   0 ;    
}

 

你可能感兴趣的:(IP)