Example #1
0
void HelpTask::makeCurrent()
{
    if(!background_saved)
        saveBackground();

    Task::makeCurrent();
}
void AnimatedImage::startAnimation(const CPoint &p) {
  if(!isLoaded()) {
    throwException(_T("No images loaded"));
  }
  hide();
  saveBackground(p);
  m_animator.startAnimation(this, p);
}
Example #3
0
void MenuTask::makeCurrent()
{
    menu_open = true;
    menu_width_visible = 0;
    menu_selected_item = SAVE_WORLD;

    if(!background_saved)
        saveBackground();

    Task::makeCurrent();
}
void AnimatedImage::paintFrames(const CPoint &p, UINT last) {
  if(!isLoaded() || isPlaying()) {
    return;
  }
  if(last >= (UINT)m_frameTable.size()) {
    last = (int)m_frameTable.size()-1;
  }
  if(hasSavedBackground() && (m_background->getSize() != m_size)) {
    hide();
  }
  if(!hasSavedBackground()) {
    saveBackground(p);
  }
  if(m_lastPaintedFrame != NULL) {
    m_lastPaintedFrame->dispose();
  }
  for(UINT i = 0; i <= last; i++) {
    const GifFrame &frame = m_frameTable[i];
    frame.paint();
    if(i < last) {
      frame.dispose();
    }
  }
}
void AnimatedImage::paintAllFrames(const CRect &r) {
  if(!isLoaded()) {
    return;
  }
  hide();
  const CSize rSize         = r.Size();
  const CSize prSize        = getSize();
  const int   n             = getFrameCount();
  int         availableArea = getArea(rSize);

  double       scaleFactor;
  CSize        newSize;
  int          fpl;
  UINT         maxArea = 0;

//  m_comment = format("imageCount:%2d  rSize:(%3d,%3d)\r\n", n, rSize.cx, rSize.cy);

  for(int framesPerLine = n; framesPerLine >= 1; framesPerLine--) {
    const int lineCount      = (n-1) / framesPerLine + 1;
    const int lastFrameCount = n%framesPerLine;
    const int fullLines      = lineCount - (lastFrameCount?1:0);

    assert((fullLines >= 1) && (lastFrameCount >= 0) && (fullLines * framesPerLine + lastFrameCount == n));

    const double sfx = min(1.0, (double)(rSize.cx-1) / ((prSize.cx+1) * framesPerLine));
    double       sfy = min(1.0, (double)(rSize.cy-1) / ((prSize.cy+1) * lineCount    ));
    double       sf  = min(sfx, sfy);

    const CSize  psz  = CSize(floor(sf * prSize.cx) + 1, floor(sf * prSize.cy) + 1);
    const UINT   area = getArea(psz);;
    const CSize dstSz(framesPerLine * psz.cx-1, lineCount * psz.cy-1);
/*
    const CSize rightWaste( rSize.cx - dstSz.cx             , fullLines * psz.cy  );
    const CSize bottomWaste(rSize.cx                        , rSize.cy - dstSz.cy );
    const int   totalWaste = getArea(rightWaste) + getArea(bottomWaste);
*/
    if((dstSz.cx <= rSize.cx) && (dstSz.cy <= rSize.cy) && (area > maxArea)) {
      maxArea     = area;
      newSize     = psz;
      scaleFactor = sf;
      fpl         = framesPerLine;
    }
/*
    m_comment += format("f/l %2d r:%3d,%3d) a %6s, waste %8s (fx,fy,f):(%.3lf,%.3lf,%.6lf) sz:(%3d,%3d)\r\n"
                       , framesPerLine
                       , dstSz.cx, dstSz.cy
                       , format1000(area).cstr()
                       , format1000(totalWaste).cstr()
                       , sfx,sfy,sf
                       , psz.cx,psz.cy
                       );
*/
  }

  CPoint p = r.TopLeft();
  saveBackground(p, &rSize);
  for(int i = 0, lc = 0; i < n; i++) {
    const GifFrame &frame = m_frameTable[i];
    if(lc == fpl) {
      p.x = r.left;
      p.y += newSize.cy;
      lc = 0;
    }
    frame.paint();
    flushPr(p,  m_workPr, scaleFactor);
    frame.dispose();
    p.x += newSize.cx;
    lc++;
  }
}