//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// LNK-CONVERTER UTILITY NATIVE SUPPORT (IMPLEMENTATION PART):
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// NativeLib DLL (for DotNetHelpers) | C+- (SysRoutine) | Author: Sergei Y.Kitáev
#include "Precompiled.h"
#include "SharedIncludes.h"
#include "partition\LnkConverter.h"
//==================================================================================================

bool LnkConverter::ReleaseScreenDC( HDC& hDC ) $last_error
{
   return !hDC || ::ReleaseDC( nullptr, $subst::NullExchange( hDC ) ) ?
      true : $LE::SetWin32FuncFailure($, L"ReleaseDC" );
}

bool LnkConverter::RefreshScreen( bool& refreshAttempt ) $last_error
{
   if ( refreshAttempt )
      return true;
   refreshAttempt = true;
   return ::InvalidateRect( nullptr, nullptr, TRUE ) ?
      true : $SET_FROM_SYSTEM_LE();
}

//--------------------------------------------------------------------------------------------------

bool LnkConverter::PerformDrawing( HDC hDC, int width, int height ) $last_error
{
   auto hBrushObj = (HBRUSH)::GetStockObject( WHITE_BRUSH );
   if ( !hBrushObj )
      return $SET_FROM_SYSTEM_LE();
   const int thickness = 4;
   int count = width / thickness;
   int fib1 = 1, fib2 = 2, fib3 = 3;
   while ( fib3 < count )
   {
      fib1 = fib2; fib2 = fib3; fib3 = fib1 + fib2;
   }
   int idx = 0;
   for (int i=1; i<=fib3; i++)
   {
      if ( idx < count )
      {
         int x = idx * thickness;
         RECT rc = { x, 0, x + thickness, width }; // LTRB
         if ( !::FillRect( hDC, &rc, hBrushObj ) )
            return $SET_FROM_SYSTEM_LE();
      }
      idx = ( idx + fib1 ) % fib3;
      ::Sleep( 5 );
   }
   return true;
}

//==================================================================================================
