Example #1
0
void
nsWindow::DoDraw(void)
{
    if (!hal::GetScreenEnabled()) {
        gDrawRequest = true;
        return;
    }

    if (sTopWindows.IsEmpty()) {
        LOG("  no window to draw, bailing");
        return;
    }

    nsWindow *targetWindow = (nsWindow *)sTopWindows[0];
    while (targetWindow->GetLastChild())
        targetWindow = (nsWindow *)targetWindow->GetLastChild();

    nsIWidgetListener* listener = targetWindow->GetWidgetListener();
    if (listener) {
        listener->WillPaintWindow(targetWindow);
    }

    LayerManager* lm = targetWindow->GetLayerManager();
    if (mozilla::layers::LayersBackend::LAYERS_CLIENT == lm->GetBackendType()) {
      // No need to do anything, the compositor will handle drawing
    } else {
        NS_RUNTIMEABORT("Unexpected layer manager type");
    }

    listener = targetWindow->GetWidgetListener();
    if (listener) {
        listener->DidPaintWindow();
    }
}
void nsBaseWidget::CreateCompositor()
{
  mCompositorThread = new Thread("CompositorThread");
  mCompositorParent = new CompositorParent(this, mCompositorThread);
  if (mCompositorThread->Start()) {
    LayerManager* lm = CreateBasicLayerManager();
    MessageLoop *childMessageLoop = mCompositorThread->message_loop();
    mCompositorChild = new CompositorChild(lm);
    AsyncChannel *parentChannel = mCompositorParent->GetIPCChannel();
    AsyncChannel::Side childSide = mozilla::ipc::AsyncChannel::Child;
    mCompositorChild->Open(parentChannel, childMessageLoop, childSide);
    PLayersChild* shadowManager =
      mCompositorChild->SendPLayersConstructor(LayerManager::LAYERS_OPENGL);

    if (shadowManager) {
      ShadowLayerForwarder* lf = lm->AsShadowForwarder();
      if (!lf) {
        delete lm;
        mCompositorChild = nsnull;
        return;
      }
      lf->SetShadowManager(shadowManager);
      lf->SetParentBackendType(LayerManager::LAYERS_OPENGL);

      mLayerManager = lm;
    } else {
      NS_WARNING("fail to construct LayersChild");
      delete lm;
      mCompositorChild = nsnull;
    }
  }
}
void
nsWindow::DoDraw(void)
{
    if (!hal::GetScreenEnabled()) {
        gDrawRequest = true;
        return;
    }

    if (!gWindowToRedraw) {
        LOG("  no window to draw, bailing");
        return;
    }

    StopBootAnimation();

    nsIntRegion region = gWindowToRedraw->mDirtyRegion;
    gWindowToRedraw->mDirtyRegion.SetEmpty();

    LayerManager* lm = gWindowToRedraw->GetLayerManager();
    if (mozilla::layers::LAYERS_OPENGL == lm->GetBackendType()) {
        LayerManagerOGL* oglm = static_cast<LayerManagerOGL*>(lm);
        oglm->SetClippingRegion(region);
        oglm->SetWorldTransform(sRotationMatrix);

        if (nsIWidgetListener* listener = gWindowToRedraw->GetWidgetListener())
          listener->PaintWindow(gWindowToRedraw, region, 0);
    } else if (mozilla::layers::LAYERS_BASIC == lm->GetBackendType()) {
        MOZ_ASSERT(sFramebufferOpen || sUsingOMTC);
        nsRefPtr<gfxASurface> targetSurface;

        if(sUsingOMTC)
            targetSurface = sOMTCSurface;
        else
            targetSurface = Framebuffer::BackBuffer();

        {
            nsRefPtr<gfxContext> ctx = new gfxContext(targetSurface);
            gfxUtils::PathFromRegion(ctx, region);
            ctx->Clip();

            // No double-buffering needed.
            AutoLayerManagerSetup setupLayerManager(
                gWindowToRedraw, ctx, mozilla::layers::BUFFER_NONE,
                ScreenRotation(EffectiveScreenRotation()));

            if (nsIWidgetListener* listener = gWindowToRedraw->GetWidgetListener())
              listener->PaintWindow(gWindowToRedraw, region, 0);
        }

        if (!sUsingOMTC) {
            targetSurface->Flush();
            Framebuffer::Present(region);
        }
    } else {
        NS_RUNTIMEABORT("Unexpected layer manager type");
    }
}
Example #4
0
void LayerTableView::selectionChangedSlot(const QItemSelection&, const QItemSelection&)
{
	QModelIndexList indexes = this->selectionModel()->selection().indexes();
	
	if (indexes.count() == 1)
	{
		LayerManager* pManager = LayerManager::getInstance();
		pManager->selectLayer(indexes.at(0).row());
	}

}
Example #5
0
void
nsWindow::DoDraw(void)
{
    if (!hal::GetScreenEnabled()) {
        gDrawRequest = true;
        return;
    }

    if (!gWindowToRedraw) {
        LOG("  no window to draw, bailing");
        return;
    }

    nsPaintEvent event(true, NS_PAINT, gWindowToRedraw);
    event.region = gWindowToRedraw->mDirtyRegion;
    gWindowToRedraw->mDirtyRegion.SetEmpty();

    LayerManager* lm = gWindowToRedraw->GetLayerManager();
    if (LayerManager::LAYERS_OPENGL == lm->GetBackendType()) {
        LayerManagerOGL* oglm = static_cast<LayerManagerOGL*>(lm);
        oglm->SetClippingRegion(event.region);
        oglm->SetWorldTransform(sRotationMatrix);
        gWindowToRedraw->mEventCallback(&event);
    } else if (LayerManager::LAYERS_BASIC == lm->GetBackendType()) {
        MOZ_ASSERT(sFramebufferOpen || sUsingOMTC);
        nsRefPtr<gfxASurface> targetSurface;

        if(sUsingOMTC)
            targetSurface = sOMTCSurface;
        else
            targetSurface = Framebuffer::BackBuffer();

        {
            nsRefPtr<gfxContext> ctx = new gfxContext(targetSurface);
            gfxUtils::PathFromRegion(ctx, event.region);
            ctx->Clip();

            // No double-buffering needed.
            AutoLayerManagerSetup setupLayerManager(
                gWindowToRedraw, ctx, BasicLayerManager::BUFFER_NONE);
            gWindowToRedraw->mEventCallback(&event);
        }

        if (!sUsingOMTC) {
            targetSurface->Flush();
            Framebuffer::Present(event.region);
        }
    } else {
        NS_RUNTIMEABORT("Unexpected layer manager type");
    }
}
Example #6
0
void nsBaseWidget::CreateCompositor()
{
  mCompositorThread = new Thread("CompositorThread");
  if (mCompositorThread->Start()) {
    bool renderToEGLSurface = false;
#ifdef MOZ_JAVA_COMPOSITOR
    renderToEGLSurface = true;
#endif
    nsIntRect rect;
    GetBounds(rect);
    mCompositorParent =
      new CompositorParent(this, mCompositorThread->message_loop(), mCompositorThread->thread_id(),
                           renderToEGLSurface, rect.width, rect.height);
    LayerManager* lm = CreateBasicLayerManager();
    MessageLoop *childMessageLoop = mCompositorThread->message_loop();
    mCompositorChild = new CompositorChild(lm);
    AsyncChannel *parentChannel = mCompositorParent->GetIPCChannel();
    AsyncChannel::Side childSide = mozilla::ipc::AsyncChannel::Child;
    mCompositorChild->Open(parentChannel, childMessageLoop, childSide);
    PRInt32 maxTextureSize;
    PLayersChild* shadowManager;
    if (mUseAcceleratedRendering) {
      shadowManager = mCompositorChild->SendPLayersConstructor(LayerManager::LAYERS_OPENGL, &maxTextureSize);
    } else {
      shadowManager = mCompositorChild->SendPLayersConstructor(LayerManager::LAYERS_BASIC, &maxTextureSize);
    }

    if (shadowManager) {
      ShadowLayerForwarder* lf = lm->AsShadowForwarder();
      if (!lf) {
        delete lm;
        mCompositorChild = nsnull;
        return;
      }
      lf->SetShadowManager(shadowManager);
      if (mUseAcceleratedRendering)
        lf->SetParentBackendType(LayerManager::LAYERS_OPENGL);
      else
        lf->SetParentBackendType(LayerManager::LAYERS_BASIC);
      lf->SetMaxTextureSize(maxTextureSize);

      mLayerManager = lm;
    } else {
      // We don't currently want to support not having a LayersChild
      NS_RUNTIMEABORT("failed to construct LayersChild");
      delete lm;
      mCompositorChild = nsnull;
    }
  }
}
//--------------------------------------------------------------------------
/// Check if the newly-started frame should be automatically traced at a specific frame.
/// \returns An eTraceType value, corresponding to the value set in the server config.
//--------------------------------------------------------------------------
int MultithreadedTraceAnalyzerLayer::GetTraceTypeFlags()
{
    int traceTypeFlags = kTraceType_None;

    // It's time to capture a frame. Check the trace type that was requested.
    InterceptorBase* interceptor = GetInterceptor();
    LayerManager* thisLayerManager = interceptor->GetParentLayerManager();

    if (thisLayerManager->IsAutocaptureFrame())
    {
        traceTypeFlags = SG_GET_INT(OptionTraceType);
    }

    return traceTypeFlags;
}
PLayersParent*
RenderFrameParent::AllocPLayers(LayerManager::LayersBackend* aBackendType)
{
  if (!mFrameLoader || mFrameLoaderDestroyed) {
    *aBackendType = LayerManager::LAYERS_NONE;
    return nsnull;
  }
  LayerManager* lm = GetLayerManager();
  ShadowLayerManager* slm = lm->AsShadowManager();
  if (!slm) {
    *aBackendType = LayerManager::LAYERS_NONE;
     return nsnull;
  }
  *aBackendType = lm->GetBackendType();
  return new ShadowLayersParent(slm, this);
}
static void
SendLayersDependentApzcTargetConfirmation(nsIPresShell* aShell, uint64_t aInputBlockId,
                                          const nsTArray<ScrollableLayerGuid>& aTargets)
{
  LayerManager* lm = aShell->GetLayerManager();
  if (!lm) {
    return;
  }

  LayerTransactionChild* shadow = lm->AsShadowForwarder()->GetShadowManager();
  if (!shadow) {
    return;
  }

  shadow->SendSetConfirmedTargetAPZC(aInputBlockId, aTargets);
}
	void Cocos2dRenderManager::releaseAllVertexBuffer()
	{
		LayerManager* layers = LayerManager::getInstancePtr();
		if (layers != nullptr)
		{
			LayerManager::EnumeratorLayer layer = layers->getEnumerator();
			while (layer.next())
			{
				EnumeratorILayerNode layerNode = layer->getEnumerator();
				while (layerNode.next())
				{
					layerNode->releaseVertexBuffer();
				}
			}
		}
	}
