home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2002 December
/
PCWorld_2002-12_cd.bin
/
Software
/
Komercni
/
Baltik
/
katB.exe
/
katB
/
DESIGN
/
DESIGN_C.GDI
< prev
next >
Wrap
Text File
|
2002-09-24
|
17KB
|
498 lines
////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------//
//-----project DESINGER, copyright 2002 Libor Bareτ-------------------------//
//----------------------------------------------------------------------------//
////////////////////////////////////////////////////////////////////////////////
//
//
// Library for Graphic User Interface
// (Using GDISTYLE of Microsoft Windows 98/XP)
//
// copyright 2002 Libor Bareτ
char m_Tahoma8Height[255];
char m_TahomaItalic8Height[255];
char m_TahomaBold8Height[255];
char m_TahomaBoldItalic8Height[255];
char m_ArialBold10Height[255];
char m_ArialBoldItalic10Height[255];
void RectToVariable(RECT* src1, int &x,&y,&x2,&y2){
x=src1->left;y = src1->top; x2 = src1->right; y2 = src1->bottom;
}
void LineFromTo2(int X,int Y, int X2, int Y2, char Color){
GrNastavBarvuPop²edí(Color);
GrKresliLinku(X,Y,X2,Y2);
}
void FillSolidRect(RECT* rect,char Color){
GrNastavBarvuPozadí(Color);
GrKresliVypln╪n∞Obdélník(rect->left,rect->top,rect->right,rect->bottom);
}
void FillSolidRect2(int x, int y, int x2, int y2,char Color){
GrNastavBarvuPozadí(Color);
GrKresliVypln╪n∞Obdélník(x,y,x2,y2);
}
void CenterText(int x, int y,string strText,char t,char b,char hFont,char bDraw,RECT* pRect){
if(y <= 33)return; // for case that text is above diagramclientrect
SIZE sz;
GetTextExtent(strText,sz,hFont);
if(pRect!=0)SetRect(pRect,x-sz.x/2-1,y-1,x+sz.x/2+1,y+sz.y+1);
if(bDraw){
FillSolidRect(pRect,b);
TextOut(x-sz.x/2,y,strText,t,b,hFont);
}
if(pRect!=0)InflateRect(pRect,9,-1,9,-1);
}
void DrawText(string szText,RECT* lpRect,char t,char b,unsigned uFormat,char hFont){
SIZE stext;GetTextExtent(szText,stext,hFont);
RECT Rect;CopyRect(&Rect,lpRect);
NormalizeRect(&Rect);
int nWidth = Rect.right - Rect.left;
int nHeight = Rect.bottom - Rect.top;
int slen = StrVelikost(szText);
long bModify = (uFormat & 0x00000010/*DT_MODIFYSTRING*/);
while(stext.x > nWidth && slen >= 0){
slen--;
if(bModify) GetTextExtent(StrKopie(szText,0,slen)+"...",stext,hFont);
else GetTextExtent(StrKopie(szText,0,slen),stext,hFont);
}
if(uFormat & 0x00000004 /*DT_VCENTER*/)nHeight=nHeight/2-stext.y/2;
else nHeight = 0;
if(uFormat & 0x00000001/*DT_CENTER*/)nWidth=nWidth/2-stext.x/2;
else nWidth = 0;
if((slen != StrVelikost(szText))){
szText=StrKopie(szText,0,slen);
if(bModify)szText+="...";
}
TextOut(Rect.left+nWidth,Rect.top+nHeight,szText,t,b,hFont);
if(uFormat & 0x00000020/*DT_UNDERLINE*/)LineFromTo2(Rect.left+nWidth,Rect.top+nHeight+stext.y,Rect.left+nWidth+stext.x,Rect.top+nHeight+stext.y,t);
}
void TextOut(int x, int y, string szText,char color,char bg, char FontType){
int nPos=0;
char charid;
int plusb;
int nLen = StrDélka(szText);
//char *nStartChar=szText[0];
void* u;
x-=2;
switch(FontType){
case FONT_TAHOMA_BOLD_8:
u=&m_TahomaBold8Height;
if(color==5)plusb=18000;
else plusb=28000;
//¼ekej(0x8001);
break;
case FONT_TAHOMA_BOLD_ITALIC_8:
u=&m_TahomaBoldItalic8Height;plusb=9000;
break;
case FONT_TAHOMA_ITALIC_8:
u=&m_TahomaItalic8Height;plusb=7000;
break;
case FONT_ARIAL_BOLD_ITALIC_10:plusb=3000;
u=&m_ArialBoldItalic10Height;
break;
case FONT_ARIAL_BOLD_10:plusb=5000;
u=&m_ArialBold10Height;
break;
default :plusb=0;
if(color == 3)plusb=13000;
else if(color == 4 && bg==5)plusb=26000;
else if(color == 5)plusb=11000;
else if(color == 2)plusb=22000;
#ifndef _XP_THEME
else if(color == 16)plusb=24000;
#endif
else plusb=1000;
u =&m_Tahoma8Height;
break;
}
if(nLen <= 0)return;
for(nPos=0;nPos < nLen; nPos++){
charid =szText[nPos];
if(charid != 33)
GrKresliP²edm╪t((charid >= 150) ? charid+plusb+851 : 1+plusb+charid,1,x,y);
x+=((char*)u)[(int)charid];
}
}
void GetTextExtent(string szText,SIZE &returnsize, char FontType){
int nPos=0,x=0;
char charid;
int nLen = StrDélka(szText);
void* u = 0;
returnsize.x=0;
switch(FontType){
case FONT_TAHOMA_BOLD_8:
u=&m_TahomaBold8Height;returnsize.y = 13;
break;
case FONT_TAHOMA_BOLD_ITALIC_8:
u=&m_TahomaBoldItalic8Height;returnsize.y = 13;
break;
case FONT_TAHOMA_ITALIC_8:
u=&m_TahomaItalic8Height;returnsize.y = 13;
break;
case FONT_ARIAL_BOLD_ITALIC_10:
u=&m_ArialBoldItalic10Height;returnsize.y = 16;
break;
case FONT_ARIAL_BOLD_10:
u=&m_ArialBold10Height;returnsize.y = 16;
break;
default :
u =&m_Tahoma8Height;returnsize.y = 13;
}
if(nLen <= 0)return;
for(nPos=0;nPos < nLen; nPos++){
charid =szText[nPos]; // optimalization;
x+=((char*)u)[(int)charid];
}
returnsize.x = x;
}
void LineFromTo(LINE* rect, char Color){
GrNastavBarvuPop²edí(Color);
GrKresliLinku(rect->x,rect->y,rect->x2,rect->y2);
}
void Draw3dRect2(int x, int y, int x2, int y2, char TopLeftColor,char BottomRightColor){
// LineFromTo2(x,y,x2-1,y,TopLeftColor);
// LineFromTo2(x,y+1,x,y2-1,TopLeftColor);
// LineFromTo2(x2,y2,x2,y,BottomRightColor);
// LineFromTo2(x2-1,y2,x,y2,BottomRightColor);
GrNastavBarvuPop²edí(TopLeftColor);
GrKresliMnohoúhelník(3,x2-1,y,x,y,x,y2-1);
GrNastavBarvuPop²edí(BottomRightColor);
GrKresliMnohoúhelník(3,x2,y,x2,y2,x,y2);
}
void Draw3dRect(RECT* lpRect,char TopLeftColor,char BottomRightColor){
Draw3dRect2(lpRect->left,lpRect->top,lpRect->right,lpRect->bottom,TopLeftColor,BottomRightColor);
}
void InflateRectOne(RECT* lpRect){
InflateRect(lpRect,-1,-1,-1,-1);
}
void DrawEdge(RECT* lpRect,unsigned nState){
RECT rc;CopyRect(&rc,lpRect);
if(nState & 0x0004/*DES_MODAL*/){
Draw3dRect(lpRect,1,4);
InflateRectOne(&rc);
Draw3dRect(&rc,5,3);
InflateRectOne(&rc);
Draw3dRect(&rc,0,0);
InflateRectOne(&rc);
}
if(nState & 0x0002/*DES_STATIC*/){
Draw3dRect(&rc,3,5);
InflateRectOne(&rc);
}
if(nState & 0x0001/*DES_CLIENT*/){
Draw3dRect(&rc,3,5);
InflateRectOne(&rc);
Draw3dRect(&rc,4,1);
}
}
#ifdef _XP_THEME
#include "design_c.xp"
#else
#include "design_c.2k"
#endif
void DrawFrameControl2(int x, int y, int x2, int y2,unsigned nType, long nState,char* szText,unsigned hBitmap){ // for 7/*DFC_EDIT*/ is hBitmap replaced by hFont !!!!!!
RECT rect;
SetRect(&rect,x,y,x2,y2);
DrawFrameControl(&rect, nType,nState, szText,hBitmap);
}
void MakeMaximalRect(RECT* dest, RECT* src){
int x,y,x2,y2;
RectToVariable(src,x,y,x2,y2);
if(dest->left > x)dest->left = x;
if(dest->top > y)dest->top = y;
if(dest->bottom < y2)dest->bottom = y2;
if(dest->right < x2)dest->right = x2;
}
void MakeMaximalRect2(RECT* dest, int x, int y){
RECT r;SetRect(&r,x,y,x,y);
MakeMaximalRect(dest,&r);
}
void NormalizeRect(RECT* dest){
if(!(dest->bottom > dest->top)){int tp;tp=dest->top;dest->top=dest->bottom;dest->bottom=tp;}
if(!(dest->right > dest->left)){int tpx;tpx=dest->left;dest->left=dest->right;dest->right=tpx;}
}/*
char IntersectHorVerLine(LINE* ln, LINE* ln2){
// MUST BE NORMALIZED !!!
if(ln->x == ln->x2){
if((ln->y <= ln2->y && ln->y2 >= ln2->y) && (ln->x >= ln2->x && ln->x <= ln2->x2))return 1;
}
else {
if((ln->x <= ln2->x && ln->x2 >= ln2->x ) && (ln->y >= ln2->x && ln->x <= ln2->y2 ))return 1;
}
return 0;
}
void _IRS(int nPos,LINE* ln, RECT* src1){
int l,r,t,b;RectToVariable(src1,l,t,r,b);
if(nPos == 0 || nPos == 2){
ln->x=l;
ln->x2=r;
ln->y2=ln->y=((nPos==0)?t:b);
}
else {
ln->y=t;
ln->y2=b;
ln->x2=ln->x=((nPos==3)?l:r);
}
}*/
char IntersectRect(RECT* src1,RECT* src2){
// The intersection is the largest rectangle contained in both existing rectangles.
// This algorithm I devised myself. I hope that it won't make errors :-)
if(src1->left > src2->right || src1->top > src2->bottom || // isnt ...
src2->left > src1->right || src2->top > src1->bottom)return 0; // isnt ...
return 1;
/*
int s2l,s2r,s2t,s2b,s1l,s1r,s1t,s1b;
RectToVariable(src1,s1l,s1t,s1r,s1b);
RectToVariable(src2,s2l,s2t,s2r,s2b);
if(PtInRect(s2l,s2t,src1) || PtInRect(s2r,s2t,src1) ||
PtInRect(s2l,s2b,src1) || PtInRect(s2r,s2b,src1) ||
PtInRect(s1l,s1t,src2) || PtInRect(s1r,s1t,src2) ||
PtInRect(s1l,s1b,src2) || PtInRect(s1r,s1b,src2))
return 1;
*/
/*
this code is for RGN intersect, but for my program is too slow that I made some another algorithm
int nPos=0,nPos2;
LINE lna,lnb;
for(;nPos < 4;nPos++){
_IRS(nPos,&lna,src1);
for(nPos2=0;nPos2 < 4; nPos2++){
_IRS(nPos2,&lnb,src2);
if(IntersectHorVerLine(&lna,&lnb))return 1;
}
}
*/
return 0;
}
char PtOnLineArea(POINT* pt,LINE* ln){
// normalize line
int x,y,x2,y2;
RectToVariable((RECT*)ln,x,y,x2,y2);
if(pt->left >= (( x < x2 ? x : x2)) && pt->left <= (( x > x2 ? x : x2)) &&
pt->top >= (( y < y2 ? y : y2)) && pt->top <= (( y > y2 ? y : y2)))
return 1;
return 0;
}
char LinesIntersect(LINE *src, LINE *dest,POINT* intersection)
{
// optimal...
int sx,sx2,sy,sy2;
RectToVariable((RECT*)src,sx,sy,sx2,sy2);
int dx,dx2,dy,dy2;
RectToVariable((RECT*)dest,dx,dy,dx2,dy2);
if( ((sx < dx) && (sx2 <dx) &&
(sx < dx2) && (sx2 <dx2)) ||
((sy < dy) && (sy2 <dy) &&
(sy < dy2) && (sy2 <dy2)) ||
((sx > dx) && (sx2 >dx) &&
(sx > dx2) && (sx2 >dx2)) ||
((sy > dy) && (sy2 >dy) &&
(sy > dy2) && (sy2 >dy2)))
return 0;
// A = sx,sy
// B = sx2,sy2
// X = dx,sy
// Y = dx2,sy2
// B-A = (x1,y1)
// Y-X = (x2,y2)
int x1,y1,x2,y2;
x1 = sx2 - sx;
y1 = sy2 - sy;
x2 = dx2 - dx;
y2 = dy2 - dy;
double k;
// function :
// (float)x1*(Ay - Xy) + y1*(Xx-Ax)
// k = ---------------------------
// x*y2 - x2 * y
k = ((float)x1*(float)y2-(float)x2*(float)y1);
if(k == 0){return 0;}
k = ((double)(((float)x1*(sy - dy) + (float)y1*( dx - sx))))/(double)k;
SetPoint(intersection,dx + x2 * k,dy + y2 * k);
if(PtOnLineArea(intersection,dest)==1)return 1;
return 0;
}
char PtInRGN(int mousex, int mousey,POINT* lt, int nCount){
int x,x2,ty,ty2,iPocet=0,tl,tl2,tx,tx2;
int _xx,_xy,_x2x,_x2y;
for(x =0; x < nCount;x++){
x2 = x==(nCount-1)?0:(x+1);
// jedna se o trivialni hranu ??
_xx = lt[x].left;_x2x = lt[x2].left;
_xy = lt[x].top;_x2y = lt[x2].top;
if(!((_xy > mousey && _x2y > mousey) ||
(_xy < mousey && _x2y < mousey) ||
(_xx < mousex && _x2x < mousex))){
/* netrivialni */
// vypocitam prusecik hrany s mousey ...
// odecti nehornejsi strany id strany spodni (y)
tl = (_xy < _x2y ? x: x2);if(tl==x)tl2=x2;else tl2 = x;
ty=(mousey - lt[tl].top);
// spocti roztec x bodu ...
tx=abs(_xx-_x2x); // sirka odchylek ...
// spocitej rozdil vrchol
ty2 = abs(_xy-_x2y);
// lezi v jedne primce
if(ty2 ==0){// nachazeji se ve stejne rovine ?
if(_xx < mousex && _x2x < mousex)return 1;
// pozn - OPTIMALIZATION.:Jeslize je rovna cara a body x,x2 jsou mezi mousex lezi testovany bod uvnitr => neni potreba dalsi zkouseni ...
}
else{
tx2 = lt[tl].left + ((lt[tl].left > lt[tl2].left)? -((float)((float)tx*(float)ty)/ty2) : +((float)((float)tx*(float)ty)/ty2));/* novy bod na x */
// jestlize je vypocteny bod na pravo od kliknute osy x, lezi asi bod v n-uhelniku
if(mousex < tx2 )iPocet++;
}
/*
GrNastavPozici(0,0);
GrPiτD¼íslo(tx2,-1,2);
GrPiτD¼íslo(x,-1,2);
GrPiτL¼íslo(iPocet,-1);
¼ekejNaKlávesu();
*/
}
}
// jestlize je, iPocet lichy lezi uvnitr ..
if(iPocet%2)return 1;
return 0;
}
void CoverLine(RECT* pLine,POINT pt[6], int by){
//
// MAKE THIS ...
// + PT[0] PT[1]
// \ /
// \ /
// +line[x,y]
// / \
// / \
// +PT[5] \
// \
// \ +PT[2]
// \ /
// \ /
// +line[x2,y2]
// / \
// / \
// +PT[4] + PT[3]
//
int x=pLine->left,x2=pLine->right;
int y=pLine->top,y2=pLine->bottom;
float vectorABx=x2 - x;
float vectorABy=y2 - y;
double rate = (double)sqrt((vectorABx)*(vectorABx)+(vectorABy)*(vectorABy))/(double)by; //
if(rate==0)return;
vectorABx/=rate;vectorABy/=rate;
SetPoint(&pt[0],x-vectorABx,y-vectorABy);
SetPoint(&pt[1],x+vectorABy,y-vectorABx);
SetPoint(&pt[2],x2+vectorABy,y2-vectorABx);
SetPoint(&pt[3],x2+vectorABx,y2+vectorABy);
SetPoint(&pt[4],x2-vectorABy,y2+vectorABx);
SetPoint(&pt[5],x-vectorABy,y+vectorABx);
}
char RGNLineIntersect(LINE* line,POINT * hrg, int nCount,POINT* pt){
int i = 0;
LINE dest;
for(i;i < nCount;i++){
dest.x = hrg[i].left;dest.y = hrg[i].top;
if(nCount > i+1){dest.x2 = hrg[i+1].left;dest.y2 = hrg[i+1].top;}
else {dest.x2 = hrg[0].left;dest.y2 = hrg[0].top;}
if(LinesIntersect(line,&dest,pt)==1){
return 1;}
}
return 0;
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////