615 * Links this native object with its java Win32GraphicsDevice. 616 * Need this link because the colorModel of the java device 617 * may be updated from native code. 618 */ 619 void AwtWin32GraphicsDevice::SetJavaDevice(JNIEnv *env, jobject objPtr) 620 { 621 javaDevice = env->NewWeakGlobalRef(objPtr); 622 } 623 624 /** 625 * Sets horizontal and vertical scale factors 626 */ 627 void AwtWin32GraphicsDevice::SetScale(float sx, float sy) 628 { 629 scaleX = sx; 630 scaleY = sy; 631 } 632 633 int AwtWin32GraphicsDevice::ScaleUpX(int x) 634 { 635 return CheckIntLimits(x * scaleX); 636 } 637 638 int AwtWin32GraphicsDevice::ScaleUpY(int y) 639 { 640 return CheckIntLimits(y * scaleY); 641 } 642 643 int AwtWin32GraphicsDevice::ScaleDownX(int x) 644 { 645 return CheckIntLimits(x / scaleX); 646 } 647 648 int AwtWin32GraphicsDevice::ScaleDownY(int y) 649 { 650 return CheckIntLimits(y / scaleY); 651 } 652 653 int AwtWin32GraphicsDevice::CheckIntLimits(double value) 654 { 655 if (value < INT_MIN) 656 { 657 return INT_MIN; 658 } 659 660 if (value > INT_MAX) 661 { 662 return INT_MAX; 663 } 664 665 return (int)ceil(value); 666 } 667 668 void AwtWin32GraphicsDevice::InitDesktopScales() 669 { 670 float dpiX = -1.0f; 671 float dpiY = -1.0f; 672 GetScreenDpi(GetMonitor(), &dpiX, &dpiY); 673 if (dpiX > 0 && dpiY > 0) { 674 SetScale(dpiX / 96, dpiY / 96); | 615 * Links this native object with its java Win32GraphicsDevice. 616 * Need this link because the colorModel of the java device 617 * may be updated from native code. 618 */ 619 void AwtWin32GraphicsDevice::SetJavaDevice(JNIEnv *env, jobject objPtr) 620 { 621 javaDevice = env->NewWeakGlobalRef(objPtr); 622 } 623 624 /** 625 * Sets horizontal and vertical scale factors 626 */ 627 void AwtWin32GraphicsDevice::SetScale(float sx, float sy) 628 { 629 scaleX = sx; 630 scaleY = sy; 631 } 632 633 int AwtWin32GraphicsDevice::ScaleUpX(int x) 634 { 635 return ClipRound(x * scaleX); 636 } 637 638 int AwtWin32GraphicsDevice::ScaleUpY(int y) 639 { 640 return ClipRound(y * scaleY); 641 } 642 643 int AwtWin32GraphicsDevice::ScaleDownX(int x) 644 { 645 return ClipRound(x / scaleX); 646 } 647 648 int AwtWin32GraphicsDevice::ScaleDownY(int y) 649 { 650 return ClipRound(y / scaleY); 651 } 652 653 int AwtWin32GraphicsDevice::ClipRound(double value) 654 { 655 value -= 0.5; 656 if (value < INT_MIN) 657 { 658 return INT_MIN; 659 } 660 661 if (value > INT_MAX) 662 { 663 return INT_MAX; 664 } 665 666 return (int)ceil(value); 667 } 668 669 void AwtWin32GraphicsDevice::InitDesktopScales() 670 { 671 float dpiX = -1.0f; 672 float dpiY = -1.0f; 673 GetScreenDpi(GetMonitor(), &dpiX, &dpiY); 674 if (dpiX > 0 && dpiY > 0) { 675 SetScale(dpiX / 96, dpiY / 96); |