hedgewars/uStore.pas
changeset 2811 4cad87e11bf6
parent 2801 24739a3bf5e3
child 2841 2c9013664ea3
equal deleted inserted replaced
2810:3bc9c723731d 2811:4cad87e11bf6
    38     Step: LongInt;
    38     Step: LongInt;
    39     squaresize : LongInt;
    39     squaresize : LongInt;
    40     numsquares : LongInt;
    40     numsquares : LongInt;
    41     ProgrTex: PTexture;
    41     ProgrTex: PTexture;
    42     MissionIcons: PSDL_Surface;
    42     MissionIcons: PSDL_Surface;
       
    43     ropeIconTex: PTexture;
    43 
    44 
    44 procedure init_uStore;
    45 procedure init_uStore;
    45 procedure free_uStore;
    46 procedure free_uStore;
    46 
    47 
    47 procedure StoreLoad;
    48 procedure StoreLoad;
    50 procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt);
    51 procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt);
    51 procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
    52 procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
    52 procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
    53 procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
    53 procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: PTexture);
    54 procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: PTexture);
    54 procedure DrawTexture(X, Y: LongInt; Texture: PTexture);
    55 procedure DrawTexture(X, Y: LongInt; Texture: PTexture);
    55 procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt);
    56 procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
    56 procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, Frames: LongInt; Angle: real);
    57 procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real);
    57 procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
    58 procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
    58 procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
    59 procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
    59 procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
    60 procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
    60 procedure DrawCentered(X, Top: LongInt; Source: PTexture);
    61 procedure DrawCentered(X, Top: LongInt; Source: PTexture);
    61 procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
    62 procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
   178 	procedure WriteNames(Font: THWFont);
   179 	procedure WriteNames(Font: THWFont);
   179 	var t: LongInt;
   180 	var t: LongInt;
   180 		i: LongInt;
   181 		i: LongInt;
   181 		r, rr: TSDL_Rect;
   182 		r, rr: TSDL_Rect;
   182 		drY: LongInt;
   183 		drY: LongInt;
   183 		texsurf, flagsurf: PSDL_Surface;
   184 		texsurf, flagsurf, iconsurf: PSDL_Surface;
   184 	begin
   185 	begin
   185 	r.x:= 0;
   186 	r.x:= 0;
   186 	r.y:= 0;
   187 	r.y:= 0;
   187 	drY:= - 4;
   188 	drY:= - 4;
   188 	for t:= 0 to Pred(TeamsCount) do
   189 	for t:= 0 to Pred(TeamsCount) do
   254 							SDL_FreeSurface(texsurf)
   255 							SDL_FreeSurface(texsurf)
   255 							end
   256 							end
   256 						end
   257 						end
   257 					end;
   258 					end;
   258 		end;
   259 		end;
   259 		MissionIcons:= LoadImage(Pathz[ptGraphics] + '/missions', ifCritical);
   260 	MissionIcons:= LoadImage(Pathz[ptGraphics] + '/missions', ifCritical);
       
   261 	iconsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 28, 28, 32, RMask, GMask, BMask, AMask);
       
   262 	if iconsurf <> nil then
       
   263 		begin
       
   264 		r.x:= 0;
       
   265 		r.y:= 0;
       
   266 		r.w:= 28;
       
   267 		r.h:= 28;
       
   268 		DrawRoundRect(@r, cWhiteColor, cNearBlackColor, iconsurf, true);
       
   269 		ropeIconTex:= Surface2Tex(iconsurf, false);
       
   270 		SDL_FreeSurface(iconsurf)
       
   271 		end;
   260 	end;
   272 	end;
   261 
   273 
   262 	procedure MakeCrossHairs;
   274 	procedure MakeCrossHairs;
   263 	var t: LongInt;
   275 	var t: LongInt;
   264 		tmpsurf, texsurf: PSDL_Surface;
   276 		tmpsurf, texsurf: PSDL_Surface;
   497 glDisableClientState(GL_VERTEX_ARRAY);
   509 glDisableClientState(GL_VERTEX_ARRAY);
   498 
   510 
   499 glPopMatrix
   511 glPopMatrix
   500 end;
   512 end;
   501 
   513 
   502 procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt);
   514 procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
   503 var ft, fb: GLfloat;
   515 begin
   504 	hw: LongInt;
   516 	DrawRotatedTextureF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0)
   505     VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
   517 end;
   506 begin
   518 
   507 glPushMatrix;
   519 procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real);
   508 glTranslatef(X, Y, 0);
   520 var ft, fb, fl, fr: GLfloat;
   509 glScalef(Scale, Scale, 1.0);
   521     hw, nx, ny: LongInt;
   510 
       
   511 if Dir < 0 then
       
   512 	hw:= - 16
       
   513 else
       
   514 	hw:= 16;
       
   515 
       
   516 ft:= Frame / Frames * Texture^.ry;
       
   517 fb:= (Frame + 1) / Frames * Texture^.ry;
       
   518 
       
   519 glBindTexture(GL_TEXTURE_2D, Texture^.id);
       
   520 
       
   521 VertexBuffer[0].X:= -hw;
       
   522 VertexBuffer[0].Y:= -16;
       
   523 VertexBuffer[1].X:= hw;
       
   524 VertexBuffer[1].Y:= -16;
       
   525 VertexBuffer[2].X:= hw;
       
   526 VertexBuffer[2].Y:= 16;
       
   527 VertexBuffer[3].X:= -hw;
       
   528 VertexBuffer[3].Y:= 16;
       
   529 
       
   530 TextureBuffer[0].X:= 0;
       
   531 TextureBuffer[0].Y:= ft;
       
   532 TextureBuffer[1].X:= Texture^.rx;
       
   533 TextureBuffer[1].Y:= ft;
       
   534 TextureBuffer[2].X:= Texture^.rx;
       
   535 TextureBuffer[2].Y:= fb;
       
   536 TextureBuffer[3].X:= 0;
       
   537 TextureBuffer[3].Y:= fb;
       
   538 
       
   539 glEnableClientState(GL_VERTEX_ARRAY);
       
   540 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
       
   541 
       
   542 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
       
   543 glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
       
   544 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
       
   545 
       
   546 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
       
   547 glDisableClientState(GL_VERTEX_ARRAY);
       
   548 
       
   549 
       
   550 glPopMatrix
       
   551 end;
       
   552 
       
   553 procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, Frames: LongInt; Angle: real);
       
   554 var ft, fb: GLfloat;
       
   555 	hw: LongInt;
       
   556     VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
   522     VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
   557 begin
   523 begin
   558 glPushMatrix;
   524 glPushMatrix;
   559 glTranslatef(X, Y, 0);
   525 glTranslatef(X, Y, 0);
   560 
   526 
   562    glRotatef(Angle, 0, 0, -1)
   528    glRotatef(Angle, 0, 0, -1)
   563 else
   529 else
   564    glRotatef(Angle, 0, 0,  1);
   530    glRotatef(Angle, 0, 0,  1);
   565 
   531 
   566 glTranslatef(Dir*OffsetX, OffsetY, 0);
   532 glTranslatef(Dir*OffsetX, OffsetY, 0);
       
   533 glScalef(Scale, Scale, 1);
       
   534 
   567 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   535 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   568 
   536 
   569 if Dir < 0 then
   537 if Dir < 0 then
   570 	hw:= - 16
   538 	hw:= w div -2
   571 else
   539 else
   572 	hw:= 16;
   540 	hw:= w div 2;
   573 
   541 
   574 ft:= Frame / Frames * Texture^.ry;
   542 nx:= round(Texture^.w * Texture^.rx / w);
   575 fb:= (Frame + 1) / Frames * Texture^.ry;
   543 ny:= round(Texture^.h * Texture^.ry / h);
       
   544 
       
   545 ft:= ((Frame mod ny) / ny);
       
   546 fb:= (((Frame mod ny) + 1) / ny);
       
   547 fl:= ((Frame div ny) / nx) * Texture^.rx;
       
   548 fr:= (((Frame div ny) + 1) / nx);
   576 
   549 
   577 glBindTexture(GL_TEXTURE_2D, Texture^.id);
   550 glBindTexture(GL_TEXTURE_2D, Texture^.id);
   578 
   551 
   579 VertexBuffer[0].X:= -hw;
   552 VertexBuffer[0].X:= -hw;
   580 VertexBuffer[0].Y:= -16;
   553 VertexBuffer[0].Y:= w / -2;
   581 VertexBuffer[1].X:= hw;
   554 VertexBuffer[1].X:= hw;
   582 VertexBuffer[1].Y:= -16;
   555 VertexBuffer[1].Y:= w / -2;
   583 VertexBuffer[2].X:= hw;
   556 VertexBuffer[2].X:= hw;
   584 VertexBuffer[2].Y:= 16;
   557 VertexBuffer[2].Y:= w / 2;
   585 VertexBuffer[3].X:= -hw;
   558 VertexBuffer[3].X:= -hw;
   586 VertexBuffer[3].Y:= 16;
   559 VertexBuffer[3].Y:= w / 2;
   587 
   560 
   588 TextureBuffer[0].X:= 0;
   561 TextureBuffer[0].X:= fl;
   589 TextureBuffer[0].Y:= ft;
   562 TextureBuffer[0].Y:= ft;
   590 TextureBuffer[1].X:= Texture^.rx;
   563 TextureBuffer[1].X:= fr;
   591 TextureBuffer[1].Y:= ft;
   564 TextureBuffer[1].Y:= ft;
   592 TextureBuffer[2].X:= Texture^.rx;
   565 TextureBuffer[2].X:= fr;
   593 TextureBuffer[2].Y:= fb;
   566 TextureBuffer[2].Y:= fb;
   594 TextureBuffer[3].X:= 0;
   567 TextureBuffer[3].X:= fl;
   595 TextureBuffer[3].Y:= fb;
   568 TextureBuffer[3].Y:= fb;
   596 
   569 
   597 glEnableClientState(GL_VERTEX_ARRAY);
   570 glEnableClientState(GL_VERTEX_ARRAY);
   598 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
   571 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
   599 
   572 
   822     begin
   795     begin
   823     FreeTexture(SpritesData[ii].Texture);
   796     FreeTexture(SpritesData[ii].Texture);
   824     if SpritesData[ii].Surface <> nil then SDL_FreeSurface(SpritesData[ii].Surface)
   797     if SpritesData[ii].Surface <> nil then SDL_FreeSurface(SpritesData[ii].Surface)
   825     end;
   798     end;
   826 SDL_FreeSurface(MissionIcons);
   799 SDL_FreeSurface(MissionIcons);
   827 
   800 FreeTexture(ropeIconTex);
   828 FreeTexture(HHTexture)
   801 FreeTexture(HHTexture)
   829 end;
   802 end;
   830 
   803 
   831 
   804 
   832 function CheckCJKFont(s: string; font: THWFont): THWFont;
   805 function CheckCJKFont(s: string; font: THWFont): THWFont;