Example #11
0
bool
TabChild::InitWidget(const nsIntSize& size)
{
    NS_ABORT_IF_FALSE(!mWidget && !mRemoteFrame, "CreateWidget twice?");

    mWidget = nsIWidget::CreatePuppetWidget(this);
    if (!mWidget) {
        NS_ERROR("couldn't create fake widget");
        return false;
    }
    mWidget->Create(
        nsnull, 0,              // no parents
        nsIntRect(nsIntPoint(0, 0), size),
        nsnull,                 // HandleWidgetEvent
        nsnull                  // nsIDeviceContext
        );

    RenderFrameChild* remoteFrame =
        static_cast<RenderFrameChild*>(SendPRenderFrameConstructor());
    if (!remoteFrame) {
      NS_WARNING("failed to construct RenderFrame");
      return false;
    }

    NS_ABORT_IF_FALSE(0 == remoteFrame->ManagedPLayersChild().Length(),
                      "shouldn't have a shadow manager yet");
    PLayersChild* shadowManager = remoteFrame->SendPLayersConstructor();
    if (!shadowManager) {
      NS_WARNING("failed to construct LayersChild");
      // This results in |remoteFrame| being deleted.
      PRenderFrameChild::Send__delete__(remoteFrame);
      return false;
    }

    LayerManager* lm = mWidget->GetLayerManager();
    NS_ABORT_IF_FALSE(LayerManager::LAYERS_BASIC == lm->GetBackendType(),
                      "content processes should only be using BasicLayers");

    BasicShadowLayerManager* bslm = static_cast<BasicShadowLayerManager*>(lm);
    NS_ABORT_IF_FALSE(!bslm->HasShadowManager(),
                      "PuppetWidget shouldn't have shadow manager yet");
    bslm->SetShadowManager(shadowManager);

    mRemoteFrame = remoteFrame;
    return true;
}
void nsBaseWidget::CreateCompositor()
{
  bool renderToEGLSurface = false;
#ifdef MOZ_ANDROID_OMTC
  renderToEGLSurface = true;
#endif
  nsIntRect rect;
  GetBounds(rect);
  mCompositorParent =
    new CompositorParent(this, renderToEGLSurface, rect.width, rect.height);
  LayerManager* lm = CreateBasicLayerManager();
  MessageLoop *childMessageLoop = CompositorParent::CompositorLoop();
  mCompositorChild = new CompositorChild(lm);
  AsyncChannel *parentChannel = mCompositorParent->GetIPCChannel();
  AsyncChannel::Side childSide = mozilla::ipc::AsyncChannel::Child;
  mCompositorChild->Open(parentChannel, childMessageLoop, childSide);
  int32_t maxTextureSize;
  PLayersChild* shadowManager;
  mozilla::layers::LayersBackend backendHint =
    mUseLayersAcceleration ? mozilla::layers::LAYERS_OPENGL : mozilla::layers::LAYERS_BASIC;
  mozilla::layers::LayersBackend parentBackend;
  shadowManager = mCompositorChild->SendPLayersConstructor(
    backendHint, 0, &parentBackend, &maxTextureSize);

  if (shadowManager) {
    ShadowLayerForwarder* lf = lm->AsShadowForwarder();
    if (!lf) {
      delete lm;
      mCompositorChild = nullptr;
      return;
    }
    lf->SetShadowManager(shadowManager);
    lf->SetParentBackendType(parentBackend);
    lf->SetMaxTextureSize(maxTextureSize);

    mLayerManager = lm;
  } else {
    // We don't currently want to support not having a LayersChild
    NS_RUNTIMEABORT("failed to construct LayersChild");
    delete lm;
    mCompositorChild = nullptr;
  }
}
Example #13
0
void TimeLine::deleteCurrentLayer()
{
    LayerManager* layerMgr = editor()->layers();
    QString strLayerName = layerMgr->currentLayer()->name();

    int ret = QMessageBox::warning(this,
                                   tr("Delete Layer", "Windows title of Delete current layer pop-up."),
                                   tr("Are you sure you want to delete layer: ") + strLayerName + " ?",
                                   QMessageBox::Ok | QMessageBox::Cancel,
                                   QMessageBox::Ok);
    if (ret == QMessageBox::Ok)
    {
        Status st = layerMgr->deleteLayer(editor()->currentLayerIndex());
        if (st == Status::ERROR_NEED_AT_LEAST_ONE_CAMERA_LAYER)
        {
            QMessageBox::information(this, "",
                                     tr("Please keep at least one camera layer in project"));
        }
    }
}
Example #14
0
void LayerTableView::updateView()
{
	//Select layer at init.
	model->refreshModel();
	this->resizeRowsToContents();

	LayerManager* pManager = LayerManager::getInstance();
	QList<LayerItem>* pList = pManager->getpLayerList();
	int index = 0;
	for (QList<LayerItem>::iterator it = pList->begin(); it != pList->end(); it++)
	{
		if (it->isSelected)
		{
			this->selectRow(index);
			break;
		}
		index++;
	}
	this->update();
}
Example #15
0
void nsBaseWidget::CreateCompositor()
{
  mCompositorThread = new Thread("CompositorThread");
  if (mCompositorThread->Start()) {
    bool renderToEGLSurface = false;
#ifdef MOZ_JAVA_COMPOSITOR
    renderToEGLSurface = true;
#endif
    nsIntRect rect;
    GetBounds(rect);
    mCompositorParent =
      new CompositorParent(this, mCompositorThread->message_loop(), mCompositorThread->thread_id(),
                           renderToEGLSurface, rect.width, rect.height);
    LayerManager* lm = CreateBasicLayerManager();
    MessageLoop *childMessageLoop = mCompositorThread->message_loop();
    mCompositorChild = new CompositorChild(lm);
    AsyncChannel *parentChannel = mCompositorParent->GetIPCChannel();
    AsyncChannel::Side childSide = mozilla::ipc::AsyncChannel::Child;
    mCompositorChild->Open(parentChannel, childMessageLoop, childSide);
    PLayersChild* shadowManager =
      mCompositorChild->SendPLayersConstructor(LayerManager::LAYERS_OPENGL);

    if (shadowManager) {
      ShadowLayerForwarder* lf = lm->AsShadowForwarder();
      if (!lf) {
        delete lm;
        mCompositorChild = nsnull;
        return;
      }
      lf->SetShadowManager(shadowManager);
      lf->SetParentBackendType(LayerManager::LAYERS_OPENGL);

      mLayerManager = lm;
    } else {
      NS_WARNING("fail to construct LayersChild");
      delete lm;
      mCompositorChild = nsnull;
    }
  }
}
void nsViewManager::WillPaintWindow(nsIWidget* aWidget)
{
  if (aWidget) {
    nsView* view = nsView::GetViewFor(aWidget);
    LayerManager *manager = aWidget->GetLayerManager();
    if (view &&
        (view->ForcedRepaint() || !manager->NeedsWidgetInvalidation())) {
      ProcessPendingUpdates();
      // Re-get the view pointer here since the ProcessPendingUpdates might have
      // destroyed it during CallWillPaintOnObservers.
      view = nsView::GetViewFor(aWidget);
      if (view) {
        view->SetForcedRepaint(false);
      }
    }
  }

  nsCOMPtr<nsIPresShell> shell = mPresShell;
  if (shell) {
    shell->WillPaintWindow();
  }
}
/**
   aRegion is given in device coordinates!!
   aContext may be null, in which case layers should be used for
   rendering.
*/
void nsViewManager::Refresh(nsView *aView, const nsIntRegion& aRegion)
{
  NS_ASSERTION(aView->GetViewManager() == this, "wrong view manager");

  if (mPresShell && mPresShell->IsNeverPainting()) {
    return;
  }

  // damageRegion is the damaged area, in twips, relative to the view origin
  nsRegion damageRegion = aRegion.ToAppUnits(AppUnitsPerDevPixel());
  // move region from widget coordinates into view coordinates
  damageRegion.MoveBy(-aView->ViewToWidgetOffset());

  if (damageRegion.IsEmpty()) {
#ifdef DEBUG_roc
    nsRect viewRect = aView->GetDimensions();
    nsRect damageRect = damageRegion.GetBounds();
    printf("XXX Damage rectangle (%d,%d,%d,%d) does not intersect the widget's view (%d,%d,%d,%d)!\n",
           damageRect.x, damageRect.y, damageRect.width, damageRect.height,
           viewRect.x, viewRect.y, viewRect.width, viewRect.height);
#endif
    return;
  }
  
  nsIWidget *widget = aView->GetWidget();
  if (!widget) {
    return;
  }

  NS_ASSERTION(!IsPainting(), "recursive painting not permitted");
  if (IsPainting()) {
    RootViewManager()->mRecursiveRefreshPending = true;
    return;
  }  

  {
    nsAutoScriptBlocker scriptBlocker;
    SetPainting(true);

    NS_ASSERTION(GetDisplayRootFor(aView) == aView,
                 "Widgets that we paint must all be display roots");

    if (mPresShell) {
#ifdef MOZ_DUMP_PAINTING
      if (nsLayoutUtils::InvalidationDebuggingIsEnabled()) {
        printf("--COMPOSITE-- %p\n", mPresShell);
      }
#endif
      uint32_t paintFlags = nsIPresShell::PAINT_COMPOSITE;
      LayerManager *manager = widget->GetLayerManager();
      if (!manager->NeedsWidgetInvalidation()) {
        manager->FlushRendering();
      } else {
        mPresShell->Paint(aView, damageRegion,
                          paintFlags);
      }
#ifdef MOZ_DUMP_PAINTING
      if (nsLayoutUtils::InvalidationDebuggingIsEnabled()) {
        printf("--ENDCOMPOSITE--\n");
      }
#endif
      mozilla::StartupTimeline::RecordOnce(mozilla::StartupTimeline::FIRST_PAINT);
    }

    SetPainting(false);
  }

  if (RootViewManager()->mRecursiveRefreshPending) {
    RootViewManager()->mRecursiveRefreshPending = false;
    InvalidateAllViews();
  }
}
	void RenderManager::onRenderToTarget(IRenderTarget* _target, bool _update)
	{
		LayerManager* layers = LayerManager::getInstancePtr();
		if (layers != nullptr)
			layers->renderToTarget(_target, _update);
	}
