Exemple #1
0
	DrawableSurface *Sprite::getRotatedSurface(int index)
	{
		RotatedImage::RotationMap::const_iterator it = rotated[index]->rotationMap.find(actColor);
		DrawableSurface *ds;
		if (it == rotated[index]->rotationMap.end())
		{
			// compute hue shift
			float baseHue, actHue, lum, sat;
			float hueShift;
			Color(51, 255, 153).getHSV(&baseHue, &sat, &lum);
			actColor.getHSV(&actHue, &sat, &lum);
			hueShift = actHue - baseHue;
			
			// rotate image
			ds = rotated[index]->orig->clone();
			ds->shiftHSV(hueShift, 0.0f, 0.0f);
			
			// write back
			rotated[index]->rotationMap[actColor] = ds;
		}
		else
		{
			ds = it->second;
		}
		return ds;
	}
Exemple #2
0
bool
RasterImage::StartDecodingWithResult(uint32_t aFlags)
{
  if (mError) {
    return false;
  }

  if (!mHasSize) {
    mWantFullDecode = true;
    return false;
  }

  uint32_t flags = (aFlags & FLAG_ASYNC_NOTIFY) | FLAG_SYNC_DECODE_IF_FAST;
  DrawableSurface surface = RequestDecodeForSizeInternal(mSize, flags);
  return surface && surface->IsFinished();
}
Pair<DrawResult, RefPtr<SourceSurface>>
RasterImage::GetFrameInternal(const IntSize& aSize,
                              uint32_t aWhichFrame,
                              uint32_t aFlags)
{
  MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE);

  if (aSize.IsEmpty()) {
    return MakePair(DrawResult::BAD_ARGS, RefPtr<SourceSurface>());
  }

  if (aWhichFrame > FRAME_MAX_VALUE) {
    return MakePair(DrawResult::BAD_ARGS, RefPtr<SourceSurface>());
  }

  if (mError) {
    return MakePair(DrawResult::BAD_IMAGE, RefPtr<SourceSurface>());
  }

  // Get the frame. If it's not there, it's probably the caller's fault for
  // not waiting for the data to be loaded from the network or not passing
  // FLAG_SYNC_DECODE.
  DrawableSurface surface =
    LookupFrame(aSize, aFlags, ToPlaybackType(aWhichFrame));
  if (!surface) {
    // The OS threw this frame away and we couldn't redecode it.
    return MakePair(DrawResult::TEMPORARY_ERROR, RefPtr<SourceSurface>());
  }

  RefPtr<SourceSurface> sourceSurface = surface->GetSourceSurface();

  if (!surface->IsFinished()) {
    return MakePair(DrawResult::INCOMPLETE, Move(sourceSurface));
  }

  return MakePair(DrawResult::SUCCESS, Move(sourceSurface));
}
void VerticalListMenuWindowArea::drawItems(ScreenBuffer& buffer) {
  // Get coordinates of the top-left corner of the menu content
  // relative to the top-left corner of the containing window
  int xBase = parentWindow_->contentX() - parentWindow_->x() + paddingLeft_;
  int yBase = parentWindow_->contentY() - parentWindow_->y() + paddingTop_;
  
/*  DrawableSurface* drawable
    = gameMemory_.graphicsCore().createDrawableSurface(
                                    parentWindow_->contentW() - paddingLeft_
                                                              - paddingRight_,
                                    parentWindow_->contentH() - paddingTop_
                                                              - paddingBottom_); */
  
/*  // Draw items
  int firstItem = 0;
  int lastItem = numItems();
  int numHiddenItemsAbove = 0;
  
  // If scrolling is enabled, print only the fully visible
  // items and the entries directly above and below them
  if (scrolling_) {
    firstItem = selectedItemNum_;
    lastItem = firstItem + maxVisibleItems();
    
    if (lastItem > numItems()) {
      lastItem = numItems() - 1;
    }
    else if (lastItem < numItems() - 1) {
//      lastItem = 
    }
    
    if (selectedItemNum_ != 0) {
      --firstItem;
    }
  } */
  
  if (needsRedraw_) {
                
    delete itemSurface_;
    itemSurface_ = gameMemory_.graphicsCore().createDrawableSurface(
                     parentWindow_->contentW() - paddingLeft_
                                                - paddingRight_,
                     parentWindow_->contentH() - paddingTop_
                                               - paddingBottom_);
    
    DrawableSurface* drawable = itemSurface_;
    
    for (int i = 0; i < numItems(); i++) {
  //    int xPos = xBase - scrollX_;
  //    int yPos = yBase + (spacing_ * i) - scrollY_;

      int xPos = -scrollX_;
      // The (i + 1) here is necessary because text is drawn upward
      // from the base position rather than downward
      int yPos = (spacing_ * (i + 1)) - scrollY_;
      
      drawItem(getItem(i),
               *drawable,
               xPos,
               yPos);
    }
    drawable->update();
  
    needsRedraw_ = false;
  }
    
  // Blit drawn items to buffer
  buffer.draw(*itemSurface_,
              parentWindow_->contentX() + paddingLeft_,
              parentWindow_->contentY() + paddingTop_);
              
//  delete drawable;
  
  // Draw cursor
  buffer.draw(cursorEnabledAnimation_->currentFrame().graphic(),
              parentWindow_->contentX(),
              parentWindow_->contentY()
                + paddingTop_                   // skip padding
                + (selectedItemNum_ * spacing_) // skip height of items above
                + (spacing_/2)                  // center vertically on item
                - scrollY_                      // account for scolling
                - (((spacing_/11) <= 0) 
                    ? (spacing_/3) 
                    : (spacing_/8)));           // this aligns better with the
                                                // fonts we're using
}
	int MessageBox(GraphicContext *parentCtx, const std::string font, MessageBoxType type, std::string title, std::string caption1, std::string caption2, std::string caption3)
	{
		// for passing captions to class
		std::string captionArray[3]={
			caption1,
			caption2,
			caption3 };
	
		int captionWidth[3];
		memset(captionWidth, 0, sizeof(captionWidth));
		Font *fontPtr=Toolkit::getFont(font);
	
		// compute number of caption
		unsigned captionCount;
		if (!caption3.empty())
		{
			captionCount = 3;
			captionWidth[2] = fontPtr->getStringWidth(captionArray[2])+40;
			captionWidth[1] = fontPtr->getStringWidth(captionArray[1])+40;
			captionWidth[0] = fontPtr->getStringWidth(captionArray[0])+40;
		}
		else if (!caption2.empty())
		{
			captionCount = 2;
			captionWidth[1] = fontPtr->getStringWidth(captionArray[1])+40;
			captionWidth[0] = fontPtr->getStringWidth(captionArray[0])+40;
		}
		else
		{
			captionCount = 1;
			captionWidth[0] = fontPtr->getStringWidth(captionArray[0])+40;
		}
	
		int totCaptionWidth = captionWidth[0]+captionWidth[1]+captionWidth[2]+(captionCount-1)*20+40;
		int titleWidth =  fontPtr->getStringWidth(title)+20;
	
		MessageBoxScreen *mbs = new MessageBoxScreen(parentCtx, font, type, title, titleWidth, totCaptionWidth, captionCount, captionWidth, captionArray);
	
		// save screen in a temporary surface
		parentCtx->setClipRect();
		DrawableSurface *background = new DrawableSurface(parentCtx->getW(), parentCtx->getH());
		background->drawSurface(0, 0, parentCtx);
		
		mbs->dispatchPaint();
	
		SDL_Event event;
		while(mbs->endValue<0)
		{
			Sint32 time = SDL_GetTicks();
			while (SDL_PollEvent(&event))
			{
				if (event.type==SDL_QUIT)
					break;
				//Manual integration of cmd+q and alt f4
				if(event.type == SDL_KEYDOWN)
				{
#					ifdef USE_OSX
					if(event.key.keysym.sym == SDLK_q && SDL_GetModState() & KMOD_META)
					{
						break;
					}
#					endif
#					ifdef USE_WIN32
					if(event.key.keysym.sym == SDLK_F4 && SDL_GetModState() & KMOD_ALT)
					{
						break;
					}
#					endif
				}

				mbs->translateAndProcessEvent(&event);
			}
			mbs->dispatchPaint();
			parentCtx->drawSurface((int)0, (int)0, background);
			parentCtx->drawSurface(mbs->decX, mbs->decY, mbs->getSurface());
			parentCtx->nextFrame();
			Sint32 newTime = SDL_GetTicks();
			SDL_Delay(std::max(40 - newTime + time, 0));
		}
	
		int retVal;
		if (mbs->endValue>=0)
			retVal=mbs->endValue;
		else
			retVal=-1;
	
		// clean up
		delete mbs;
		
		// restore screen and destroy temporary surface
		parentCtx->drawSurface(0, 0, background);
		delete background;
	
		return retVal;
	}
