Changeset 303 for branches/highdpi/Packages/CevoComponents/ScreenTools.pas
- Timestamp:
- Mar 9, 2021, 9:19:49 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/Packages/CevoComponents/ScreenTools.pas
r266 r303 13 13 TTexture = record 14 14 Image: TDpiBitmap; 15 clBevelLight, clBevelShade, clTextLight, clTextShade, clLitText, clMark, 16 clPage, clCover: TColor; 17 end; 15 clBevelLight: TColor; 16 clBevelShade: TColor; 17 clTextLight: TColor; 18 clTextShade: TColor; 19 clLitText: TColor; 20 clMark: TColor; 21 clPage: TColor; 22 clCover: TColor; 23 end; 24 TLoadGraphicFileOption = (gfNoError, gfNoGamma); 25 TLoadGraphicFileOptions = set of TLoadGraphicFileOption; 26 18 27 19 28 {$IFDEF WINDOWS} … … 28 37 procedure EditFrame(ca: TDpiCanvas; p: TRect; const T: TTexture); 29 38 function HexStringToColor(S: string): integer; 30 function LoadGraphicFile( bmp: TDpiBitmap; Path: string; Options: integer = 0): boolean;39 function LoadGraphicFile(Bmp: TDpiBitmap; FileName: string; Options: TLoadGraphicFileOptions = []): boolean; 31 40 function LoadGraphicSet(const Name: string): integer; 32 41 procedure Dump(dst: TDpiBitmap; HGr, xDst, yDst, Width, Height, xGr, yGr: integer); … … 91 100 function SetMainTextureByAge(Age: integer): boolean; 92 101 procedure LoadPhrases; 93 procedure Texturize(Dest, Texture: TDpiBitmap; TransparentColor: Integer);102 procedure Texturize(Dest, Texture: TDpiBitmap; TransparentColor: Cardinal); 94 103 procedure DarkenImage(Bitmap: TDpiBitmap; Change: Integer); 95 104 … … 158 167 cliWater = 4; 159 168 160 // LoadGraphicFile options161 gfNoError = $01;162 gfNoGamma = $02;163 164 169 type 165 170 TGrExtDescr = record { don't use dynamic strings here! } … … 256 261 MenuItem := MenuItems[MenuItems.Count - 1]; 257 262 MenuItems.Delete(MenuItems.Count - 1); 258 MenuItem.Free;263 FreeAndNil(MenuItem); 259 264 end; 260 265 end; 261 266 262 267 function TurnToYear(Turn: Integer): Integer; 263 var264 I: Integer;265 268 begin 266 269 Result := -4000; 267 for I := 1 to Turn do 268 if Result < -1000 then Inc(Result, 50) // 0..60 269 else if Result < 0 then Inc(Result, 25) // 60..100 270 else if Result < 1500 then Inc(Result, 20) // 100..175 271 else if Result < 1750 then Inc(Result, 10) // 175..200 272 else if Result < 1850 then Inc(Result, 2) // 200..250 273 else Inc(Result); 270 if Turn <= 0 then Exit; 271 272 // Year -4000..-1000, Turn 0..60 273 Inc(Result, Min(60, Turn) * 50); 274 Dec(Turn, Min(60, Turn)); 275 if Turn = 0 then Exit; 276 277 // Year -1000..0, Turn 60..100 278 Inc(Result, Min(40, Turn) * 25); 279 Dec(Turn, Min(40, Turn)); 280 if Turn = 0 then Exit; 281 282 // Year 0..1500, Turn 100..175 283 Inc(Result, Min(75, Turn) * 20); 284 Dec(Turn, Min(75, Turn)); 285 if Turn = 0 then Exit; 286 287 // Year 1500..1750, Turn 175..200 288 Inc(Result, Min(25, Turn) * 10); 289 Dec(Turn, Min(25, Turn)); 290 if Turn = 0 then Exit; 291 292 // Year 1750..1850, Turn 200..250 293 Inc(Result, Min(50, Turn) * 2); 294 Dec(Turn, Min(50, Turn)); 295 if Turn = 0 then Exit; 296 297 // Year 1850.., Turn 250.. 298 Inc(Result, Turn); 274 299 end; 275 300 … … 395 420 end; 396 421 397 function LoadGraphicFile(bmp: TDpiBitmap; Path: string; Options: Integer): Boolean; 398 var 399 jtex: TDpiJpegImage; 422 function LoadGraphicFile(Bmp: TDpiBitmap; FileName: string; Options: 423 TLoadGraphicFileOptions = []): Boolean; 424 var 425 Jpeg: TDpiJpegImage; 400 426 Png: TDpiPortableNetworkGraphic; 401 427 begin 402 Result := True; 403 if ExtractFileExt(Path) = '' then 404 Path := Path + '.png'; 405 if ExtractFileExt(Path) = '.jpg' then begin 406 jtex := TDpiJpegImage.Create; 407 try 428 Result := False; 429 if ExtractFileExt(FileName) = '' then 430 FileName := FileName + '.png'; 431 432 if FileExists(FileName) then begin 433 if ExtractFileExt(FileName) = '.jpg' then begin 434 Jpeg := TDpiJpegImage.Create; 408 435 try 409 jtex.LoadFromFile(Path); 436 Jpeg.LoadFromFile(FileName); 437 if not (gfNoGamma in Options) then 438 Bmp.PixelFormat := pf24bit; 439 Bmp.SetSize(Jpeg.Width, Jpeg.Height); 440 Bmp.Canvas.Draw(0, 0, Jpeg); 441 Result := True; 410 442 except 411 443 Result := False; 412 444 end; 413 if Result then 414 begin 415 if Options and gfNoGamma = 0 then 416 bmp.PixelFormat := pf24bit; 417 Bmp.SetSize(jtex.Width, jtex.Height); 418 Bmp.Canvas.Draw(0, 0, jtex); 419 end; 420 finally 421 FreeAndNil(jtex); 422 end; 423 end 424 else 425 if ExtractFileExt(Path) = '.png' then begin 426 Png := TDpiPortableNetworkGraphic.Create; 427 try 428 Png.PixelFormat := Bmp.PixelFormat; 445 FreeAndNil(Jpeg); 446 end else 447 if ExtractFileExt(FileName) = '.png' then begin 448 Png := TDpiPortableNetworkGraphic.Create; 429 449 try 430 Png.LoadFromFile(Path); 431 except 432 Result := False; 433 end; 434 if Result then begin 435 if Options and gfNoGamma = 0 then 436 bmp.PixelFormat := pf24bit; 437 bmp.SetSize(Png.Width, Png.Height); 450 Png.PixelFormat := Bmp.PixelFormat; 451 Png.LoadFromFile(FileName); 452 if not (gfNoGamma in Options) then 453 Bmp.PixelFormat := pf24bit; 454 Bmp.SetSize(Png.Width, Png.Height); 438 455 if (Png.RawImage.Description.Format = ricfGray) then 439 456 begin … … 441 458 Bmp.PixelFormat := pf24bit; 442 459 CopyGray8BitTo24bitBitmap(Bmp, Png); 443 end else 444 Bmp.Canvas.draw(0, 0, Png); 460 end 461 else 462 Bmp.Canvas.Draw(0, 0, Png); 463 Result := True; 464 except 465 Result := False; 445 466 end; 446 finally447 467 FreeAndNil(Png); 448 end; 449 end else 450 if ExtractFileExt(Path) = '.bmp' then begin 451 try 452 bmp.LoadFromFile(Path); 453 except 454 Result := False; 455 end; 456 if Result then begin 457 if Options and gfNoGamma = 0 then 458 bmp.PixelFormat := pf24bit; 459 end; 460 end else 461 raise Exception.Create('Unsupported image file type ' + ExtractFileExt(Path)); 468 end else 469 if ExtractFileExt(FileName) = '.bmp' then begin 470 try 471 Bmp.LoadFromFile(FileName); 472 if not (gfNoGamma in Options) then 473 Bmp.PixelFormat := pf24bit; 474 Result := True; 475 except 476 Result := False; 477 end; 478 end else 479 raise Exception.Create('Unsupported image file type ' + ExtractFileExt(FileName)); 480 end; 462 481 463 482 if not Result then begin 464 if Options and gfNoError = 0then465 raise Exception.Create(Format(Phrases.Lookup('FILENOTFOUND'), [ Path]));466 end; 467 468 if ( Options and gfNoGamma = 0) and (Gamma <> 100) then483 if not (gfNoError in Options) then 484 raise Exception.Create(Format(Phrases.Lookup('FILENOTFOUND'), [FileName])); 485 end; 486 487 if (not (gfNoGamma in Options)) and (Gamma <> 100) then 469 488 ApplyGammaToBitmap(Bmp); 470 489 end; … … 1247 1266 i, r, g, b: Integer; 1248 1267 begin 1249 begin 1250 for i := 0 to 15 do 1251 begin // gradient 1252 r := Color and $FF + Brightness[i]; 1253 if r < 0 then 1254 r := 0 1255 else if r >= 256 then 1256 r := 255; 1257 g := Color shr 8 and $FF + Brightness[i]; 1258 if g < 0 then 1259 g := 0 1260 else if g >= 256 then 1261 g := 255; 1262 b := Color shr 16 and $FF + Brightness[i]; 1263 if b < 0 then 1264 b := 0 1265 else if b >= 256 then 1266 b := 255; 1267 ca.Pen.Color := r + g shl 8 + b shl 16; 1268 ca.MoveTo(x + dx * i, y + dy * i); 1269 ca.LineTo(x + dx * i + Width, y + dy * i + Height); 1270 end; 1271 ca.Pen.Color := $000000; 1272 ca.MoveTo(x + 1, y + 16 * dy + Height); 1273 ca.LineTo(x + 16 * dx + Width, y + 16 * dy + Height); 1274 ca.LineTo(x + 16 * dx + Width, y); 1275 end; 1268 for i := 0 to Length(Brightness) - 1 do begin // gradient 1269 r := Color and $FF + Brightness[i]; 1270 if r < 0 then 1271 r := 0 1272 else if r >= 256 then 1273 r := 255; 1274 g := Color shr 8 and $FF + Brightness[i]; 1275 if g < 0 then 1276 g := 0 1277 else if g >= 256 then 1278 g := 255; 1279 b := Color shr 16 and $FF + Brightness[i]; 1280 if b < 0 then 1281 b := 0 1282 else if b >= 256 then 1283 b := 255; 1284 ca.Pen.Color := r + g shl 8 + b shl 16; 1285 ca.MoveTo(x + dx * i, y + dy * i); 1286 ca.LineTo(x + dx * i + Width, y + dy * i + Height); 1287 end; 1288 ca.Pen.Color := $000000; 1289 ca.MoveTo(x + 1, y + 16 * dy + Height); 1290 ca.LineTo(x + 16 * dx + Width, y + 16 * dy + Height); 1291 ca.LineTo(x + 16 * dx + Width, y); 1276 1292 end; 1277 1293 … … 1549 1565 end; 1550 1566 1551 procedure Texturize(Dest, Texture: TDpiBitmap; TransparentColor: Integer);1567 procedure Texturize(Dest, Texture: TDpiBitmap; TransparentColor: Cardinal); 1552 1568 var 1553 1569 SrcPixel, DstPixel: TPixelPointer; … … 1645 1661 UniFont[section].Size := 1646 1662 Round(size * DpiScreen.PixelsPerInch / UniFont[section].PixelsPerInch * 0.8); 1663 //UniFont[section].Size := Round(Size * 72 / UniFont[section].PixelsPerInch); 1647 1664 end; 1648 1665 end; … … 1679 1696 LoadFonts; 1680 1697 LoadGraphicFile(Templates, GetGraphicsDir + DirectorySeparator + 1681 'Templates.png', gfNoGamma);1698 'Templates.png', [gfNoGamma]); 1682 1699 LoadGraphicFile(Colors, GetGraphicsDir + DirectorySeparator + 'Colors.png'); 1683 1700 LoadGraphicFile(Paper, GetGraphicsDir + DirectorySeparator + 'Paper.jpg');
Note:
See TracChangeset
for help on using the changeset viewer.