📄 tools.h
字号:
Displaysinglexy(x1,y1,s,i) ;
}
// {display for menu name}
void Displaychinesexy1(int x,int y,word s)
{ Disp_chinese_at(s,x,y);
}
void Displayasciixy1(int x,int y,byte s)
{int x1,y1;
Textxy_gxy(x,y, x1,y1);
unsigned char s1=s;
unsigned char s2[2];
s2[0]=s1;
s2[1]='\0';
outtextxy(x1,y1+7,s2);
}
void Displaysinglexy1(int& x,int& y,string s,int& i)
{
if (!isascii(s[i]) )
{
Displaychinesexy1(x,y,s[i]*256+s[i+1] );
i=i+2;
x=x+2;
}
else
{
Displayasciixy1(x,y,s[i] );
i=i+1;
x=x+1;
}
}
void Displaytextxy1(int x,int y,string s)
{int x1,y1,i;
i=0;
x1=x;
y1=y;
while (i<=strlen(s) )
Displaysinglexy1(x1,y1,s,i);
}
// {outtext}
void Spaces(string s,int n)
{int k;
for (k=0;k<n;k++)
s[k]=' ';
s[n]='\0';
}
void Substr(string s1,string s2,int si,int n)
{ int i,j;
for(i=si-1,j=0;i<si+n-1 && s1[i]!='\0';i++,j++ )
s2[j]=s1[i];
s2[j]='\0';
}
void Ltrim(string s1,string s2)
{ int i,j;
i=0;
j=strlen(s1);
while ((i<j)&& (s1[i]==' ') )
i=i+1;
int k,m;
for(k=i,m=0;s1[k]!='\0';k++,m++)
s2[m]=s1[k];
s2[m]='\0';
}
void Rtrim(string s1,string s2)
{ int i;
i=strlen(s1);
i--;
while ( (i>=0) && (s1[i]==' ') )
i=i-1;
int k,m;
for(k=0,m=0; k<=i; k++,m++)
s2[m]=s1[k];
s2[m]='\0';
}
void Upper(string ss)
{ int i;
int j=strlen(ss);
for( i=0; i<j;i++)
{ if(ss[i]<='z'&& ss[i]>='a')
ss[i]=ss[i]-32;
}
}
void Lower(string ss)
{int i;
int j=strlen(ss);
for (i=0; i<j;i++)
{ if (ss[i]>='A'&& ss[i]<='Z')
ss[i]=ss[i]+32;
}
}
void String_start(textsettingstype * ts,int x,int y,string s,
int& x1,int& y1)
{int l;
l=strlen(s);
if (ts->direction==HORIZ_DIR)
{
switch(ts->horiz)
{ case LEFT_TEXT: x1=x; break;
case CENTER_TEXT: x1=x-l/2; break; //x-4*l+1;
case RIGHT_TEXT: x1=x-l;break; //x-8*l+1
}
switch(ts->vert)
{ case BOTTOM_TEXT: y1=y-2; break;
case CENTER_TEXT: y1=y-1; break;
case TOP_TEXT: y1=y;break;
}
}
else {
switch(ts->horiz)
{ case LEFT_TEXT: x1=x; break;
case CENTER_TEXT: x1=x-1; break;
case RIGHT_TEXT: x1=x-2;break;
}
switch(ts->vert)
{ case BOTTOM_TEXT: y1=y; break;
case CENTER_TEXT: y1=y+l/2; break;
case TOP_TEXT: y1=y+l; break;
}
}
}
void Disp_chmodel_vertgxy(chwordmode cwm,int x1,int y1)
{int i,j;
word w;
for (i=0;i<=15;i++)
{ w=cwm[i];
w=swap(w);
for (j=0;j<=15;j++)
{ if ( (w & 0x8000)!=0 )
putpixel(x1+i-1-9,y1-j,getcolor() );
w=w<<1;
}
}
}
void Out_chinese_xyd(word s,int x,int y,word dir)
{ chwordmode cwm;
int x1,y1;
Get_chmodel_fromxhzk(s,cwm);
Textxy_gxy(x,y, x1,y1);
if (dir==HORIZ_DIR)
Disp_chmodel_fromgxy(cwm,x1,y1);
else
Disp_chmodel_vertgxy(cwm,x1,y1);
}
void Outsinglefrom_xyd( string s,int& x,int& y,int dir, int& i)
{int x1,y1;
if (!isascii(s[i]))
{ Out_chinese_xyd( s[i]*256+s[i+1],x,y,dir);
i=i+2;
if (dir==HORIZ_DIR)
x=x+2;
else
y=y-2;
}
else {
if (dir==HORIZ_DIR)
{
settextstyle(0,0,1);
Displayasciixy(x,y,s[i]);
}
else
{settextstyle(0,1,1);
Displayasciixy(x,y,s[i]);
}
i=i+1;
if (dir==HORIZ_DIR)
x=x+1;
else
y=y-1;
}
}
void Outtextfrom_xyd( string s,int x,int y,int dir)
{int x1,y1,i;
i=0;
x1=x; y1=y;
while (i<=strlen(s))
{
Outsinglefrom_xyd(s,x1,y1,dir,i);
}
}
void Outtextxy(int x,int y,string s)
{
int x1,y1;
textsettingstype* ts;
gettextsettings(ts);
if (ts->direction==HORIZ_DIR)
settextjustify(LEFT_TEXT,TOP_TEXT);
else
settextjustify(LEFT_TEXT,TOP_TEXT);
settextstyle(0,ts->direction,1);
String_start(ts, x,y,s,x1,y1);
Outtextfrom_xyd(s,x1,y1,ts->direction);
settextjustify(ts->horiz,ts->vert);
settextstyle(ts->font,ts->direction,ts->charsize);
}
void Outtext(string s)
{ Outtextxy(getx()/8+1,gety()/20+1,s); }
//cursor
void Cursor_init(cursor& cur,int initx,int inity,int forecolor,int backcolor)
{int size,tempfore,tempback;
cur.col=initx;
cur.row=inity;
cur.word_high=(getmaxy()+1)/24;
cur.word_width=(getmaxx()+1)/80;
charhigh=cur.word_high;
cur.cy=cur.word_high;
cur.sd=true;
tempfore=getcolor();
tempback=getbkcolor();
setcolor(forecolor);
setbkcolor(backcolor);
size=imagesize(1,1,cur.word_width,2);
line(1,1,cur.word_width,1);
line(1,2,cur.word_width,2);
cur.pmem=farmalloc(size);
getimage(1,1,cur.word_width,2,cur.pmem);
putimage(1,1,cur.pmem,1);
setcolor(tempfore);
setbkcolor(tempback);
}
void Cursor_show(cursor& cur)
{int x1,y1;
cur.visible=true;
x1=(cur.col-1)*8;
y1=(cur.row-1)*20+cur.cy;
putimage(x1,y1,cur.pmem,1);
if (!cur.sd)
putimage(x1+cur.word_width,y1,cur.pmem,1);
}
void Cursor_hide(cursor& cur)
{int tempcolor;
if(cur.visible)
{
Cursor_show(cur);
cur.visible=false;
}
}
void Cursor_setsd(cursor& cur,boolean ssdd)
{ if (cur.visible)
Cursor_hide(cur);
cur.sd=ssdd;
if (cur.visible)
Cursor_show(cur);
}
void Cursor_done(cursor& cur)
{ Cursor_hide(cur);
farfree(cur.pmem);
}
boolean Cursor_isvisible(cursor& cur)
{
boolean cursor_isvisible=cur.visible;
return cursor_isvisible;
}
void Cursor_moveto(cursor& cur,int newx,int newy)
{ if (Cursor_isvisible(cur))
Cursor_hide(cur);
cur.col=newx;
cur.row=newy;
Cursor_show(cur);
}
int Cursor_cursorx(cursor& cur)
{ int cursor_cursorx=cur.col;
return cursor_cursorx;
}
int Cursor_cursory(cursor& cur)
{ int cursor_cursory=cur.row;
return cursor_cursory;
}
void Cursor_relmove(cursor& cur,int dx,int dy)
{ Cursor_moveto(cur,Cursor_cursorx(cur)+dx, Cursor_cursory(cur)+dy);
}
//{ string object }
void Stringobj_init( stringobj& strobj,string news)
{ strcpy(strobj.s,news);
}
void Stringobj_movetoword(stringobj& strobj,int& i,cursor& cur1)
{
if(i<=0)
Error("error");
else
{ Cursor_hide(cur1);
cur1.col=strobj.scrx1;
cur1.row=strobj.scry1;
int j=strlen(strobj.s);
if(i>j+1)
{cur1.col+=j;
i--;
}
else
cur1.col+=i-1;
if(strobj.s[i-1]=='\0')
if( (i-2)>=0)
Cursor_setsd(cur1,(boolean)(Isascii(strobj.s[i-2] ) ) );
else
Cursor_setsd(cur1,true);
else
Cursor_setsd(cur1,(boolean)(Isascii(strobj.s[i-1]) ) );
Cursor_show(cur1);
}
}
void Stringobj_putstring(stringobj& strobj,string news)
{ //strobj.s=new unsigned char[60];
strcpy(strobj.s,news);
}
void Stringobj_moveto(stringobj& strobj,int newx,int newy)
{
strobj.scrx1=newx;
strobj.scry1=newy;
}
int Stringobj_firstx(stringobj& strobj)
{ int stringobj_firstx=strobj.scrx1;
return stringobj_firstx;
}
int Stringobj_firsty(stringobj& strobj)
{
int stringobj_firsty=strobj.scry1;
return stringobj_firsty;
}
string Stringobj_curstring(stringobj& strobj)
{ string stringobj_curstring=strobj.s;
return stringobj_curstring;
}
void Stringobj_displaystringxy(stringobj& strobj,int x,int y)
{ strobj.scrx1=x;
strobj.scry1=y;
Displaytextxy(x,y,strobj.s);
}
void Stringobj_done(stringobj& strobj)
{ }
void Delete(string s,int i,int k)
{
if( (i<0)||i>=strlen(s) )
;
else if(k==1)
{
int len=strlen(s),j;
for( j=i;j<len;j++)
s[j]=s[j+1];
if(s[len-1]!='\0')
s[len-1]='\0';
}
else if(k==2)
{
int len=strlen(s),j;
for( j=i;j<len;j++)
s[j]=s[j+2];
if(s[len-2]!='\0')
s[len-2]='\0';
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -