Subversion Repositories Kolibri OS

Rev

Rev 5266 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. void draw_window() {
  2.         _ksys_window_redraw(1);
  3.         _ksys_draw_window(0, 0, ScreenX, ScreenY, 0, 0, 0, 0, 0);
  4.         _ksys_window_redraw(2);
  5. }
  6.  
  7. void DrawLine(int x0, int y0, int x1, int y1, int color) {
  8.         int Temp = 0;
  9.         int x=0;
  10.         int y=0;
  11.  
  12.         //cases when line is out of screen
  13.         if (y0 < 0 && y1 < 0) return;
  14.         if (y0 >Height - 1 && y1>Height - 1) return;
  15.         if (x0 < 0 && x1 < 0) return;
  16.         if (x0>Width - 1 && x1>Width - 1) return;
  17.  
  18.         if ((x1 - x0) == 0) {
  19.                 if (y1 == min(y0, y1)) {
  20.                         Temp = y1;
  21.                         y1 = y0;
  22.                         y0 = Temp;
  23.                 }
  24.                 //correcting borders
  25.                 if (y0 < 0) y0 = 0;
  26.                 if (y1>Height - 1) y1 = Height - 1;
  27.                 for (y = y0; y <= y1; y++) {
  28.                         BufferDraw[x0][y] = color;
  29.                         if (x0+1<=Width-1) BufferDraw[x0+1][y] = color;
  30.                 }
  31.         }
  32.         else if ((y1 - y0) == 0) {
  33.                 if (x1 == min(x0, x1)) {
  34.                         Temp = x1;
  35.                         x1 = x0;
  36.                         x0 = Temp;
  37.                 }
  38.                 if (x0 < 0) x0 = 0;
  39.                 if (x1>Width - 1) x1 = Width - 1;
  40.                 for (x = x0; x < x1; x++) {
  41.                         BufferDraw[x][y0] = color;
  42.                         if (y0+1<=Height-1) BufferDraw[x][y0+1] = color;
  43.                 }
  44.         }
  45.         else {
  46.                 int PartX=0;
  47.                 int PartY=0;
  48.  
  49.                 int LeftX=min(x0,x1);
  50.                 if (LeftX<0) LeftX=0;
  51.                 if (LeftX>Width-1) LeftX=Width-1;
  52.  
  53.                 int RightX=max(x0,x1);
  54.                 if (RightX<0) RightX=0;
  55.                 if (RightX>Width-1) RightX=Width-1;
  56.  
  57.                 int LeftY=min(y0,y1);
  58.                 if (LeftY<0) LeftY=0;
  59.                 if (LeftY>Height-1) LeftY=Height-1;
  60.  
  61.                 int RightY=max(y0,y1);
  62.                 if (RightY<0) RightY=0;
  63.                 if (RightY>Height-1) RightY=Height-1;
  64.  
  65.                 if (RightX-LeftX>=RightY-LeftY) {
  66.                         for (x=LeftX; x<=RightX; x++) {
  67.                                 y=(y1-y0)*(x-x0)/(x1-x0)+y0;
  68.                                 if (y<0) continue;
  69.                                 BufferDraw[x][y]=color;
  70.                                 if (y+1<=Height-1) BufferDraw[x][y+1]=color;
  71.                         }
  72.                 } else {
  73.                         for (y=LeftY; y<=RightY; y++) {
  74.                                 x=(x1-x0)*(y-y0)/(y1-y0)+x0;
  75.                                 if (x<0) continue;
  76.                                 BufferDraw[x][y]=color;
  77.                                 if (x+1<=Width-1) BufferDraw[x+1][y]=color;
  78.                         }
  79.                 }
  80.  
  81.         }
  82. }
  83.  
  84. void DrawText(int x, int y, char Text[] , int color) {
  85.         int i=0;
  86.         for (i=0; Text[i]!='\0'; i++) {
  87.                 int j=0;
  88.                 unsigned char isMatch=0;
  89.                 for (j=0; Alphabet[j]!='\0'; j++) {
  90.                         if (Text[i]==Alphabet[j]) {
  91.                                 isMatch=1;
  92.                                 break;
  93.                         }
  94.                 }
  95.                 if (isMatch==0) {
  96.                         x+=17;
  97.                         continue;
  98.                 }
  99.                 int bitLen=15;
  100.                 int bitX=0;
  101.                 int bitY=0;
  102.                 for (bitX=0; bitX<bitLen; bitX++) {
  103.                         for (bitY=0; bitY<bitLen; bitY++) {
  104.                                 if (*(AlphaGraphic[j]+bitY*bitLen+bitX)==1) {
  105.                                         if (x+bitX>=0 && x+bitX<=(Width-1) && y+bitY>=0 && y+bitY<=(Height-1)) BufferDraw[x+bitX][y+bitY]=color;
  106.                                 }
  107.                         }
  108.                 }
  109.                 x+=bitLen+2;
  110.         }
  111. }
  112.  
  113. void DrawPit (int x, int y, int color) {
  114.         DrawLine (0+x,43+y,15+x,10+y,color);
  115.         DrawLine (15+x,10+y,30+x,43+y,color);
  116.         DrawLine (0+x,43+y,30+x,43+y,color);
  117. }
  118.  
  119. void DrawBlock (int x, int y, int color) {
  120.         DrawLine (0+x,0+y,40+x,0+y,color);
  121.         DrawLine (40+x,0+y,40+x,40+y,color);
  122.         DrawLine (40+x,40+y,0+x,40+y,color);
  123.         DrawLine (0+x,40+y,0+x,0+y,color);
  124. }
  125.  
  126. void DrawHero (int x, int y, int Verts, int InitAngle, int color) {
  127.         int R=25;
  128.         int PointX1=x+FloatToInt(R*sin(InitAngle));
  129.         int PointY1=y-FloatToInt(R*cos(InitAngle));
  130.         int PointX2=0;
  131.         int PointY2=0;
  132.         int i=0;
  133.         for (i=0; i<Verts; i++) {
  134.                 InitAngle=(InitAngle+360/Verts)%360;
  135.                 PointX2=x+FloatToInt(R*sin(InitAngle));
  136.                 PointY2=y-FloatToInt(R*cos(InitAngle));
  137.                 DrawLine(PointX1,PointY1,PointX2,PointY2,color);
  138.                 PointX1=PointX2;
  139.                 PointY1=PointY2;
  140.                 CollideVerts[i][0]=PointX1;
  141.                 CollideVerts[i][1]=PointY1;
  142.  
  143.         }
  144. }
  145.  
  146. void DrawBatut (int x, int y, int color) {
  147.         DrawLine (x,y+20,x+43,y+20,color);
  148.         DrawLine (x+43,y+20,x+43,y+43,color);
  149.         DrawLine (x+43,y+43,x,y+43,color);
  150.         DrawLine (x,y+43,x,y+20,color);
  151.         DrawLine (x+10+2,y+35,x+30+2,y+35,color);
  152.         DrawLine (x+10+2,y+35,x+20+2,y+27,color);
  153.         DrawLine (x+20+2,y+27,x+30+2,y+35,color);
  154.  
  155. }
  156. void DrawFlag (int x,int y, int color) {
  157.         DrawLine (x,y,x,y+43,color);
  158.         DrawLine (x,y+43,x+10,y+43,color);
  159.         DrawLine (x,y,x+30,y,color);
  160.         DrawLine (x+30,y,x+30,y+20,color);
  161.         DrawLine (x,y+20,x+30,y+20,color);
  162.         DrawText (x+10,y+4,"c",color);
  163. }
  164.  
  165. void DrawScreen (int x,int y,int xsize, int ysize, void* image) {
  166.         asm volatile("int $0x40"::"a"(7),"b"(image),"c"((xsize<<16)+ysize),"d"((x<<16)+y):"memory");
  167. }
  168.  
  169. void DrawTitle (int x, int y, int color) {
  170.         int i=0;
  171.         //n
  172.         for (i=0; i<=10; i++) {
  173.                 DrawLine (x,y+i,x+70,y+i,color);
  174.                 DrawLine (x+i,y,x+i,y+80, color);
  175.                 DrawLine (x+i+70,y+10,x+i+70,y+80,color);
  176.         }
  177.         //-
  178.         for (i=0; i<=10; i++) {
  179.                 DrawLine (x+100,y+30+i,x+130,y+30+i,color);
  180.         }
  181.         //S
  182.         for (i=0; i<=10; i++) {
  183.                 DrawLine (x+160,y+i,x+220, y+i, color);
  184.                 DrawLine (x+150+i,y+10,x+150+i,y+30,color);
  185.                 DrawLine (x+150,y+30+i,x+210,y+30+i,color);
  186.                 DrawLine (x+210+i,y+40,x+210+i,y+70,color);
  187.                 DrawLine (x+150,y+70+i,x+210,y+70+i,color);
  188.  
  189.         }
  190.         //i
  191.         for (i=0; i<=10; i++) {
  192.                 DrawLine (x+240,y+i,x+255,y+i,color);
  193.                 DrawLine (x+242+i,y+20,x+242+i,y+80,color);
  194.         }
  195.         //D
  196.         for (i=0; i<=10; i++) {
  197.                 DrawLine (x+270,y+i,x+320,y+i,color);
  198.                 DrawLine (x+270+i,y,x+270+i,y+80,color);
  199.                 DrawLine (x+270,y+i+70,x+320,y+70+i,color);
  200.                 DrawLine (x+320+i,y+10,x+320+i,y+70,color);
  201.         }
  202.         //E
  203.         for (i=0; i<=10; i++) {
  204.                 DrawLine (x+350,y+i,x+410,y+i, color);
  205.                 DrawLine (x+350,y+35+i,x+410,y+35+i,color);
  206.                 DrawLine (x+350,y+70+i,x+410,y+70+i,color);
  207.         }
  208.         //R
  209.          for (i=0; i<=10; i++) {
  210.                 DrawLine (x+430,y+i,x+480,y+i,color);
  211.                 DrawLine (x+430+i,y,x+430+i,y+80,color);
  212.                 DrawLine (x+480+i,y+10,x+480+i,y+40,color);
  213.                 DrawLine (x+430,y+40+i,x+480,y+40+i,color);
  214.                 DrawLine (x+480+i,y+52,x+480+i,y+80,color);
  215.         }
  216. }
  217.  
  218. void DrawPew (int x,int y,int frame,int color) {
  219.         frame-=15;
  220.         DrawLine (x,y-25-frame,x,y-30-frame,color);
  221.         DrawLine (x,y+25+frame,x,y+30+frame,color);
  222.         DrawLine (x+25+frame,y,x+30+frame,y,color);
  223.         DrawLine (x-25-frame,y,x-30-frame,y,color);
  224.         DrawLine (x+15+frame,y+15+frame,x+20+frame,y+20+frame,color);
  225.         DrawLine (x-15-frame,y-15-frame,x-20-frame,y-20-frame,color);
  226.         DrawLine (x-15-frame,y+15+frame,x-20-frame,y+20+frame,color);
  227.         DrawLine (x+15+frame,y-15-frame,x+20+frame,y-20-frame,color);
  228. }
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.