260 QuantumToolkit.runWithRenderLock(() -> { 261 // platformWindow can be null here, if this window is owned, 262 // and its owner is being closed. 263 if (platformWindow != null) { 264 platformWindow.setView(null); 265 } 266 if (oldScene != null) { 267 oldScene.updateSceneState(); 268 } 269 return null; 270 }); 271 } 272 if (oldScene != null) { 273 ViewPainter painter = ((ViewScene)oldScene).getPainter(); 274 QuantumRenderer.getInstance().disposePresentable(painter.presentable); // latched on RT 275 } 276 } 277 278 @Override public void setBounds(float x, float y, boolean xSet, boolean ySet, 279 float w, float h, float cw, float ch, 280 float xGravity, float yGravity) 281 { 282 if (isAppletStage) { 283 xSet = ySet = false; 284 } 285 float pScale = platformWindow.getPlatformScale(); 286 int px, py; 287 if (xSet || ySet) { 288 Screen screen = platformWindow.getScreen(); 289 List<Screen> screens = Screen.getScreens(); 290 if (screens.size() > 1) { 291 float wx = xSet ? x : platformWindow.getX(); 292 float wy = ySet ? y : platformWindow.getY(); 293 float relx = screen.getX() + screen.getWidth() / 2.0f - wx; 294 float rely = screen.getY() + screen.getHeight()/ 2.0f - wy; 295 float distsq = relx * relx + rely * rely; 296 for (Screen s : Screen.getScreens()) { 297 relx = s.getX() + s.getWidth() / 2.0f - wx; 298 rely = s.getY() + s.getHeight()/ 2.0f - wy; 299 float distsq2 = relx * relx + rely * rely; 300 if (distsq2 < distsq) { 301 screen = s; 302 distsq = distsq2; 303 } 304 } 305 } 306 float sx = screen == null ? 0 : screen.getX(); 307 float sy = screen == null ? 0 : screen.getY(); 308 px = xSet ? Math.round(sx + (x - sx) * pScale) : 0; 309 py = ySet ? Math.round(sy + (y - sy) * pScale) : 0; 310 } else { 311 px = py = 0; 312 } 313 int pw = (int) (w > 0 ? Math.ceil(w * pScale) : w); 314 int ph = (int) (h > 0 ? Math.ceil(h * pScale) : h); 315 int pcw = (int) (cw > 0 ? Math.ceil(cw * pScale) : cw); 316 int pch = (int) (ch > 0 ? Math.ceil(ch * pScale) : ch); 317 platformWindow.setBounds(px, py, xSet, ySet, 318 pw, ph, pcw, pch, 319 xGravity, yGravity); 320 } 321 322 @Override 323 public float getUIScale() { 324 return platformWindow.getPlatformScale(); 325 } 326 327 @Override 328 public float getRenderScale() { 329 return platformWindow.getRenderScale(); 330 } 331 332 @Override public void setMinimumSize(int minWidth, int minHeight) { 333 float pScale = platformWindow.getPlatformScale(); 334 minWidth = (int) Math.ceil(minWidth * pScale); 335 minHeight = (int) Math.ceil(minHeight * pScale); 336 platformWindow.setMinimumSize(minWidth, minHeight); 337 } 338 339 @Override public void setMaximumSize(int maxWidth, int maxHeight) { 340 float pScale = platformWindow.getPlatformScale(); 341 maxWidth = (int) Math.ceil(maxWidth * pScale); 342 maxHeight = (int) Math.ceil(maxHeight * pScale); 343 platformWindow.setMaximumSize(maxWidth, maxHeight); 344 } 345 346 static Image findBestImage(java.util.List icons, int width, int height) { 347 Image image = null; 348 double bestSimilarity = 3; //Impossibly high value 349 for (Object icon : icons) { 350 //Iterate imageList looking for best matching image. 351 //'Similarity' measure is defined as good scale factor and small insets. 352 //best possible similarity is 0 (no scale, no insets). 353 //It's found by experimentation that good-looking results are achieved 354 //with scale factors x1, x3/4, x2/3, xN, x1/N. 355 //Check to make sure the image/image format is correct. 356 Image im = (Image)icon; 357 if (im == null || !(im.getPixelFormat() == PixelFormat.BYTE_RGB || 358 im.getPixelFormat() == PixelFormat.BYTE_BGRA_PRE || 359 im.getPixelFormat() == PixelFormat.BYTE_GRAY)) 360 { 361 continue; 362 } | 260 QuantumToolkit.runWithRenderLock(() -> { 261 // platformWindow can be null here, if this window is owned, 262 // and its owner is being closed. 263 if (platformWindow != null) { 264 platformWindow.setView(null); 265 } 266 if (oldScene != null) { 267 oldScene.updateSceneState(); 268 } 269 return null; 270 }); 271 } 272 if (oldScene != null) { 273 ViewPainter painter = ((ViewScene)oldScene).getPainter(); 274 QuantumRenderer.getInstance().disposePresentable(painter.presentable); // latched on RT 275 } 276 } 277 278 @Override public void setBounds(float x, float y, boolean xSet, boolean ySet, 279 float w, float h, float cw, float ch, 280 float xGravity, float yGravity, 281 float renderScaleX, float renderScaleY) 282 { 283 if (renderScaleX > 0.0 || renderScaleY > 0.0) { 284 // We set the render scale first since the call to setBounds() 285 // below can induce a recursive update on the scales if it moves 286 // the window to a new screen and we will then end up being called 287 // back with a new scale. We do not want to set these old scale 288 // values after that recursion happens. 289 if (renderScaleX > 0.0) { 290 platformWindow.setRenderScaleX(renderScaleX); 291 } 292 if (renderScaleY > 0.0) { 293 platformWindow.setRenderScaleY(renderScaleY); 294 } 295 ViewScene vscene = getViewScene(); 296 if (vscene != null) { 297 vscene.updateSceneState(); 298 vscene.entireSceneNeedsRepaint(); 299 } 300 } 301 if (isAppletStage) { 302 xSet = ySet = false; 303 } 304 float pScaleX = platformWindow.getPlatformScaleX(); 305 float pScaleY = platformWindow.getPlatformScaleY(); 306 int px, py; 307 if (xSet || ySet) { 308 Screen screen = platformWindow.getScreen(); 309 List<Screen> screens = Screen.getScreens(); 310 if (screens.size() > 1) { 311 float winfxW = (w > 0) ? w : (platformWindow.getWidth() / pScaleX); 312 float winfxH = (h > 0) ? h : (platformWindow.getHeight()/ pScaleY); 313 float winfxX = xSet ? x : 314 screen.getX() + (platformWindow.getX() - screen.getPlatformX()) / pScaleX; 315 float winfxY = ySet ? y : 316 screen.getY() + (platformWindow.getY() - screen.getPlatformY()) / pScaleY; 317 float winfxCX = winfxX + winfxW/2f; 318 float winfxCY = winfxY + winfxH/2f; 319 // If the center point of the window (winfxCX,Y) is on any 320 // screen, then use that screen. Otherwise, use the screen 321 // whose center is closest to the window center. 322 int scrX = screen.getX(); 323 int scrY = screen.getY(); 324 int scrW = screen.getWidth(); 325 int scrH = screen.getHeight(); 326 if (winfxCX < scrX || 327 winfxCY < scrY || 328 winfxCX >= scrX + scrW || 329 winfxCY >= scrY + scrH) 330 { 331 float relx = scrX + scrW / 2.0f - winfxCX; 332 float rely = scrY + scrH / 2.0f - winfxCY; 333 float distsq = relx * relx + rely * rely; 334 for (Screen s : Screen.getScreens()) { 335 scrX = s.getX(); 336 scrY = s.getY(); 337 scrW = s.getWidth(); 338 scrH = s.getHeight(); 339 if (winfxCX >= scrX && 340 winfxCY >= scrY && 341 winfxCX < scrX + scrW && 342 winfxCY < scrY + scrH) 343 { 344 screen = s; 345 break; 346 } 347 relx = scrX + scrW / 2.0f - winfxCX; 348 rely = scrY + scrH / 2.0f - winfxCY; 349 float distsq2 = relx * relx + rely * rely; 350 if (distsq2 < distsq) { 351 screen = s; 352 distsq = distsq2; 353 } 354 } 355 } 356 } 357 float sx = screen == null ? 0 : screen.getX(); 358 float sy = screen == null ? 0 : screen.getY(); 359 float sScaleX = screen.getPlatformScaleX(); 360 float sScaleY = screen.getPlatformScaleY(); 361 px = xSet ? Math.round(screen.getPlatformX() + (x - sx) * sScaleX) : 0; 362 py = ySet ? Math.round(screen.getPlatformY() + (y - sy) * sScaleY) : 0; 363 } else { 364 px = py = 0; 365 } 366 int pw = (int) (w > 0 ? Math.ceil(w * pScaleX) : w); 367 int ph = (int) (h > 0 ? Math.ceil(h * pScaleY) : h); 368 int pcw = (int) (cw > 0 ? Math.ceil(cw * pScaleX) : cw); 369 int pch = (int) (ch > 0 ? Math.ceil(ch * pScaleY) : ch); 370 platformWindow.setBounds(px, py, xSet, ySet, 371 pw, ph, pcw, pch, 372 xGravity, yGravity); 373 } 374 375 @Override 376 public float getPlatformScaleX() { 377 return platformWindow.getPlatformScaleX(); 378 } 379 380 @Override 381 public float getPlatformScaleY() { 382 return platformWindow.getPlatformScaleY(); 383 } 384 385 @Override 386 public float getOutputScaleX() { 387 return platformWindow.getOutputScaleX(); 388 } 389 390 @Override 391 public float getOutputScaleY() { 392 return platformWindow.getOutputScaleY(); 393 } 394 395 @Override public void setMinimumSize(int minWidth, int minHeight) { 396 minWidth = (int) Math.ceil(minWidth * getPlatformScaleX()); 397 minHeight = (int) Math.ceil(minHeight * getPlatformScaleY()); 398 platformWindow.setMinimumSize(minWidth, minHeight); 399 } 400 401 @Override public void setMaximumSize(int maxWidth, int maxHeight) { 402 maxWidth = (int) Math.ceil(maxWidth * getPlatformScaleX()); 403 maxHeight = (int) Math.ceil(maxHeight * getPlatformScaleY()); 404 platformWindow.setMaximumSize(maxWidth, maxHeight); 405 } 406 407 static Image findBestImage(java.util.List icons, int width, int height) { 408 Image image = null; 409 double bestSimilarity = 3; //Impossibly high value 410 for (Object icon : icons) { 411 //Iterate imageList looking for best matching image. 412 //'Similarity' measure is defined as good scale factor and small insets. 413 //best possible similarity is 0 (no scale, no insets). 414 //It's found by experimentation that good-looking results are achieved 415 //with scale factors x1, x3/4, x2/3, xN, x1/N. 416 //Check to make sure the image/image format is correct. 417 Image im = (Image)icon; 418 if (im == null || !(im.getPixelFormat() == PixelFormat.BYTE_RGB || 419 im.getPixelFormat() == PixelFormat.BYTE_BGRA_PRE || 420 im.getPixelFormat() == PixelFormat.BYTE_GRAY)) 421 { 422 continue; 423 } |