Example #19
0
void
nsWindow::DoDraw(void)
{
    if (!hal::GetScreenEnabled()) {
        gDrawRequest = true;
        return;
    }

    if (!gWindowToRedraw) {
        LOG("  no window to draw, bailing");
        return;
    }

    nsIntRegion region = gWindowToRedraw->mDirtyRegion;
    gWindowToRedraw->mDirtyRegion.SetEmpty();

    nsIWidgetListener* listener = gWindowToRedraw->GetWidgetListener();
    if (listener) {
        listener->WillPaintWindow(gWindowToRedraw);
    }

    LayerManager* lm = gWindowToRedraw->GetLayerManager();
    if (mozilla::layers::LAYERS_CLIENT == lm->GetBackendType()) {
      // No need to do anything, the compositor will handle drawing
    } else if (mozilla::layers::LAYERS_BASIC == lm->GetBackendType()) {
        MOZ_ASSERT(sFramebufferOpen || sUsingOMTC);
        nsRefPtr<gfxASurface> targetSurface;

        if(sUsingOMTC)
            targetSurface = sOMTCSurface;
        else
            targetSurface = Framebuffer::BackBuffer();

        {
            nsRefPtr<gfxContext> ctx = new gfxContext(targetSurface);
            gfxUtils::PathFromRegion(ctx, region);
            ctx->Clip();

            // No double-buffering needed.
            AutoLayerManagerSetup setupLayerManager(
                gWindowToRedraw, ctx, mozilla::layers::BUFFER_NONE,
                ScreenRotation(EffectiveScreenRotation()));

            listener = gWindowToRedraw->GetWidgetListener();
            if (listener) {
                listener->PaintWindow(gWindowToRedraw, region);
            }
        }

        if (!sUsingOMTC) {
            targetSurface->Flush();
            Framebuffer::Present(region);
        }
    } else {
        NS_RUNTIMEABORT("Unexpected layer manager type");
    }

    listener = gWindowToRedraw->GetWidgetListener();
    if (listener) {
        listener->DidPaintWindow();
    }
}
Example #20
0
ExportDlg::ExportDlg(QWidget *parent)
	: QDialog()
{
	this->setWindowTitle("Export image");
	LayerManager *layerManager = LayerManager::getInstance();
	imageSize = layerManager->getLayerSize();
	originalSizeLabel = new QLabel(QString("Original size: " + QString::number(imageSize.width()) + "px  *  " + QString::number(imageSize.height()) + "px"));
	exportSizeLabel = new QLabel(QString("Export Size:"));
	widthLabel = new QLabel(QString("Width:"));
	widthLabel->setFixedWidth(50);
	heightLabel = new QLabel(QString("Height: "));
	heightLabel->setFixedWidth(50);

	widthEdit = new QLineEdit();
	widthEdit->setText(QString::number(imageSize.width()));
	connect(widthEdit, SIGNAL(textChanged(const QString &)), this, SLOT(widthEditChangedSlot(const QString &)));
	heightEdit = new QLineEdit();
	heightEdit->setText(QString::number(imageSize.height()));
	connect(heightEdit, SIGNAL(textChanged(const QString &)), this, SLOT(heightEditChangedSlot(const QString &)));
	widthEdit->setValidator(new QIntValidator(1, 1920, this));
	heightEdit->setValidator(new QIntValidator(1, 1080, this));


	buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
	connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
	connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));

	canvas = new ThumbnailCanvas(false);
	canvas->setFixedSize(200, 200);

	//Merge all layer to one image.
	QImage image(layerManager->getLayerSize().width(), layerManager->getLayerSize().height(), QImage::Format_ARGB32);
	QColor transparent(0, 0, 0, 0);
	image.fill(transparent);
	QList<LayerItem>* layerList = layerManager->getpLayerList();

	QPainter mergePainter(&image);
	mergePainter.setCompositionMode(QPainter::CompositionMode_DestinationOver);

	for (QList<LayerItem>::iterator it = layerList->begin(); it != layerList->end(); it++)
	{
		if (it->isShow)
		{
			mergePainter.drawImage(it->anchor.rx(), it->anchor.ry(), it->thumbnail);
		}
	}
	previewImage = QPixmap::fromImage(image);
	canvas->setPixmap(previewImage);

	QHBoxLayout *widthLayout = new QHBoxLayout();
	QHBoxLayout *heightLayout = new QHBoxLayout();
	widthLayout->addWidget(widthLabel);
	widthLayout->addWidget(widthEdit);
	widthLayout->addWidget(new QLabel("px"));

	heightLayout->addWidget(heightLabel);
	heightLayout->addWidget(heightEdit);
	heightLayout->addWidget(new QLabel("px"));


	QVBoxLayout *rightLayout = new QVBoxLayout();
	rightLayout->addWidget(originalSizeLabel);
	rightLayout->addWidget(exportSizeLabel);
	rightLayout->addLayout(widthLayout);
	rightLayout->addLayout(heightLayout);

	QHBoxLayout *leftLayout = new QHBoxLayout();
	leftLayout->addWidget(canvas);
	leftLayout->addLayout(rightLayout);

	QVBoxLayout* mainLayout = new QVBoxLayout();
	mainLayout->addLayout(leftLayout);
	mainLayout->addWidget(buttonBox);

	this->setLayout(mainLayout);

}
Example #21
0
void LayerTableView::deleteLayer()
{
	LayerManager* pManager = LayerManager::getInstance();
	pManager->deleteLayer();
}
Example #22
0
void Gamestep3::init()
{
	window.setMouseCursorVisible(true);

	layerManager.add(&white1l);
	layerManager.add(&white2l);

	layerManager.add(&layerBackground);
	layerManager.add(&layerCell);
	layerManager.add(&layerAgent);


	// Generation de la map de cellules
	const sf::Vector2u viewport = window.getSize();
	const sf::Vector2u margins(100, 100);

	const int maxRadius = 50;
	const int minSpacing = 5;

	const int idealCols = 10;
	const int idealRows = 5;

	int W = viewport.x - 2 * ( margins.x + maxRadius );
	int H = viewport.y - 2 * ( margins.y + maxRadius );

	int U = H / (( maxRadius + minSpacing ) * 4);
	int V = W / (( maxRadius + minSpacing ) * 2);

	if(U > idealRows) U = idealRows;
	if(V > idealCols) V = idealCols;

	float dx = W / (V - 1);
	float dy = H / (U * 1.5f);

	for(int u = 0; u < U; u++)
	{
		for(int v = 0; v < V; v++)
		{

			float x = v 			* dx + margins.x + maxRadius;
			float y = (u*2 + v%2) 	* dy + margins.y + maxRadius;


			Cell::Size s;
			switch(rand() % 3)
			{
				case 0: s = Cell::SMALL; break;
				case 1: s = Cell::MED; break;
				case 2: s = Cell::BIG; break;
			}


			Cell* c;

			if(u == 0 && v == 0) // Le joueur commence dans le coin haut gauche
				c = new Cell(sf::Vector2f(x, y), Cell::BIG, 1);
			else if(u == U-1 && v == V-1) // Et l'ennemi dans le coin bas droite
				c = new Cell(sf::Vector2f(x, y), Cell::BIG, -1);
			else
				c = new Cell(sf::Vector2f(x, y), s);


			cells.push_back(c);
			layerCell.addElement(c);

		}
	}


	reticule.setOrigin(64, 64);
	layerCell.addElement(&reticule);

}
Example #23
0
void Gamestep3::update()
{
	int width= window.getSize().x;
	int height= window.getSize().y;

	int white1size = white1.size();
	int white2size = white2.size();

	for(unsigned int j=0; j<white1size; j++){
		if(white1size>0 && white1.at(j)->getPosition().y>height+128){
			white1.erase(white1.begin()+j);
			white1size--;
		}
	}

	for(unsigned int j=0; j<white2size; j++){
		if(white2size>0 && white2.at(j)->getPosition().y>height+128){
			white2.erase(white2.begin()+j);
			white2size--;
		}
	}


	//spawn white1
	if(frame%30==0){
		int r = 0 + (rand() % ((width-128) - 0));
		white1.push_back(new Element(Texture("white1.png"),sf::Vector2f(r,0), 0.f));
		float srand = (rand()%5)/10.0;
		white1[white1.size()-1]->setScale(0.75+(srand),0.75+(srand));
		white1l.addElement(white1[white1.size()-1]);
	}

	//spawn white2
	if(frame%50==0){
		int r = 0 + (rand() % ((width-128) - 0));
		white2.push_back(new Element(Texture("white2.png"),sf::Vector2f(r,0), 0.f));
		float srand = (rand()%10)/10.0;
		white2[white2.size()-1]->setScale(0.75+(srand),0.75+(srand));
		white2l.addElement(white2[white2.size()-1]);
	}
	//Update white1
	for(std::vector<Element*>::iterator i = white1.begin(); i != white1.end(); i++){
		(*i)->move(0,2);
	}

	//Update white2
	for(std::vector<Element*>::iterator i = white2.begin(); i != white2.end(); i++){
		(*i)->move(0,1);
	}


	// Gestion du click
	bool lbutton = sf::Mouse::isButtonPressed(sf::Mouse::Left);
	bool rbutton = sf::Mouse::isButtonPressed(sf::Mouse::Right);

	if( (lbutton || rbutton) && !clicked)
	{
		clicked = true;
		bool clicDansLeVide = true;

		for(std::vector<Cell*>::iterator i = cells.begin(); i != cells.end(); i++)
		{
			if( (*i)->isInside(sf::Mouse::getPosition()) )
			{
				onclick(*i, lbutton);
				clicDansLeVide = false;
				break;
			}
		}

		if(lbutton && clicDansLeVide) unselect();
	}

	if(!lbutton && !rbutton) clicked = false;






	// Dessin du réticule pour la cellule selectionnée
	if(selectedCell != NULL)
	{
		reticule.setColor(sf::Color::Green);
		reticule.setPosition(selectedCell->getPosition());
		reticule.rotate(2);
		float scale = (100+abs(((frame/4)%40)-20)) / 100.f;
		reticule.setScale( scale * selectedCell->getScale() * 5.f );
	}
	else
	{
		reticule.setColor(sf::Color::Transparent);
	}


	// Suppression des agents inactifs
	for(std::vector<Agent*>::iterator i = agents.begin(); i != agents.end();)
	{
		if( !(*i)->isAlive() )
		{
			delete (*i);
			layerAgent.removeElement(*i);
			i = agents.erase(i);
		}
		else i++;
	}



	// Conditions de victoire et pre-check pour l'AI
	int nbPositive = 0;
	int nbNegative = 0;
	int nbNeutre = 0;
	for(std::vector<Cell*>::iterator i = cells.begin(); i != cells.end(); i++)
	{
		if( (*i)->getValue() > 0 ) nbPositive++;
		if( (*i)->getValue() < 0 ) nbNegative++;
		if( (*i)->getValue() == 0 ) nbNeutre++;
	}
	if(nbPositive == 0) lose = true;
	if(nbNegative == 0) win = true;


	// Boucle AI
	for(std::vector<Cell*>::iterator i = cells.begin(); i != cells.end(); i++)
	{
		if( (*i)->getValue() < 0 )
		{
			int intervalBetweenAttacks = ((120 /*+ rand()%60*/) /*- (*i)->getValue()*3*/ + nbNegative*50);

			if((*i)->getLastAttack() == 0) (*i)->setLastAttack(frame);
			if(frame - (*i)->getLastAttack() > intervalBetweenAttacks)
			{
				(*i)->setLastAttack(frame);

				// Opérations très lourdes mais osef total vu les perfs du jeu
				std::vector<Cell*> targets = cells;
				std::sort(targets.begin(), targets.end(), AI::SortFunctor((*i)));
				std::remove_if(targets.begin(), targets.end(), AI::RemoveFunctor((*i)));

				if(targets.size() > 0)
				{
					int target = rand() % min(3, (int)targets.size());

					Agent* a = new Agent(10, *(*i), *(targets[target]));
					agents.push_back(a);
					layerAgent.addElement(a);
				}
			}

		}
	}

	// Fond rouge
	int red = 90+abs(((frame/4)%60)-30);
	window.clear(sf::Color(red, 22, 22));


	layerManager.update(frame);
	layerManager.draw(window);
	window.display();

	frame++;
}
	void RenderManager::onResizeView(const IntSize& _viewSize)
	{
		LayerManager* layers = LayerManager::getInstancePtr();
		if (layers != nullptr)
			layers->resizeView(_viewSize);
	}