hedgewars/uUtils.pas
branchwebgl
changeset 8330 aaefa587e277
parent 8026 4a4f21070479
parent 8204 9a6030d96273
child 8444 75db7bb8dce8
equal deleted inserted replaced
8116:d24257910f8d 8330:aaefa587e277
    74 {$IFNDEF PAS2C}
    74 {$IFNDEF PAS2C}
    75 procedure Write(var f: textfile; s: shortstring);
    75 procedure Write(var f: textfile; s: shortstring);
    76 procedure WriteLn(var f: textfile; s: shortstring);
    76 procedure WriteLn(var f: textfile; s: shortstring);
    77 {$ENDIF}
    77 {$ENDIF}
    78 
    78 
       
    79 function  isPhone: Boolean; inline;
       
    80 function  getScreenDPI: Double; inline; //cdecl; external;
       
    81 
       
    82 {$IFDEF IPHONEOS}
       
    83 procedure startLoadingIndicator; cdecl; external;
       
    84 procedure stopLoadingIndicator; cdecl; external;
       
    85 procedure saveFinishedSynching; cdecl; external;
       
    86 function  isApplePhone: Boolean; cdecl; external;
       
    87 procedure AudioServicesPlaySystemSound(num: LongInt); cdecl; external;
       
    88 {$ENDIF}
       
    89 
    79 procedure initModule(isNotPreview: boolean);
    90 procedure initModule(isNotPreview: boolean);
    80 procedure freeModule;
    91 procedure freeModule;
    81 
    92 
    82 
    93 
    83 implementation
    94 implementation
   366        ((#$3200  <= u) and (u <= #$4DBF))  or // Enclosed CJK Letters and Months / CJK Compatibility / CJK Unified Ideographs Extension A
   377        ((#$3200  <= u) and (u <= #$4DBF))  or // Enclosed CJK Letters and Months / CJK Compatibility / CJK Unified Ideographs Extension A
   367        ((#$4E00  <= u) and (u <= #$9FFF))  or // CJK Unified Ideographs
   378        ((#$4E00  <= u) and (u <= #$9FFF))  or // CJK Unified Ideographs
   368        ((#$AC00  <= u) and (u <= #$D7AF))  or // Hangul Syllables
   379        ((#$AC00  <= u) and (u <= #$D7AF))  or // Hangul Syllables
   369        ((#$F900  <= u) and (u <= #$FAFF))  or // CJK Compatibility Ideographs
   380        ((#$F900  <= u) and (u <= #$FAFF))  or // CJK Compatibility Ideographs
   370        ((#$FE30  <= u) and (u <= #$FE4F)))    // CJK Compatibility Forms
   381        ((#$FE30  <= u) and (u <= #$FE4F)))    // CJK Compatibility Forms
   371        then 
   382        then
   372         begin
   383         begin
   373             CheckCJKFont:=  THWFont( ord(font) + ((ord(High(THWFont))+1) div 2) );
   384             CheckCJKFont:=  THWFont( ord(font) + ((ord(High(THWFont))+1) div 2) );
   374             exit;
   385             exit;
   375         end;
   386         end;
   376     inc(i)
   387     inc(i)
   416 begin
   427 begin
   417 system.writeln(f, s)
   428 system.writeln(f, s)
   418 end;
   429 end;
   419 {$ENDIF}
   430 {$ENDIF}
   420 
   431 
       
   432 // this function is just to determine whether we are running on a limited screen device
       
   433 function isPhone: Boolean; inline;
       
   434 begin
       
   435     isPhone:= false;
       
   436 {$IFDEF IPHONEOS}
       
   437     isPhone:= isApplePhone();
       
   438 {$ENDIF}
       
   439 {$IFDEF ANDROID}
       
   440     //nasty nasty hack. TODO: implement callback to java to have a unified way of determining if it is a tablet
       
   441     if (cScreenWidth < 1000) and (cScreenHeight < 500) then
       
   442         isPhone:= true;
       
   443 {$ENDIF}
       
   444 end;
       
   445 
       
   446 //This dummy function should be reimplemented (externally).
       
   447 function getScreenDPI: Double; inline;
       
   448 begin
       
   449 {$IFDEF ANDROID}
       
   450 //    getScreenDPI:= Android_JNI_getDensity();
       
   451     getScreenDPI:= 1;
       
   452 {$ELSE}
       
   453     getScreenDPI:= 1;
       
   454 {$ENDIF}
       
   455 end;
       
   456 
   421 procedure initModule(isNotPreview: boolean);
   457 procedure initModule(isNotPreview: boolean);
   422 {$IFDEF DEBUGFILE}
   458 {$IFDEF DEBUGFILE}
   423 var logfileBase: shortstring;
   459 var logfileBase: shortstring;
   424 {$IFNDEF MOBILE}var i: LongInt;{$ENDIF}
   460     i: LongInt;
   425 {$ENDIF}
   461 {$ENDIF}
   426 begin
   462 begin
   427 {$IFDEF DEBUGFILE}
   463 {$IFDEF DEBUGFILE}
   428     if isNotPreview then
   464     if isNotPreview then
   429     begin
   465     begin
   438     InitCriticalSection(logMutex);
   474     InitCriticalSection(logMutex);
   439 {$ENDIF}
   475 {$ENDIF}
   440 {$I-}
   476 {$I-}
   441 {$IFDEF MOBILE}
   477 {$IFDEF MOBILE}
   442     {$IFDEF IPHONEOS} Assign(f, UserPathPrefix + '/hw-' + logfileBase + '.log'); {$ENDIF}
   478     {$IFDEF IPHONEOS} Assign(f, UserPathPrefix + '/hw-' + logfileBase + '.log'); {$ENDIF}
   443     {$IFDEF ANDROID} Assign(f,pathPrefix + '/' + logfileBase + '.log'); {$ENDIF}
   479     {$IFDEF ANDROID} Assign(f, pathPrefix + '/' + logfileBase + '.log'); {$ENDIF}
   444     Rewrite(f);
   480     i:= i; // avoid hint
   445 {$ELSE}
   481 {$ELSE}
       
   482     f:= stdout; // if everything fails, write to stderr
   446     if (UserPathPrefix <> '') then
   483     if (UserPathPrefix <> '') then
   447         begin
   484         begin
   448             i:= 0;
   485         if not FileExists(UserPathPrefix + '/Logs/') then
   449             while(i < 7) do
   486             CreateDir(UserPathPrefix + '/Logs/');
       
   487         i:= 0;
       
   488         while(i < 7) do
   450             begin
   489             begin
   451                 assign(f, UserPathPrefix + '/Logs/' + logfileBase + inttostr(i) + '.log');
   490             assign(f, UserPathPrefix + '/Logs/' + logfileBase + inttostr(i) + '.log');
   452                 rewrite(f);
   491             if IOResult = 0 then
   453                 if IOResult = 0 then
   492                 break;
   454                     break;
   493             inc(i)
   455                 inc(i)
       
   456             end;
   494             end;
   457             if i = 7 then
   495         end;
   458                 f:= stderr; // if everything fails, write to stderr
   496 {$ENDIF}
   459         end
   497     Rewrite(f);
   460     else
       
   461         f:= stderr;
       
   462 {$ENDIF}
       
   463 {$I+}
   498 {$I+}
   464 {$ENDIF}
   499 {$ENDIF}
   465 
   500 
   466 end;
   501 end;
   467 
   502