RasterImage::Draw(gfxContext* aContext,
                  const IntSize& aSize,
                  const ImageRegion& aRegion,
                  uint32_t aWhichFrame,
                  SamplingFilter aSamplingFilter,
                  const Maybe<SVGImageContext>& /*aSVGContext - ignored*/,
                  uint32_t aFlags)
{
  if (aWhichFrame > FRAME_MAX_VALUE) {
    return DrawResult::BAD_ARGS;
  }

  if (mError) {
    return DrawResult::BAD_IMAGE;
  }

  // Illegal -- you can't draw with non-default decode flags.
  // (Disabling colorspace conversion might make sense to allow, but
  // we don't currently.)
  if (ToSurfaceFlags(aFlags) != DefaultSurfaceFlags()) {
    return DrawResult::BAD_ARGS;
  }

  if (!aContext) {
    return DrawResult::BAD_ARGS;
  }

  if (IsUnlocked() && mProgressTracker) {
    mProgressTracker->OnUnlockedDraw();
  }

  // If we're not using SamplingFilter::GOOD, we shouldn't high-quality scale or
  // downscale during decode.
  uint32_t flags = aSamplingFilter == SamplingFilter::GOOD
                 ? aFlags
                 : aFlags & ~FLAG_HIGH_QUALITY_SCALING;

  DrawableSurface surface =
    LookupFrame(aSize, flags, ToPlaybackType(aWhichFrame));
  if (!surface) {
    // Getting the frame (above) touches the image and kicks off decoding.
    if (mDrawStartTime.IsNull()) {
      mDrawStartTime = TimeStamp::Now();
    }
    return DrawResult::NOT_READY;
  }

  bool shouldRecordTelemetry = !mDrawStartTime.IsNull() &&
                               surface->IsFinished();

  auto result = DrawInternal(Move(surface), aContext, aSize,
                             aRegion, aSamplingFilter, flags);

  if (shouldRecordTelemetry) {
      TimeDuration drawLatency = TimeStamp::Now() - mDrawStartTime;
      Telemetry::Accumulate(Telemetry::IMAGE_DECODE_ON_DRAW_LATENCY,
                            int32_t(drawLatency.ToMicroseconds()));
      mDrawStartTime = TimeStamp();
  }

  return result;
}