| 327 | } |
| 328 | |
| 329 | void PreviewEditorWindow::updateUsingEditor(Editor* editor) |
| 330 | { |
| 331 | if (!m_isEnabled || !editor) { |
| 332 | hideWindow(); |
| 333 | m_relatedEditor = nullptr; |
| 334 | return; |
| 335 | } |
| 336 | |
| 337 | if (!editor->isActive()) |
| 338 | return; |
| 339 | |
| 340 | m_relatedEditor = editor; |
| 341 | |
| 342 | Document* document = editor->document(); |
| 343 | Editor* miniEditor = (m_docView ? m_docView->editor(): nullptr); |
| 344 | |
| 345 | if (!isVisible()) |
| 346 | openWindow(); |
| 347 | |
| 348 | // Document preferences used to store the preferred zoom/scroll point |
| 349 | auto& docPref = Preferences::instance().document(document); |
| 350 | bool autoScroll = docPref.preview.autoScroll(); |
| 351 | |
| 352 | // Set the same location as in the given editor. |
| 353 | if (!miniEditor || miniEditor->document() != document) { |
| 354 | destroyDocView(); |
| 355 | |
| 356 | m_docView = new DocumentView(document, DocumentView::Preview, this); |
| 357 | addChild(m_docView); |
| 358 | |
| 359 | miniEditor = m_docView->editor(); |
| 360 | miniEditor->setZoom(render::Zoom::fromScale(docPref.preview.zoom())); |
| 361 | miniEditor->setLayer(editor->layer()); |
| 362 | miniEditor->setFrame(editor->frame()); |
| 363 | miniEditor->setState(EditorStatePtr(new NavigateState)); |
| 364 | miniEditor->setAnimationSpeedMultiplier(m_aniSpeed); |
| 365 | miniEditor->addObserver(this); |
| 366 | layout(); |
| 367 | |
| 368 | if (!autoScroll) |
| 369 | miniEditor->setEditorScroll(docPref.preview.scroll()); |
| 370 | } |
| 371 | |
| 372 | m_centerButton->setSelected(autoScroll); |
| 373 | if (autoScroll) { |
| 374 | gfx::Point centerPoint = editor->getVisibleSpriteBounds().center(); |
| 375 | miniEditor->centerInSpritePoint(centerPoint); |
| 376 | |
| 377 | saveScrollPref(); |
| 378 | } |
| 379 | |
| 380 | if (!m_playButton->isPlaying()) { |
| 381 | miniEditor->stop(); |
| 382 | miniEditor->setLayer(editor->layer()); |
| 383 | miniEditor->setFrame(editor->frame()); |
| 384 | } |
| 385 | else { |
| 386 | if (miniEditor->isPlaying()) { |
nothing calls this directly
no test coverage detected