void UReporterGraph::DrawLegend(UCanvas* Canvas) { FVector2D CurrentTextPos = GraphScreenSize.Max; CurrentTextPos.X = GraphScreenSize.Min.X; UFont* Font = GetDefaultFont(); int32 DummyY, CurrentX; StringSize(Font, CurrentX, DummyY, TEXT("99.99")); const float InsideLegendWidth = -CurrentX; for(int32 i = 0; i < CurrentData.Num(); i++) { FVector2D ScreenPos = ToScreenSpace(CurrentTextPos, Canvas); if (LegendPosition == ELegendPosition::Outside) { int32 DummyY, CurrentX; StringSize(Font, CurrentX, DummyY, *CurrentData[i].LineName); LegendWidth = CurrentX + 10; } else { LegendWidth = InsideLegendWidth; } FCanvasTextItem TextItem(FVector2D::ZeroVector, FText::FromString(*CurrentData[i].LineName), Font, CurrentData[i].Color); TextItem.EnableShadow(FColor::Black, FVector2D(1, 1)); TextItem.SetColor(CurrentData[i].Color); Canvas->DrawItem(TextItem, ScreenPos.X - LegendWidth, ScreenPos.Y); CurrentTextPos.Y -= (GraphScreenSize.Max.Y - GraphScreenSize.Min.Y) / CurrentData.Num(); } }
/** * Renders the memory headings for grouped rendering * * @param RI the render interface to draw with * @param X the X location to start rendering at * @param Y the Y location to start rendering at * * @return the height of headings rendered */ static int32 RenderMemoryHeadings(class FCanvas* Canvas,int32 X,int32 Y) { // The heading looks like: // Stat [32chars] MemUsed [8chars] PhysMem [8chars] // get the size of the spaces, since we can't render the width calculation strings int32 StatColumnSpaceSizeX, StatColumnSpaceSizeY; int32 TimeColumnSpaceSizeX, TimeColumnSpaceSizeY; StringSize(STAT_FONT, StatColumnSpaceSizeX, StatColumnSpaceSizeY, *STAT_COLUMN_WIDTH); StringSize(STAT_FONT, TimeColumnSpaceSizeX, TimeColumnSpaceSizeY, *TIME_COLUMN_WIDTH); Canvas->DrawShadowedString(X,Y,TEXT("Memory Counters"),STAT_FONT,StatGlobals.HeadingColor); // Determine where the first column goes int32 CurrX = X + StatGlobals.AfterNameColumnOffset; RightJustify(Canvas,CurrX,Y,TEXT("MemUsedAvg"),StatGlobals.HeadingColor); CurrX += StatGlobals.InterColumnOffset; RightJustify(Canvas,CurrX,Y,TEXT("MemUsedAvg%"),StatGlobals.HeadingColor); CurrX += StatGlobals.InterColumnOffset; RightJustify(Canvas,CurrX,Y,TEXT("MemUsedMax"),StatGlobals.HeadingColor); CurrX += StatGlobals.InterColumnOffset; RightJustify(Canvas,CurrX,Y,TEXT("MemUsedMax%"),StatGlobals.HeadingColor); CurrX += StatGlobals.InterColumnOffset; RightJustify(Canvas,CurrX,Y,TEXT("MemPool"),StatGlobals.HeadingColor); CurrX += StatGlobals.InterColumnOffset; RightJustify(Canvas,CurrX,Y,TEXT("Pool Capacity"),StatGlobals.HeadingColor); return FONT_HEIGHT + (FONT_HEIGHT / 3); }
/** * Initializes stat render globals. */ void Initialize( const FIntPoint NewSizeXY ) { if( SizeXY != NewSizeXY ) { SizeXY = NewSizeXY; bNeedRefresh = true; } if( SizeXY.X < 1280 ) { SetNewFont( EStatFontTypes::Tiny ); } if( bNeedRefresh ) { // This is the number of W characters to leave spacing for in the stat name column. const FString STATNAME_COLUMN_WIDTH = FString::ChrN( GetNumCharsForStatName(), 'M' ); // This is the number of W characters to leave spacing for in the other stat columns. const FString STATDATA_COLUMN_WIDTH = FString::ChrN( StatFontType == EStatFontTypes::Small ? 8 : 7, 'W' ); // Get the size of the spaces, since we can't render the width calculation strings. int32 StatColumnSpaceSizeY = 0; int32 TimeColumnSpaceSizeY = 0; // Determine where the first column goes. StringSize(StatFont, AfterNameColumnOffset, StatColumnSpaceSizeY, *STATNAME_COLUMN_WIDTH); // Determine the width of subsequent columns. StringSize(StatFont, InterColumnOffset, TimeColumnSpaceSizeY, *STATDATA_COLUMN_WIDTH); bNeedRefresh = false; } }
static void RightJustify(FCanvas* Canvas, int32 X, int32 Y, TCHAR const* Text, FLinearColor const& Color) { int32 StatColumnSpaceSizeX, StatColumnSpaceSizeY; StringSize(STAT_FONT, StatColumnSpaceSizeX, StatColumnSpaceSizeY, Text); Canvas->DrawShadowedString(X + StatGlobals.InterColumnOffset - StatColumnSpaceSizeX,Y,Text,STAT_FONT,Color); }
static void RightJustify(FCanvas* Canvas, int32 X, int32 Y, TCHAR const* Text, FLinearColor const& Color) { int32 StatColumnSpaceSizeX, StatColumnSpaceSizeY; StringSize(GetStatRenderGlobals().StatFont, StatColumnSpaceSizeX, StatColumnSpaceSizeY, Text); Canvas->DrawShadowedString(X + GetStatRenderGlobals().InterColumnOffset - StatColumnSpaceSizeX,Y,Text,GetStatRenderGlobals().StatFont,Color); }
void FloatToStr(float float_nr, char* float_str, char accuracy) { int intNr = float_nr; float_nr -= intNr; intToStr(intNr, float_str); int pointPos = StringSize(float_str); if (pointPos > 0) { float_str[pointPos++] = '.'; while (accuracy--) { float_nr *= 10; char restNr = float_nr; float_str[pointPos++] = restNr + '0'; float_nr -= restNr; } float_str[pointPos] = 0; // while (float_str[--pointPos] == '0') { // float_str[pointPos] = 0; // } } }
void zuluCryptFormatSize( u_int64_t number,char * buffer,size_t buffer_size ) { const char * z = StringIntToString_1( buffer,buffer_size,number ) ; switch( StringSize( z ) ){ case 0 : case 1 : case 2 : case 3 : snprintf( buffer,buffer_size,"%d B",( int )number ) ; break ; case 4 : case 5 : case 6 : convert( buffer,buffer_size,"KB",number,1024 ) ; break ; case 7 : case 8 : case 9 : convert( buffer,buffer_size,"MB",number,1024 * 1024 ) ; break ; case 10: case 11 : case 12 : convert( buffer,buffer_size,"GB",number,1024 * 1024 * 1024 ) ; break ; case 13: case 14 : case 15 : convert( buffer,buffer_size,"TB",number,1024.0 * 1024 * 1024 * 1024 ) ; break ; default: convert( buffer,buffer_size,"TB",number,1024.0 * 1024 * 1024 * 1024 ) ; break ; } }
static string_t _get_mapper_property_from_udev( const char * mapper,const char * prefix,size_t position ) { DIR * dir = opendir( "/dev/disk/by-id/" ) ; struct dirent * e ; const char * f = mapper + StringSize( crypt_get_dir() ) + 1 ; stringList_t stl ; string_t st = StringVoid ; if( dir != NULL ){ while( ( e = readdir( dir ) ) != NULL ){ if( StringStartsAndEndsWith( e->d_name,prefix,f ) ){ stl = StringListSplit( e->d_name,'-' ) ; st = StringListCopyStringAt( stl,position ) ; StringListDelete( &stl ) ; break ; } } closedir( dir ) ; } return st ; }
void StringPushBack(char* str, char ch){ char pos=StringSize(str); if(pos>0){ str[pos++]=ch; str[pos]=0; } }
/** * Initializes stat render globals. * * @param bForce - forces to initialize globals again, used after font has been changed * */ void Initialize( bool bForce = false ) { static bool bIsInitialized = false; if( !bIsInitialized || bForce ) { // Get the size of the spaces, since we can't render the width calculation strings. int32 StatColumnSpaceSizeY; int32 TimeColumnSpaceSizeY; // Determine where the first column goes. StringSize(STAT_FONT, AfterNameColumnOffset, StatColumnSpaceSizeY, *STAT_COLUMN_WIDTH); // Determine the width of subsequent columns. StringSize(STAT_FONT, InterColumnOffset, TimeColumnSpaceSizeY, *TIME_COLUMN_WIDTH); bIsInitialized = true; } }
void FCrashInfo::WriteLine( FArchive* ReportFile, const ANSICHAR* Line ) { if( Line != NULL ) { int64 StringBytes = StringSize( Line ); ReportFile->Serialize( ( void* )Line, StringBytes ); } ReportFile->Serialize( TCHAR_TO_UTF8( LINE_TERMINATOR ), FCStringWide::Strlen(LINE_TERMINATOR) ); }
static u_int64_t _offset( const char * offset ) { char * e ; u_int64_t r = 0 ; size_t s = StringSize( offset ) ; if( s == 0 ){ return 0 ; }else{ e = StringCopy_2( offset ) ; if( StringEndsWithAtLeastOne( e,"m","MB","mb","Mb","M",NULL ) ){ r = StringConvertToInt( _remove_letters( e ) ) ; r = 2 * 1024 * r ; }else if( StringEndsWithAtLeastOne( e,"g","GB","gb","Gb","G",NULL ) ){ r = StringConvertToInt( _remove_letters( e ) ) ; r = 2 * 1024 * 1024 * r ; }else if( StringEndsWithAtLeastOne( e,"t","TB","tb","Tb","T",NULL ) ){ r = StringConvertToInt( _remove_letters( e ) ) ; r = 1.0 * 2 * 1024 * 1024 * 1024 * r ; }else if( StringEndsWithAtLeastOne( e,"k","KB","kb","Kb","K",NULL ) ){ r = StringConvertToInt( _remove_letters( e ) ) ; r = 2 * r ; }else if( StringEndsWithAtLeastOne( e,"b","B",NULL ) ){ r = StringConvertToInt( _remove_letters( e ) ) ; if( r < 512 ){ r = 0 ; }else{ r = r / 512 ; } }else { r = StringConvertToInt( offset ) ; } StringFree( e ) ; } return r ; }
void UReporterGraph::DrawAxes(UCanvas* Canvas) { FVector2D Min = GraphScreenSize.Min; FVector2D XMax = GraphScreenSize.Min; XMax.X = GraphScreenSize.Max.X; FVector2D YMax = GraphScreenSize.Min; YMax.Y = GraphScreenSize.Max.Y; UFont* Font = GetDefaultFont(); int32 StringSizeX, StringSizeY; // Draw the X axis StringSize(Font, StringSizeX, StringSizeY, *FString::Printf(TEXT("%.2f"), GraphMinMaxData.Max.X) ); const float SizeX = (XMax.X - Min.X) * Canvas->SizeX; NumXNotches = FMath::CeilToInt(SizeX * 0.7 / StringSizeX); DrawAxis(Canvas, Min, XMax, NumXNotches, false); // Draw the Y axis StringSize(Font, StringSizeX, StringSizeY, *FString::Printf(TEXT("%.2f"), GraphMinMaxData.Max.Y)); float SizeY = (YMax.Y - Min.Y) * Canvas->SizeY; NumYNotches = FMath::CeilToInt(SizeY * 0.7 / StringSizeY); DrawAxis(Canvas, Min, YMax, NumYNotches, true); }
int main(void) { String s = StringCreate("Craig"); String t = StringDup(s); t = s; printf("Hello "); StringPrint(s); printf(" I see you're %d characters long\n", StringSize(s)); StringDestroy(s); StringDestroy(t); }
/* * Calculate the width of the key. */ static double KeyWidth(void) { int i; double c; c = 0; for (i = 0; i < nidents; i++) c = maxDouble(c, StringSize(identtable[i]->name)); c += 3 * borderspace; c += KEY_BOX_WIDTH; return c; }
static u_int64_t _offset( const char * offset ) { char * e ; char f ; u_int64_t r = 0 ; size_t s = StringSize( offset ) ; if( s == 0 ){ return 0 ; }else{ f = *( offset + s - 1 ) ; } if( !( f >= '0' && f <= '9' ) ){ /* * The argument ends with a non digit number,assume the argument is not in offsets but * in bytes and convert it to offsets */ e = StringCopy_2( offset ) ; *( e + s - 1 ) = '\0' ; r = StringConvertToInt( e ) ; if( f == 'b' || f == 'B' ) { if( r < 512 ){ r = 0 ; }else{ r = r / 512 ; } }else if( f == 'k' || f == 'K' ){ r = 2 * r ; }else if( f == 'm' || f == 'M' ){ r = 2 * 1024 * r ; }else if( f == 'g' || f == 'G' ){ r = 2 * 1024 * 1024 * r ; }else if( f == 't' || f == 'T' ){ r = 1.0 * 2 * 1024 * 1024 * 1024 * r ; }else{ r = 0 ; } StringFree( e ) ; }else{ r = StringConvertToInt( offset ) ; } return r ; }
// Utility routine which allocates memory and copies a string // INT CopyString(PCWSTR wzSrc, __deref_out PWSTR *pwzDest) { INT err = NO_ERROR; ULONG cb = StringSize(wzSrc); *pwzDest = malloc(cb); if (*pwzDest == NULL) { err = WSA_NOT_ENOUGH_MEMORY; } else { memcpy(*pwzDest, wzSrc, cb); } return err; }
static floatish KeyWidth(void) { intish i; floatish c; c = 0.0; for (i = 0; i < nidents; i++) { c = max(c, StringSize(identtable[i]->name)); } c += 3.0 * borderspace; c += (floatish) KEY_BOX_WIDTH; return c; }
void UInterpTrackAkAudioEvent::DrawTrack( FCanvas* Canvas, UInterpGroup* Group, const FInterpTrackDrawParams& Params ) { UInterpData* Data = CastChecked<UInterpData>(Group->GetOuter()); bool bHitTesting = Canvas->IsHitTesting(); // Use base-class to draw key triangles Super::DrawTrack(Canvas, Group, Params ); // Draw event name for each block on top. for(int32 i = 0; i < Events.Num(); i++) { float SoundStartTime = Events[i].Time; int32 PixelPos = FMath::TruncToInt((SoundStartTime - Params.StartTime) * Params.PixelsPerSec); UAkAudioEvent * Event = Events[i].AkAudioEvent; FString SoundString( TEXT("None") ); if(Event) { SoundString = FString( Event->GetName() ); } else { SoundString = Events[i].EventName; } int32 XL, YL; StringSize( GEngine->GetSmallFont(), XL, YL, *SoundString ); if(bHitTesting) { Canvas->SetHitProxy( new HInterpTrackKeypointProxy(Group, this, i) ); } Canvas->DrawShadowedString( PixelPos + 2, Params.TrackHeight - YL - KeyVertOffset, *SoundString, GEngine->GetSmallFont(), KeyLabelColor ); if(bHitTesting) { Canvas->SetHitProxy(NULL); } } }
/* * 1 is returned if a volume is a truecrypt volume. * 0 is returned if a volume is not a truecrypt volume or functionality is not supported */ int zuluCryptVolumeIsTcrypt( const char * device,const char * key,int key_source ) { struct crypt_device * cd = NULL; struct crypt_params_tcrypt params ; memset( ¶ms,'\0',sizeof( struct crypt_params_tcrypt ) ) ; if( key_source ){;} if( crypt_init( &cd,device ) < 0 ){ return 0 ; }else{ params.passphrase = key ; params.passphrase_size = StringSize( key ) ; params.flags = CRYPT_TCRYPT_LEGACY_MODES ; if( crypt_load( cd,CRYPT_TCRYPT,¶ms ) == 0 ){ return zuluExit( 1,cd ) ; }else{ return zuluExit( 0,cd ) ; } } }
int zuluCryptEXEOpenVolume( const struct_opts * opts,const char * mapping_name,uid_t uid ) { int share = opts->share ; int open_mount = opts->open_mount ; const char * device = opts->device ; const char * mount_point = opts->mount_point ; const char * m_opts = opts->m_opts ; const char * source = opts->key_source ; const char * pass = opts->key ; const char * plugin_path = opts->plugin_path ; const char * fs_opts = opts->fs_opts ; const char * offset = opts->offset ; const char * const * tcrypt_keyfiles = opts->tcrypt_multiple_keyfiles ; /* * Below is a form of memory management.All strings are collected in a stringlist object to easily delete them * when the function returns.This allows for the function to have multiple exit points without risks of leaking * memory from manually examining each exit point to make sure all strings are deleted or go with multiple goto * code deleting blocks to take into account different exit points. */ stringList_t stl ; string_t * stringArray = StringListArray( &stl,6 ) ; string_t * passphrase = &stringArray[ 0 ] ; string_t * m_name = &stringArray[ 1 ] ; string_t * data = &stringArray[ 2 ] ; string_t * m_point = &stringArray[ 3 ] ; string_t * mapper = &stringArray[ 4 ] ; string_t * mapper_path = &stringArray[ 5 ] ; const char * key = NULL ; const char * mapper_name ; const char * e ; size_t key_len = 0 ; int st = 0 ; stringList_t stz ; tvcrypt v_info ; unsigned long m_flags ; int tcrypt_keyfile = 0 ; const char * uuid ; char * device_path ; /* * open_struct_t is declared in ../lib/include.h */ open_struct_t volume ; struct stat statstr ; /* * zuluCryptVolumeIsInSystemVolumeList() is defined in volumes.c */ if( zuluCryptVolumeIsInSystemVolumeList( device ) ){ /* * check permissions only if volume is explicity mentioned as system. * This is an exception to avoid some udev bad behaviors on udev enabled build */ if( !zuluCryptUserIsAMemberOfAGroup( uid,"zulucrypt" ) ){ return zuluExit( 22,device,mount_point,stl ) ; } } if( m_opts == NULL ){ m_opts = "rw" ; } /* * zuluCryptMountFlagsAreNotCorrect() is defined in ./mount_flags.c */ if( zuluCryptMountFlagsAreNotCorrect( m_opts,uid,&m_flags ) ){ return zuluExit( 5,device,mount_point,stl ) ; } if( StringHasComponent( m_opts,"rw" ) ){ /* * zuluCryptSecurityDeviceIsWritable() is defined in path_access.c */ st = zuluCryptCanOpenPathForWriting( device,uid ) ; }else{ /* * zuluCryptSecurityDeviceIsReadable() is defined in path_access.c */ st = zuluCryptCanOpenPathForReading( device,uid ) ; } /* * 1-permissions denied * 2-invalid path * 3-shenanigans * 4-common error */ switch( st ){ case 0 : break ; case 1 : return zuluExit( 6,device,mount_point,stl ) ; case 2 : return zuluExit( 6,device,mount_point,stl ) ; case 3 : return zuluExit( 6,device,mount_point,stl ) ; case 4 : return zuluExit( 6,device,mount_point,stl ) ; default: return zuluExit( 6,device,mount_point,stl ) ; } if( open_mount ){ /* * zuluCryptCreateMountPoint() is defined in create_mount_point.c */ *m_point = zuluCryptCreateMountPoint( device,mount_point,m_opts,uid ) ; mount_point = StringContent( *m_point ) ; if( mount_point == NULL ){ return zuluExit( 9,device,mount_point,stl ) ; } }else{ if( uid != 0 ){ return zuluExit( 7,device,mount_point,stl ) ; } if( mount_point != NULL ){ return zuluExit( 8,device,mount_point,stl ) ; } } if( share ){ /* * zuluCryptBindSharedMountPointPathTaken() is defined in bind.c */ if( zuluCryptBindSharedMountPointPathTaken( *m_point ) ){ return zuluExit_1( 10,opts,device,mount_point,stl ) ; } } /* * zuluCryptCreateMapperName() is defined in ../lib/create_mapper_name.c */ *m_name = zuluCryptCreateMapperName( device,mapping_name,uid,ZULUCRYPTshortMapperPath ) ; *mapper = StringCopy( *m_name ) ; mapper_name = StringContent( *m_name ) ; *mapper_path = String( zuluCryptMapperPrefix() ) ; e = StringMultipleAppend( *mapper_path,"/",mapper_name,NULL ) ; if( stat( e,&statstr ) == 0 ){ return zuluExit_1( 11,opts,device,mount_point,stl ) ; } if( plugin_path != NULL ){ /* * zuluCryptUUIDFromPath() is defined in path_access.c */ uuid = zuluCryptUUIDFromPath( device ) ; device_path = _device_path( device ) ; /* * zuluCryptPluginManagerGetKeyFromModule is defined in ../pluginManager/zuluCryptPluginManager.c */ *passphrase = zuluCryptPluginManagerGetKeyFromModule( device_path,plugin_path,uuid,uid,opts,&st ) ; StringFree( device_path ) ; StringFree( uuid ) ; if( st != 0 || *passphrase == StringVoid ){ return zuluExit_1( 12,opts,device,mount_point,stl ) ; } key_len = StringLength( *passphrase ) ; key = StringContent( *passphrase ) ; zuluCryptSecurityLockMemory_1( *passphrase ) ; }else if( source == NULL && tcrypt_keyfiles[ 0 ] == NULL ){ printf( gettext( "Enter passphrase: " ) ) ; /* * ZULUCRYPT_KEY_MAX_SIZE is set in ../constants.h */ switch( StringSilentlyGetFromTerminal_1( passphrase,ZULUCRYPT_KEY_MAX_SIZE ) ){ case 1 : return zuluExit_1( 13,opts,device,mount_point,stl ) ; case 2 : return zuluExit_1( 14,opts,device,mount_point,stl ) ; } printf( "\n" ) ; key = StringContent( *passphrase ) ; key_len = StringLength( *passphrase ) ; zuluCryptSecurityLockMemory_1( *passphrase ) ; }else{ if( source == NULL || pass == NULL ){ if( tcrypt_keyfiles == NULL ){ return zuluExit_1( 15,opts,device,mount_point,stl ) ; } } if( StringsAreEqual( source,"-p" ) ){ key = pass ; key_len = StringSize( pass ) ; }else if( StringsAreEqual( source,"-f" ) ){ if( StringHasNoComponent( pass,"/.zuluCrypt-socket" ) ){ tcrypt_keyfile = 1 ; } /* * function is defined at "path_access.c" */ switch( zuluCryptGetPassFromFile( pass,uid,data ) ){ case 1 : return zuluExit_1( 16,opts,device,mount_point,stl ) ; case 2 : return zuluExit_1( 17,opts,device,mount_point,stl ) ; case 4 : return zuluExit_1( 18,opts,device,mount_point,stl ) ; case 5 : return zuluExit_1( 19,opts,device,mount_point,stl ) ; } key = StringContent( *data ) ; key_len = StringLength( *data ) ; zuluCryptSecurityLockMemory_1( *data ) ; } } memset( &volume,'\0',sizeof( open_struct_t ) ) ; if( key != NULL ){ volume.key = key ; volume.key_len = key_len ; }else{ volume.key = "" ; volume.key_len = 0 ; } volume.device = device ; volume.offset = offset ; volume.mapper_name = mapper_name ; volume.m_point = mount_point ; volume.fs_opts = fs_opts ; volume.uid = uid ; volume.m_opts = m_opts ; volume.m_flags = m_flags ; /* * zuluCryptTrueCryptVeraCryptVolumeInfo() is defined in this source file. */ zuluCryptTrueCryptVeraCryptVolumeInfo( opts->type,&v_info ) ; volume.iteration_count = v_info.iteration_count ; volume.veraCrypt_volume = StringAtLeastOneMatch( v_info.type,"vcrypt","veracrypt","vera",NULL ) ; StringDelete( &v_info.type ) ; plugin_path = plugin_path + StringLastIndexOfChar_1( plugin_path,'/' ) + 1 ; volume.luks_detached_header = StringHasComponent( plugin_path,"luks" ) ; volume.general_detached_header = StringHasComponent( plugin_path,"generic_header" ) ; if( tcrypt_keyfile ){ volume.key_source = TCRYPT_KEYFILE ; } if( tcrypt_keyfiles[ 0 ] != NULL ){ /* * Here, we take a list of keyfiles supplied by the user and then copy them to a safe * location at "/run/zuluCrypt" and then we pass these safe copies to cryptsetup. * * The idea is not to let cryptsetup, a privileged process handle user managed files. */ stz = zuluCryptCreateKeyFiles( tcrypt_keyfiles,0 ) ; volume.tcrypt_keyfiles_count = StringListSize( stz ) ; volume.tcrypt_keyfiles = StringListStringArray_0( stz ) ; st = _open_volume( &volume ) ; zuluCryptDeleteKeyFiles( stz ) ; StringFree( volume.tcrypt_keyfiles ) ; StringListDelete( &stz ) ; }else{ st = _open_volume( &volume ) ; } /* * below two return values comes from ../lib/mount_volume.c */ if( st == -1 ){ st = 20 ; } if( st == 12 ){ st = 21 ; } if( st == 8 || st == 3 ){ st = 3 ; } device = StringMultiplePrepend( *mapper,"/",zuluCryptMapperPrefix(),NULL ) ; if( st == 0 && share ){ /* * user wish to share the mount point bind the mount point to a publicly accessed path at /run/media/public/ */ /* * zuluCryptBindMountVolume() is defined in ../zuluCrypt-cli/bin/bind.c */ zuluCryptBindMountVolume( device,*m_point,m_flags ) ; } /* * zuluCryptCheckInvalidKey() is defined in check_invalid_key.c */ zuluCryptCheckInvalidKey( opts->device ) ; return zuluExit_1( st,opts,device,mount_point,stl ) ; }
void UFaceFXMatineeControl::DrawTrack( FCanvas* Canvas, UInterpGroup* Group, const FInterpTrackDrawParams& Params ) { static const FColor KeySelectedColor(255,128,0); static const FColor KeyLabelColor(225,225,225); static const FColor KeyBackgroundColor(0,150,200); static const FColor KeyColorBlack(0,0,0); static const int32 KeyVertOffset = 3; const bool bHitTesting = Canvas->IsHitTesting(); const bool bAllowBarSelection = bHitTesting && Params.bAllowKeyframeBarSelection; const bool bAllowTextSelection = bHitTesting && Params.bAllowKeyframeTextSelection; AMatineeActor* MatineeActor = CastChecked<AMatineeActor>(Group->GetOuter()->GetOuter()); UInterpGroupInst* GroupInst = MatineeActor->FindFirstGroupInst(Group); const AActor* GroupActor = GroupInst ? GroupInst->GetGroupActor() : nullptr; //cached animation ids TArray<FFaceFXAnimId> AnimIds; AnimIds.AddUninitialized(Keys.Num()); //Draw the tiles for each animation for (int32 i = 0; i < Keys.Num(); i++) { const FFaceFXTrackKey& AnimKey = Keys[i]; FFaceFXAnimId AnimationId; if(AnimKey.AnimationId.IsValid()) { AnimationId = AnimKey.AnimationId; } else if(const UFaceFXAnim* Animation = GetAnimation(AnimKey, this)) { AnimationId = Animation->GetId(); } AnimIds[i] = AnimationId; //determine animation duration const float AnimStartTime = AnimKey.Time; const float AnimEndTime = AnimStartTime + AnimKey.GetAnimationDuration(GroupActor); const int32 StartPixelPos = FMath::TruncToInt((AnimStartTime - Params.StartTime) * Params.PixelsPerSec); const int32 EndPixelPos = FMath::TruncToInt((AnimEndTime - Params.StartTime) * Params.PixelsPerSec); // Find if this sound is one of the selected ones. bool bKeySelected = false; for (const FInterpEdSelKey& SelectedKey : Params.SelectedKeys) { if(SelectedKey.Group == Group && SelectedKey.Track == this && SelectedKey.KeyIndex == i) { bKeySelected = true; break; } } const FColor& BorderColor = bKeySelected ? KeySelectedColor : KeyColorBlack; if(bAllowBarSelection) { Canvas->SetHitProxy(new HInterpTrackKeypointProxy(Group, this, i)); } Canvas->DrawTile(StartPixelPos, KeyVertOffset, EndPixelPos - StartPixelPos + 1, FMath::TruncToFloat(Params.TrackHeight - 2.f*KeyVertOffset), 0.f, 0.f, 1.f, 1.f, BorderColor); Canvas->DrawTile(StartPixelPos+1, KeyVertOffset+1, EndPixelPos - StartPixelPos - 1, FMath::TruncToFloat(Params.TrackHeight - 2.f*KeyVertOffset) - 2, 0.f, 0.f, 1.f, 1.f, KeyBackgroundColor); if(bAllowBarSelection) { Canvas->SetHitProxy(nullptr); } } // Use base-class to draw key triangles Super::DrawTrack( Canvas, Group, Params ); //Draw animation names on top for (int32 i = 0; i < Keys.Num(); i++) { const FFaceFXTrackKey& AnimKey = Keys[i]; //fetch the cached animation id for the key const FFaceFXAnimId& AnimId = AnimIds[i]; FString AnimName(TEXT("Unknown")); if(AnimId.IsValid()) { AnimName = AnimId.Group.IsNone() ? TEXT("") : AnimId.Group.ToString() + TEXT(" / "); AnimName += AnimId.Name.ToString(); } if(AnimKey.bLoop) { AnimName += TEXT(" [Looping]"); } int32 XL, YL; StringSize(GEngine->GetSmallFont(), XL, YL, *AnimName); if (bAllowTextSelection) { Canvas->SetHitProxy(new HInterpTrackKeypointProxy(Group, this, i)); } const int32 PixelPos = FMath::TruncToInt((AnimKey.Time - Params.StartTime) * Params.PixelsPerSec); Canvas->DrawShadowedString((PixelPos + 2), Params.TrackHeight - YL - KeyVertOffset, *AnimName, GEngine->GetSmallFont(), KeyLabelColor); if (bAllowTextSelection) { Canvas->SetHitProxy(nullptr); } } }
void FTileSetEditorViewportClient::Draw(FViewport* InViewport, FCanvas* Canvas) { // Clear the viewport Canvas->Clear(GetBackgroundColor()); // Can only proceed if we have a valid tile set UPaperTileSet* TileSet = TileSetBeingEdited.Get(); if (TileSet == nullptr) { return; } if (UTexture2D* Texture = TileSet->GetTileSheetTexture()) { const bool bUseTranslucentBlend = Texture->HasAlphaChannel(); // Fully stream in the texture before drawing it. Texture->SetForceMipLevelsToBeResident(30.0f); Texture->WaitForStreaming(); FLinearColor TextureDrawColor = FLinearColor::White; { // Draw the tile sheet texture const float XPos = -ZoomPos.X * ZoomAmount; const float YPos = -ZoomPos.Y * ZoomAmount; const float Width = Texture->GetSurfaceWidth() * ZoomAmount; const float Height = Texture->GetSurfaceHeight() * ZoomAmount; Canvas->DrawTile(XPos, YPos, Width, Height, 0.0f, 0.0f, 1.0f, 1.0f, TextureDrawColor, Texture->Resource, bUseTranslucentBlend); } const FLinearColor BorderRectangleColor(0.3f, 0.3f, 0.3f, 1.0f); { const FIntPoint TextureSize = Texture->GetImportedSize(); const FIntMargin BorderSize = TileSet->GetMargin(); const FIntRect TileSetRegion(BorderSize.Left, BorderSize.Top, TextureSize.X - BorderSize.Right, TextureSize.Y - BorderSize.Bottom); const float X = (TileSetRegion.Min.X - ZoomPos.X) * ZoomAmount; const float Y = (TileSetRegion.Min.Y - ZoomPos.Y) * ZoomAmount; const float W = TileSetRegion.Width() * ZoomAmount; const float H = TileSetRegion.Height() * ZoomAmount; FCanvasBoxItem BoxItem(FVector2D(X, Y), FVector2D(W, H)); BoxItem.SetColor(BorderRectangleColor); Canvas->DrawItem(BoxItem); } if (bShowTilesWithCollision || bShowTilesWithMetaData) { // Draw an overlay rectangle on top of any tiles that have collision or metadata geometry const int32 NumTiles = TileSet->GetTileCount(); const FLinearColor CollisionOverlayColor(0.0f, 0.7f, 1.0f, 0.5f); const FLinearColor MetaDataOverlayColor(1.0f, 0.2f, 0.0f, 0.5f); const FLinearColor InfoOverlayColor = bShowTilesWithCollision ? CollisionOverlayColor : MetaDataOverlayColor; const FIntPoint TileSetTileSize(TileSet->GetTileSize()); const float Width = (TileSetTileSize.X - 2) * ZoomAmount; const float Height = (TileSetTileSize.Y - 2) * ZoomAmount; for (int32 TileIndex = 0; TileIndex < NumTiles; ++TileIndex) { if (const FPaperTileMetadata* TileMetadata = TileSet->GetTileMetadata(TileIndex)) { const bool bShowDueToCollision = TileMetadata->HasCollision() && bShowTilesWithCollision; const bool bShowDueToMetaData = TileMetadata->HasMetaData() && bShowTilesWithMetaData; if (bShowDueToCollision || bShowDueToMetaData) { FVector2D TileUV; TileSet->GetTileUV(TileIndex, /*out*/ TileUV); const float XPos = (TileUV.X + 1 - ZoomPos.X) * ZoomAmount; const float YPos = (TileUV.Y + 1 - ZoomPos.Y) * ZoomAmount; Canvas->DrawTile(XPos, YPos, Width, Height, 0.0f, 0.0f, 1.0f, 1.0f, InfoOverlayColor, GWhiteTexture, /*bUseTranslucentBlend=*/ true); } } } } } // Overlay the selection rectangles DrawSelectionRectangles(InViewport, Canvas); if (bHasValidPaintRectangle) { const FViewportSelectionRectangle& Rect = ValidPaintRectangle; const float X = (Rect.TopLeft.X - ZoomPos.X) * ZoomAmount; const float Y = (Rect.TopLeft.Y - ZoomPos.Y) * ZoomAmount; const float W = Rect.Dimensions.X * ZoomAmount; const float H = Rect.Dimensions.Y * ZoomAmount; FCanvasBoxItem BoxItem(FVector2D(X, Y), FVector2D(W, H)); BoxItem.SetColor(Rect.Color); Canvas->DrawItem(BoxItem); } if (CurrentSelectedTileIndex != INDEX_NONE) { const FString TileIndexString = FString::Printf(TEXT("Tile# %d"), CurrentSelectedTileIndex); int32 XL; int32 YL; StringSize(GEngine->GetLargeFont(), XL, YL, *TileIndexString); const float DrawX = 4.0f; const float DrawY = FMath::FloorToFloat(InViewport->GetSizeXY().Y - YL - 4.0f); Canvas->DrawShadowedString(DrawX, DrawY, *TileIndexString, GEngine->GetLargeFont(), FLinearColor::White); } }
/* * get_pass_from_file function is defined at get_pass_from_file.c * */ int zuluCryptEXEAddKey( const struct_opts * opts,uid_t uid ) { const char * device = opts->device ; const char * keyType1 = opts->existing_key_source ; const char * existingKey = opts->existing_key ; const char * keyType2 = opts->new_key_source ; const char * newKey = opts->new_key ; /* * Below is a form of memory management.All strings are collected in a stringlist object to easily delete them * when the function returns.This allows for the function to have multiple exit points without risks of leaking * memory from manually examining each exit point to make sure all strings are deleted or go with multiple goto * code deleting blocks to take into account different exit points. */ stringList_t stl ; string_t * stringArray = StringListArray( &stl,5 ) ; string_t * presentKey = &stringArray[ 0 ] ; string_t * newKey_1 = &stringArray[ 1 ] ; string_t * newKey_2 = &stringArray[ 2 ] ; string_t * ek = &stringArray[ 3 ] ; string_t * nk = &stringArray[ 4 ] ; const char * key1 = NULL ; const char * key2 = NULL ; size_t len1 = 0 ; size_t len2 = 0 ; int status = 0 ; tcrypt_opts tcrypt ; memset( &tcrypt,'\0',sizeof( tcrypt_opts ) ) ; /* * zuluCryptPartitionIsSystemPartition() is defined in ./partitions.c */ if( zuluCryptPartitionIsSystemPartition( device,uid ) ){ if( !zuluCryptUserIsAMemberOfAGroup( uid,"zulucrypt" ) ){ return zuluExit( 4,stl ) ; } } /* * zuluCryptSecurityDeviceIsWritable() is defined in path_access.c */ status = zuluCryptCanOpenPathForWriting( device,uid ) ; /* * 1-permissions denied * 2-invalid path * 3-shenanigans * 4-common error */ switch( status ){ case 0 : break ; case 1 : return zuluExit( 5,stl ) ; case 2 : return zuluExit( 5,stl ) ; case 3 : return zuluExit( 5,stl ) ; case 4 : return zuluExit( 5,stl ) ; default: return zuluExit( 5,stl ) ; } switch( _zuluCryptCheckEmptySlots( device ) ){ case 0 : return zuluExit( 6,stl ) ; case 1 : return zuluExit( 2,stl ) ; case 2 : /* no complains,continue */ ; } if( keyType1 == NULL && keyType2 == NULL ){ switch( zuluGetKeys( presentKey,newKey_1,newKey_2 ) ){ case 1 : return zuluExit( 7,stl ) ; case 2 : return zuluExit( 8,stl ) ; } if( StringEqualString( *newKey_1,*newKey_2 ) ){ key1 = StringContent( *presentKey ) ; len1 = StringLength ( *presentKey ) ; key2 = StringContent( *newKey_1 ) ; len2 = StringLength ( *newKey_1 ) ; }else{ return zuluExit( 9,stl ) ; } }else{ if( newKey == NULL || existingKey == NULL ){ return zuluExit( 10,stl ) ; } if( StringsAreEqual( keyType1,"-f" ) ){ /* * this function is defined at "path_access.c" */ switch( zuluCryptGetPassFromFile( existingKey,uid,ek ) ){ case 1 : return zuluExit( 11,stl ) ; case 4 : return zuluExit( 12,stl ) ; case 2 : return zuluExit( 13,stl ) ; case 5 : return zuluExit( 14,stl ) ; } key1 = StringContent( *ek ) ; len1 = StringLength( *ek ) ; if( StringHasNoComponent( existingKey,"/.zuluCrypt-socket" ) ){ tcrypt.existing_key_is_keyfile = 1 ; } } if( StringsAreEqual( keyType2,"-f" ) ){ /* * this function is defined at "path_access.c" */ switch( zuluCryptGetPassFromFile( newKey,uid,nk ) ){ case 1 : return zuluExit( 11,stl ) ; case 4 : return zuluExit( 12,stl ) ; case 2 : return zuluExit( 13,stl ) ; case 5 : return zuluExit( 14,stl ) ; } key2 = StringContent( *nk ) ; len2 = StringLength( *nk ) ; if( StringHasNoComponent( newKey,"/.zuluCrypt-socket" ) ){ tcrypt.new_key_is_keyfile = 1 ; } } if( StringsAreEqual( keyType1,"-f" ) && StringsAreEqual( keyType2,"-f" ) ){ ; }else if( StringsAreEqual( keyType1,"-p" ) && StringsAreEqual( keyType2,"-p" ) ){ key1 = existingKey ; len1 = StringSize( existingKey ) ; key2 = newKey ; len2 = StringSize( newKey ) ; }else if( StringsAreEqual( keyType1,"-p" ) && StringsAreEqual( keyType2,"-f" ) ){ key1 = existingKey ; len1 = StringSize( existingKey ) ; }else if( StringsAreEqual( keyType1,"-f" ) && StringsAreEqual( keyType2,"-p" ) ){ key2 = newKey ; len2 = StringSize( newKey ) ; }else{ return zuluExit( 10,stl ) ; } } zuluCryptSecurityLockMemory( stl ) ; zuluCryptSecurityGainElevatedPrivileges() ; /* * zuluCryptVolumeIsLuks() is defined in ../lib/is_luks.c */ if( zuluCryptVolumeIsLuks( device ) ){ /* * zuluCryptAddKey() is defined in ../lib/add_key.c */ status = zuluCryptAddKey( device,key1,len1,key2,len2 ) ; }else{ tcrypt.device = device ; tcrypt.existing_key = key1 ; tcrypt.existing_key_size = len1 ; tcrypt.new_key = key2 ; tcrypt.new_key_size = len2 ; status = _replace_truecrypt_key( &tcrypt ) ; } zuluCryptSecurityDropElevatedPrivileges() ; return zuluExit( status,stl ) ; }
static unsigned long ComputeExternalSize(const internal_parser_type *ipt, unsigned long *SourceLines, unsigned long *Nodes) { otree *otp; ttree *ttp; nodeptr np; unsigned long size = sizeof(external_parser_type); unsigned long i, elems, bufchars; /* sourceline table */ elems = 0; if ((otp = ipt->srclines) == NULL) { if (ipt->last_source_line) { elems = ipt->last_source_line->lineno; } } else { while (otp->next) otp = otp->next; elems = otp->sum + otp->num; } *SourceLines = elems; size += elems * sizeof(offsrcline); /* the table */ /* nodetable */ elems = bufchars = 0; ttp = ipt->nodes; while (ttp) { for (i = 0;i < ttp->num;i++) { elems++; np = ttp->elems + i; if (np->name) bufchars += StringSize(np->name); /* * Add all sizes of strings that have been generated at the parsing * step. */ /* * See also several places in this file and in debug.c where this * switch list must be changed. Seek for X_CEXPRLIST. */ switch ( np->type ) { case X_CEXPRLIST: if ( np->u.strng ) bufchars += StringSize( np->u.strng ); break; default: break; } } ttp = ttp->next; } *Nodes = elems; size += elems * sizeof(treenode); size += bufchars; size += sizeof(((external_parser_type *)0)->Magic); return(size); }
void UReporterGraph::DrawData(UCanvas* Canvas) { FVector2D Start, End; const FVector2D Min = FVector2D(GraphScreenSize.Min.X * Canvas->SizeX, Canvas->SizeY - GraphScreenSize.Min.Y * Canvas->SizeY); const FVector2D Max = FVector2D(GraphScreenSize.Max.X * Canvas->SizeX, Canvas->SizeY - GraphScreenSize.Max.Y * Canvas->SizeY); const float Height = GraphScreenSize.Max.Y - GraphScreenSize.Min.Y; const float dx = Height / FMath::Abs(Max.Y - Min.Y); UFont* Font = GetDefaultFont(); int32 StringSizeX, StringSizeY; // Draw the X axis StringSize(Font, StringSizeX, StringSizeY, TEXT("0")); float UpOffset = 0; float DownOffset = 0; if (bDrawCursorOnGraph && DataStyle == EGraphDataStyle::Lines) { DrawLine(Canvas, DataToNormalized(FVector2D(CursorLocation, GraphMinMaxData.Min.Y)), DataToNormalized(FVector2D(CursorLocation, GraphMinMaxData.Max.Y)), FLinearColor::White, EReporterLineStyle::Line); } for (int32 i = 0; i < CurrentData.Num(); i++) { if (IsOffsetForDataSetsEnabled()) { if (i % 2) { UpOffset += dx; } else { DownOffset += dx; } } for (int32 j = 1; j < CurrentData[i].Data.Num(); j++) { FVector2D DataStart = Start = CurrentData[i].Data[j - 1]; FVector2D DataEnd = End = CurrentData[i].Data[j]; Start = DataToNormalized(Start); End = DataToNormalized(End); if (DataStyle == EGraphDataStyle::Lines) { const FVector2D DrawOffset = FVector2D(UpOffset, UpOffset) * (i % 2 ? 1.0 : -1.0f); DrawLine(Canvas, Start + DrawOffset, End + DrawOffset, CurrentData[i].Color); if (bDrawCursorOnGraph && CursorLocation >= DataStart.X && CursorLocation < DataEnd.X) { const float t = (CursorLocation - DataStart.X) / (DataEnd.X - DataStart.X); FVector2D Location = FMath::Lerp<FVector2D, float>(DataStart, DataEnd, t); FVector2D TextPos = ToScreenSpace(DataToNormalized(Location), Canvas) + DrawOffset; Canvas->Canvas->DrawShadowedString(StringSizeX + TextPos.X, TextPos.Y, *FString::Printf(TEXT("%1.2f"), Location.Y), Font, CurrentData[i].Color); } } else { FVector2D Position0, Position1, Position2; // draw the top triangle of the quad Position0.X = Start.X; Position0.Y = (GraphMinMaxData.Min.Y * (GraphScreenSize.Max.Y - GraphScreenSize.Min.Y)) + GraphScreenSize.Min.Y; Position1 = End; Position2 = Start; DrawTriangle(Canvas, Position0, Position1, Position2, CurrentData[i].Color); // draw the second triangle of the quad Position0.X = Start.X; Position0.Y = (GraphMinMaxData.Min.Y * (GraphScreenSize.Max.Y - GraphScreenSize.Min.Y)) + GraphScreenSize.Min.Y; Position1.X = End.X; Position1.Y = (GraphMinMaxData.Min.Y * (GraphScreenSize.Max.Y - GraphScreenSize.Min.Y)) + GraphScreenSize.Min.Y; Position2 = End; DrawTriangle(Canvas, Position0, Position1, Position2, CurrentData[i].Color); } } } }
void UReporterGraph::DrawAxis(UCanvas* Canvas, FVector2D Start, FVector2D End, float NumNotches, bool bIsVerticalAxis) { // Draw the axis line DrawLine(Canvas, Start, End, AxesColor); // Divide each axis up into the desired notches float NotchDelta = (Start - End).Size() / (float)NumNotches; FVector2D NotchDataDelta = (GraphMinMaxData.Max - GraphMinMaxData.Min) / NumNotches; FVector2D NotchLocation = Start; FVector2D NotchLength(0,0); FLinearColor NotchColor = AxesColor; // if we should just draw notches switch(AxisStyle) { case EGraphAxisStyle::Lines: { NumNotches = 1; FVector2D NotchDataDelta = (GraphMinMaxData.Max - GraphMinMaxData.Min) / NumNotches; NotchDelta = (Start - End).Size(); if(bIsVerticalAxis) { NotchLength.X = -(End.Y - Start.Y) * 0.05f; NotchLocation.X += NotchLength.X * -0.5f; } else { NotchLength.Y = -(End.X - Start.X) * 0.05f; NotchLocation.Y += NotchLength.Y * -0.5f; } } break; case EGraphAxisStyle::Notches: { if(bIsVerticalAxis) { NotchLength.X = -(End.Y - Start.Y) * 0.05f; NotchLocation.X += NotchLength.X * -0.5f; } else { NotchLength.Y = -(End.X - Start.X) * 0.05f; NotchLocation.Y += NotchLength.Y * -0.5f; } } break; case EGraphAxisStyle::Grid: { NotchColor *= 0.125f; if(bIsVerticalAxis) { NotchLength.X = End.Y - Start.Y; } else { NotchLength.Y = End.X - Start.X; } } break; } UFont* Font = GetDefaultFont(); const FVector2D Width = FVector2D((GraphScreenSize.Max.X - GraphScreenSize.Min.X), 0); const FVector2D Height = FVector2D(0, (GraphScreenSize.Max.Y - GraphScreenSize.Min.Y)); for (int Index = 0; Index < NumNotches + 1; Index++) { FString NotchValue = FString::Printf(TEXT("%1.2f"), (bIsVerticalAxis ? GraphMinMaxData.Min.Y + (NotchDataDelta.Y * (Index /*+ 1*/)) : GraphMinMaxData.Min.X + (NotchDataDelta.X * (Index /*+ 1*/)))); int32 StringSizeX, StringSizeY; StringSize(Font, StringSizeX, StringSizeY, *NotchValue ); FVector2D ScreenPos = ToScreenSpace(NotchLocation, Canvas); if (bIsVerticalAxis) { Canvas->Canvas->DrawShadowedString(ScreenPos.X - StringSizeX - 4, ScreenPos.Y - StringSizeY * 0.5f, *NotchValue, Font, AxesColor); DrawLine(Canvas, NotchLocation, NotchLocation + Width, NotchColor); } else { Canvas->Canvas->DrawShadowedString( ScreenPos.X - StringSizeX * 0.5f, ScreenPos.Y + (AxisStyle == EGraphAxisStyle::Grid ? + 5 : -NotchLength.Y * Canvas->SizeY), *NotchValue , Font, AxesColor); DrawLine(Canvas, NotchLocation, NotchLocation + Height, NotchColor); } if(bIsVerticalAxis) { NotchLocation.Y += NotchDelta; } else { NotchLocation.X += NotchDelta; } } }
void FPhATEdPreviewViewportClient::DrawCanvas( FViewport& InViewport, FSceneView& View, FCanvas& Canvas ) { if (!PhATPtr.IsValid()) { return; } // Turn on/off the ground box SharedData->EditorFloorComp->SetVisibility(SharedData->bDrawGround); float W, H; PhATFont->GetCharSize(TEXT('L'), W, H); const float XOffset = 5.0f; const float YOffset = 32.0f; FCanvasTextItem TextItem( FVector2D::ZeroVector, FText::GetEmpty(), PhATFont, FLinearColor::White ); // Write body/constraint count at top. FString StatusString = FText::Format( NSLOCTEXT("UnrealEd", "BodiesConstraints_F", "{0} Bodies {1} Considered for bounds {2} Ratio {3} Constraints"), FText::AsNumber(SharedData->PhysicsAsset->SkeletalBodySetups.Num()), FText::AsNumber(SharedData->PhysicsAsset->BoundsBodies.Num()), FText::AsNumber(static_cast<float>(SharedData->PhysicsAsset->BoundsBodies.Num())/static_cast<float>(SharedData->PhysicsAsset->SkeletalBodySetups.Num())), FText::AsNumber(SharedData->PhysicsAsset->ConstraintSetup.Num()) ).ToString(); TextItem.Text = FText::FromString( StatusString ); Canvas.DrawItem( TextItem, XOffset, YOffset); TextItem.Text = FText::GetEmpty(); if (SharedData->bRunningSimulation) { #if PLATFORM_MAC TextItem.Text = NSLOCTEXT("UnrealEd", "Sim_Mac", "SIM: Command+RightMouse to interact with bodies"); #else TextItem.Text = NSLOCTEXT("UnrealEd", "Sim", "SIM: Ctrl+RightMouse to interact with bodies"); #endif } else if (SharedData->bSelectionLock) { TextItem.Text = NSLOCTEXT("UnrealEd", "Lock", "LOCK"); }else if(SharedData->EditingMode == FPhATSharedData::PEM_ConstraintEdit) { if(GetWidgetMode() == FWidget::WM_Translate) { TextItem.Text = NSLOCTEXT("UnrealEd", "SingleMove", "hold ALT to move a single reference frame"); }else if(GetWidgetMode() == FWidget::WM_Rotate) { TextItem.Text = NSLOCTEXT("UnrealEd", "DoubleRotate", "hold ALT to rotate both reference frames"); } } Canvas.DrawItem( TextItem, XOffset, Viewport->GetSizeXY().Y - (3 + H) ); // Draw current physics weight if (SharedData->bRunningSimulation) { FString PhysWeightString = FString::Printf(TEXT("Phys Blend: %3.0f pct"), SharedData->EditorSimOptions->PhysicsBlend * 100.f); int32 PWLW, PWLH; StringSize(PhATFont, PWLW, PWLH, *PhysWeightString); TextItem.Text = FText::FromString(PhysWeightString); Canvas.DrawItem( TextItem, Viewport->GetSizeXY().X - (3 + PWLW + 2*W), Viewport->GetSizeXY().Y - (3 + H) ); } int32 HalfX = (Viewport->GetSizeXY().X-XOffset)/2; int32 HalfY = Viewport->GetSizeXY().Y/2; if ((SharedData->bShowHierarchy && SharedData->EditorSimOptions->bShowNamesInHierarchy)) { // Iterate over each graphics bone. for (int32 i = 0; i < SharedData->EditorSkelComp->GetNumComponentSpaceTransforms(); ++i) { FVector BonePos = SharedData->EditorSkelComp->ComponentToWorld.TransformPosition(SharedData->EditorSkelComp->GetComponentSpaceTransforms()[i].GetLocation()); FPlane proj = View.Project(BonePos); if (proj.W > 0.f) // This avoids drawing bone names that are behind us. { int32 XPos = HalfX + (HalfX * proj.X); int32 YPos = HalfY + (HalfY * (proj.Y * -1)); FName BoneName = SharedData->EditorSkelMesh->RefSkeleton.GetBoneName(i); FColor BoneNameColor = FColor::White; //iterate through selected bones and see if any match for(int32 j=0; j< SharedData->SelectedBodies.Num(); ++j) { int32 SelectedBodyIndex = SharedData->SelectedBodies[j].Index; FName SelectedBoneName = SharedData->PhysicsAsset->SkeletalBodySetups[SelectedBodyIndex]->BoneName; if(SelectedBoneName == BoneName) { BoneNameColor = FColor::Green; break; } } if (Canvas.IsHitTesting()) { Canvas.SetHitProxy(new HPhATEdBoneNameProxy(i)); } TextItem.Text = FText::FromString(BoneName.ToString()); TextItem.SetColor(BoneNameColor); Canvas.DrawItem( TextItem, XPos, YPos ); if (Canvas.IsHitTesting()) { Canvas.SetHitProxy(NULL); } } } } // If showing center-of-mass, and physics is started up.. if (SharedData->bShowCOM) { // iterate over each bone for (int32 i = 0; i <SharedData->EditorSkelComp->Bodies.Num(); ++i) { FBodyInstance* BodyInst = SharedData->EditorSkelComp->Bodies[i]; check(BodyInst); FVector BodyCOMPos = BodyInst->GetCOMPosition(); float BodyMass = BodyInst->GetBodyMass(); FPlane Projection = View.Project(BodyCOMPos); if (Projection.W > 0.f) // This avoids drawing bone names that are behind us. { int32 XPos = HalfX + (HalfX * Projection.X); int32 YPos = HalfY + (HalfY * (Projection.Y * -1)); FString COMString = FString::Printf(TEXT("%3.3f"), BodyMass); TextItem.Text = FText::FromString(COMString); TextItem.SetColor(SharedData->COMRenderColor); Canvas.DrawItem( TextItem, XPos, YPos ); } } } }
/* FillTree copies all treenodes of the ttree to base+buf in a relocatable * manner. Look at ExpandTinnedTree() or regina_t.h for a description. * Each treenode is copied to the table and the containing strings are copied * as extstrings to base+start which is incremented. * The table must be large enough. * The index just beyond the last copied character is returned. */ static unsigned long FillTree(treenode *table, char *base, unsigned long start, const ttree *ttp) { cnodeptr np; unsigned long i,j; extstring *e; while (ttp) { for (i = 0;i < ttp->num;i++) { np = (cnodeptr) (ttp->elems + i); *table = *np; /* Full copy includes unnecessary stuff but is fast */ if (np->name) { table->name = (streng *) start; e = (extstring *) (base + start); e->length = np->name->len; memcpy(e + 1 /* just beyond the head */, np->name->value, e->length); start += StringSize(np->name); } /* * Remove all "flags" from the target and copy only approved values * the parser computes already. */ memset( &table->u, 0, sizeof( table->u ) ); /* * See also several places in this file and in debug.c where this * switch list must be changed. Seek for X_CEXPRLIST. */ switch ( np->type ) { case X_EQUAL: case X_DIFF: case X_GT: case X_GTE: case X_LT: case X_LTE: table->u.flags = np->u.flags; break; case X_PARSE: /* * fixes 972850 */ table->u.parseflags = np->u.parseflags; break; case X_ADDR_V: table->u.nonansi = np->u.nonansi; break; case X_CEXPRLIST: if ( np->u.strng ) { table->u.strng = (streng *) start; e = (extstring *) (base + start); e->length = np->u.strng->len; memcpy(e + 1, np->u.strng->value, e->length); start += StringSize(np->u.strng); } break; case X_LABEL: table->u.trace_only = np->u.trace_only; break; case X_ADDR_WITH: if ( !np->p[0] && !np->p[1] && !np->p[2] ) table->u.of = np->u.of; break; default: break; } if (table->next == NULL) table->next = (nodeptr) (unsigned long) -1; else table->next = (nodeptr) np->next->nodeindex; for (j = 0;j < sizeof(np->p) / sizeof(np->p[0]);j++) { if (table->p[j] == NULL) table->p[j] = (nodeptr) (unsigned long) -1; else table->p[j] = (nodeptr) np->p[j]->nodeindex; } table++; } ttp = ttp->next; } return(start); }
void FVisualLoggerCanvasRenderer::DrawHistogramGraphs(class UCanvas* Canvas, class APlayerController*) { if (FLogVisualizer::Get().GetTimeSliderController().IsValid() == false) { return; } const float GoldenRatioConjugate = 0.618033988749895f; if (CollectedGraphs.Num() > 0) { const FVisualLoggerTimeSliderArgs& TimeSliderArgs = FLogVisualizer::Get().GetTimeSliderController()->GetTimeSliderArgs(); TRange<float> LocalViewRange = TimeSliderArgs.ViewRange.Get(); const float LocalViewRangeMin = LocalViewRange.GetLowerBoundValue(); const float LocalViewRangeMax = LocalViewRange.GetUpperBoundValue(); const float LocalSequenceLength = LocalViewRangeMax - LocalViewRangeMin; const float WindowHalfWidth = LocalSequenceLength * TimeSliderArgs.CursorSize.Get() * 0.5f; const FVector2D TimeStampWindow(SelectedEntry.TimeStamp - WindowHalfWidth, SelectedEntry.TimeStamp + WindowHalfWidth); const FColor GraphsBackgroundColor = ULogVisualizerSettings::StaticClass()->GetDefaultObject<ULogVisualizerSettings>()->GraphsBackgroundColor; const int NumberOfGraphs = CollectedGraphs.Num(); const int32 NumberOfColumns = FMath::CeilToInt(FMath::Sqrt(NumberOfGraphs)); int32 NumberOfRows = FMath::FloorToInt(NumberOfGraphs / NumberOfColumns); if (NumberOfGraphs - NumberOfRows * NumberOfColumns > 0) { NumberOfRows += 1; } const int32 MaxNumberOfGraphs = FMath::Max(NumberOfRows, NumberOfColumns); const float GraphWidth = 0.8f / NumberOfColumns; const float GraphHeight = 0.8f / NumberOfRows; const float XGraphSpacing = 0.2f / (MaxNumberOfGraphs + 1); const float YGraphSpacing = 0.2f / (MaxNumberOfGraphs + 1); const float StartX = XGraphSpacing; float StartY = 0.5 + (0.5 * NumberOfRows - 1) * (GraphHeight + YGraphSpacing); float CurrentX = StartX; float CurrentY = StartY; int32 GraphIndex = 0; int32 CurrentColumn = 0; int32 CurrentRow = 0; bool bDrawExtremesOnGraphs = ULogVisualizerSettings::StaticClass()->GetDefaultObject<ULogVisualizerSettings>()->bDrawExtremesOnGraphs; for (auto It(CollectedGraphs.CreateIterator()); It; ++It) { TWeakObjectPtr<UReporterGraph> HistogramGraph = Canvas->GetReporterGraph(); if (!HistogramGraph.IsValid()) { break; } HistogramGraph->SetNumGraphLines(It->Value.GraphLines.Num()); int32 LineIndex = 0; UFont* Font = GEngine->GetSmallFont(); int32 MaxStringSize = 0; float Hue = 0; auto& CategoriesForGraph = UsedGraphCategories.FindOrAdd(It->Key.ToString()); It->Value.GraphLines.KeySort(TLess<FName>()); for (auto LinesIt(It->Value.GraphLines.CreateConstIterator()); LinesIt; ++LinesIt) { const FString DataName = LinesIt->Value.DataName.ToString(); int32 CategoryIndex = CategoriesForGraph.Find(DataName); if (CategoryIndex == INDEX_NONE) { CategoryIndex = CategoriesForGraph.AddUnique(DataName); } Hue = CategoryIndex * GoldenRatioConjugate; if (Hue > 1) { Hue -= FMath::FloorToFloat(Hue); } HistogramGraph->GetGraphLine(LineIndex)->Color = FLinearColor::FGetHSV(Hue * 255, 0, 244); HistogramGraph->GetGraphLine(LineIndex)->LineName = DataName; HistogramGraph->GetGraphLine(LineIndex)->Data.Append(LinesIt->Value.Samples); HistogramGraph->GetGraphLine(LineIndex)->LeftExtreme = LinesIt->Value.LeftExtreme; HistogramGraph->GetGraphLine(LineIndex)->RightExtreme = LinesIt->Value.RightExtreme; int32 DummyY, StringSizeX; StringSize(Font, StringSizeX, DummyY, *LinesIt->Value.DataName.ToString()); MaxStringSize = StringSizeX > MaxStringSize ? StringSizeX : MaxStringSize; ++LineIndex; } FVector2D GraphSpaceSize; GraphSpaceSize.Y = GraphSpaceSize.X = 0.8f / CollectedGraphs.Num(); HistogramGraph->SetGraphScreenSize(CurrentX, CurrentX + GraphWidth, CurrentY, CurrentY + GraphHeight); CurrentX += GraphWidth + XGraphSpacing; HistogramGraph->SetAxesMinMax(FVector2D(TimeStampWindow.X, It->Value.Min.Y), FVector2D(TimeStampWindow.Y, It->Value.Max.Y)); HistogramGraph->DrawCursorOnGraph(true); HistogramGraph->UseTinyFont(CollectedGraphs.Num() >= 5); HistogramGraph->SetCursorLocation(SelectedEntry.TimeStamp); HistogramGraph->SetNumThresholds(0); HistogramGraph->SetStyles(EGraphAxisStyle::Grid, EGraphDataStyle::Lines); HistogramGraph->SetBackgroundColor(GraphsBackgroundColor); HistogramGraph->SetLegendPosition(/*bShowHistogramLabelsOutside*/ false ? ELegendPosition::Outside : ELegendPosition::Inside); HistogramGraph->OffsetDataSets(/*bOffsetDataSet*/false); HistogramGraph->DrawExtremesOnGraph(bDrawExtremesOnGraphs); HistogramGraph->bVisible = true; HistogramGraph->Draw(Canvas); ++GraphIndex; if (++CurrentColumn >= NumberOfColumns) { CurrentColumn = 0; CurrentRow++; CurrentX = StartX; CurrentY -= GraphHeight + YGraphSpacing; } } } }