@@ -176,7 +176,7 @@ public Grid ContentControl
176176 #region Window position and size
177177
178178 private const double OuterBorderWidth = 1.0 ;
179-
179+
180180 public const double HeaderHeight = 24.0 ;
181181
182182 private double windowWidth = 400.0 + 2 * OuterBorderWidth ;
@@ -309,7 +309,7 @@ public string CaptionText
309309 {
310310 get
311311 {
312- return String . Format ( CultureInfo . InvariantCulture ,
312+ return String . Format ( CultureInfo . CurrentCulture ,
313313 "{0}\u00D7 {1}{2}" ,
314314 ImageSize . Item1 ,
315315 ImageSize . Item2 ,
@@ -320,31 +320,61 @@ public string CaptionText
320320 public void SnapToImageBounds ( )
321321 {
322322 // select foreground window from several processes of supported applications
323- var nativeWindow = Models . AppsInterop . NativeWindow . GetTopMostWindow ( ) ;
323+ var nativeWindows = Models . AppsInterop . NativeWindow . GetWindowsInTopMostOrder ( ) ;
324324
325- if ( nativeWindow != null ) // TODO: display error if no window was found
325+ if ( nativeWindows . Count > 0 ) // TODO: display error if no window was found
326326 {
327- if ( nativeWindow . ClassName == Models . AppsInterop . PhotoViewerWindow . MainWindowClassName )
327+ if ( String . Compare ( nativeWindows [ 0 ] . ClassName , Models . AppsInterop . PhotoViewerWindow . MainWindowClassName , StringComparison . Ordinal ) == 0 )
328328 {
329- var photoViewerWindow = new Models . AppsInterop . PhotoViewerWindow ( nativeWindow . Handle ) ;
329+ var photoViewerWindow = new Models . AppsInterop . PhotoViewerWindow ( nativeWindows [ 0 ] . Handle ) ;
330330
331331 var rectViewedImage = photoViewerWindow . PhotoCanvasRect ( ) ;
332332 if ( ! rectViewedImage . IsEmpty )
333333 {
334- this . PositionWindow ( Models . Geometry . Point . Zero , rectViewedImage ) ;
334+ var location = new GridTargetLocation { ImageBounds = rectViewedImage , Offset = Models . Geometry . Point . Zero , } ;
335+ this . PositionWindow ( location ) ;
335336 }
336337 }
337338 else
338339 {
339- Task . Factory . StartNew < Tuple < Models . Geometry . Rectangle , Models . Geometry . Point > > ( ( ) =>
340+ var nativeWindow = nativeWindows [ 0 ] ;
341+
342+ // TODO: simplify Octane Render specific code
343+ // Fixing issue with detached panels of Octane Render Standalone
344+ if ( Models . AppsInterop . OctaneRenderWindow . GetFromAllProcesses ( ) . Count > 0 )
345+ {
346+ var octaneRenderWindows = nativeWindows
347+ . Where ( w => w . ClassName == Models . AppsInterop . OctaneRenderWindow . GetFromAllProcesses ( ) [ 0 ] . ClassName )
348+ . OrderByDescending ( w => w . Rect . Width )
349+ . First ( ) ;
350+
351+ // Select window with max size from topmost list
352+ for ( var i = 0 ; i < nativeWindows . Count ; i ++ )
353+ {
354+ if ( nativeWindows [ i ] . ClassName != Models . AppsInterop . OctaneRenderWindow . GetFromAllProcesses ( ) [ 0 ] . ClassName )
355+ {
356+ break ;
357+ }
358+ else
359+ {
360+ if ( nativeWindows [ i ] . Rect . Width == octaneRenderWindows . Rect . Width )
361+ {
362+ nativeWindow = nativeWindows [ i ] ;
363+ break ;
364+ }
365+ }
366+ }
367+ }
368+
369+ var bitmap = nativeWindow . GetShot ( ) ;
370+
371+ Task . Factory . StartNew < GridTargetLocation > ( ( ) =>
340372 {
341- var bitmap = nativeWindow . GetShot ( ) ;
342373 var flatImage = new Models . FlatImage ( bitmap ) ;
343374
344375 Models . Geometry . Rectangle imageBounds ;
345376 if ( Models . AppsInterop . OctaneRenderWindow . GetFromAllProcesses ( ) . Any ( w => w . ClassName == nativeWindow . ClassName ) )
346377 {
347- // TODO: remove this Octane Render specific code
348378 imageBounds = Models . AppsInterop . OctaneRenderWindow . FindRenderedImageBorders ( flatImage ) ;
349379 }
350380 else
@@ -353,16 +383,14 @@ public void SnapToImageBounds()
353383 }
354384
355385 var nativeWindowLocation = new Models . Geometry . Point ( nativeWindow . Location . X , nativeWindow . Location . Y ) ;
356- return new Tuple < Models . Geometry . Rectangle , Models . Geometry . Point > ( imageBounds , nativeWindowLocation ) ;
386+ return new GridTargetLocation { ImageBounds = imageBounds , Offset = nativeWindowLocation , } ;
357387 } ) . ContinueWith ( ( t ) =>
358388 {
359- var imageBounds = t . Result . Item1 ;
360- var windowLocation = t . Result . Item2 ;
361- if ( ! imageBounds . IsEmpty )
389+ if ( ! t . Result . ImageBounds . IsEmpty )
362390 {
363- if ( ( imageBounds . Width > 150 ) && ( imageBounds . Height > 50 ) )
391+ if ( ( t . Result . ImageBounds . Width > 150 ) && ( t . Result . ImageBounds . Height > 50 ) )
364392 {
365- this . PositionWindow ( t . Result . Item2 , t . Result . Item1 ) ;
393+ this . PositionWindow ( t . Result ) ;
366394 }
367395 }
368396 } ,
@@ -371,15 +399,22 @@ public void SnapToImageBounds()
371399 }
372400 }
373401
374- private void PositionWindow ( Models . Geometry . Point parentLocation , Models . Geometry . Rectangle rectRenderedImage )
402+ private void PositionWindow ( GridTargetLocation location )
375403 {
376404 var diffX = 0.0 ;
377405 var diffY = HeaderHeight ;
378406 // TODO: remove magiс numbers
379- this . WindowLeft = rectRenderedImage . Left + parentLocation . X - diffX - 1 ;
380- this . WindowTop = rectRenderedImage . Top + parentLocation . Y - diffY - 1 ;
381- this . WindowWidth = ( rectRenderedImage . Right - rectRenderedImage . Left ) + diffX + 2 ;
382- this . WindowHeight = ( rectRenderedImage . Bottom - rectRenderedImage . Top ) + diffY + 2 ;
407+ this . WindowLeft = location . ImageBounds . Left + location . Offset . X - diffX - 1 ;
408+ this . WindowTop = location . ImageBounds . Top + location . Offset . Y - diffY - 1 ;
409+ this . WindowWidth = ( location . ImageBounds . Right - location . ImageBounds . Left ) + diffX + 2 ;
410+ this . WindowHeight = ( location . ImageBounds . Bottom - location . ImageBounds . Top ) + diffY + 2 ;
383411 }
384412 }
413+
414+ class GridTargetLocation
415+ {
416+ public Models . Geometry . Point Offset { get ; set ; }
417+
418+ public Models . Geometry . Rectangle ImageBounds { get ; set ; }
419+ }
385420}
0 commit comments