コード例 #1
0
void VRAMEditorLayeredGraphicScene::boxGenericLength(
                    Graphic& dst,
                    int baseIndex,
                    int numTiles,
                    Color color,
                    int width,
                    double scale) {
  for (int i = 0; i < numTiles; i++) {
    // Calculate position in Graphic
    int xPos = tileIndexToXPos(baseIndex + i);
    int yPos = tileIndexToYPos(baseIndex + i);
  
    BoxGraphicSceneObject box(color,
                              width,
                              GGTile::width * scale,
                              GGTile::height * scale,
                              xPos * scale,
                              yPos * scale,
                              true);
    
    box.render(dst,
               Box(0, 0, dst.w(), dst.h()),
               1.00);
  }
}
コード例 #2
0
ファイル: PaletteEditor.cpp プロジェクト: suppertails66/tales
void PaletteEditor::drawPreviewGraphic(Graphic& dst) {
  colorPreview_.setColor(
    Color(currentColor().realR(),
          currentColor().realG(),
          currentColor().realB(),
          Color::fullAlphaOpacity));
  colorPreview_.render(dst,
                       Box(0, 0, dst.w(), dst.h()),
                       1.00);
}
コード例 #3
0
void GraphicSubheaderAddDialog::updatePreview() {
    GGTileSet tiles
            = levelGraphicsData_.compressedGraphic(graphicIndex_);

    if (flipped_) {
        for (int i = 0; i < tiles.numTiles(); i++) {
            tiles[i].flipHorizontal();
        }
    }

    Graphic graphic
            = tiles.toPalettizedGraphic(16,
                                        objectPalette_,
                                        Color(0, 0, 0, Color::fullAlphaOpacity));
    Graphic scaledGraphic(graphic.w() * 2,
                          graphic.h() * 2);
    graphic.scale(scaledGraphic);

    ui->graphicPreview->setPixmap(
                TalesQtFormatConversion::graphicToPixmap(scaledGraphic));

    ui->previewNumTilesLabel->setText(
                (StringConversion::toString(tiles.numTiles()) + " tiles").c_str());
}
コード例 #4
0
void MetatilePickerLayeredGraphicScene::render(Graphic& dst,
                      Box srcbox,
                      double scale) {
  dst.clear();
  
  int metatileNum = 0;
  for (int j = 0; j < metatilesPerColumn_; j++) {
    for (int i = 0; i < metatilesPerRow_; i++) {
      if (bgLayerEnabled_) {
        dst.blit(metatilesVisualBG_[metatileNum],
                 Box(i * MetatileStructure::metatileWidth,
                     j * MetatileStructure::metatileHeight,
                     MetatileStructure::metatileWidth,
                     MetatileStructure::metatileHeight),
                 Graphic::transUpdate);
      }
      
      if (fgLayerEnabled_) {
        dst.blit(metatilesVisualFG_[metatileNum],
                 Box(i * MetatileStructure::metatileWidth,
                     j * MetatileStructure::metatileHeight,
                     MetatileStructure::metatileWidth,
                     MetatileStructure::metatileHeight),
                 Graphic::transUpdate);
      }
      
      if (effectLayerEnabled_) {
        dst.blit(metatilesEffect_[metatileNum],
                 Box(i * MetatileStructure::metatileWidth,
                     j * MetatileStructure::metatileHeight,
                     MetatileStructure::metatileWidth,
                     MetatileStructure::metatileHeight),
                 Graphic::noTransUpdate);
      }
      
      if (verticalSolidityLayerEnabled_) {
        dst.blit(metatilesVerticalSolidity_[metatileNum],
                 Box(i * MetatileStructure::metatileWidth,
                     j * MetatileStructure::metatileHeight,
                     MetatileStructure::metatileWidth,
                     MetatileStructure::metatileHeight),
                 Graphic::noTransUpdate);
      }
      
      if (horizontalSolidityLayerEnabled_) {
        dst.blit(metatilesHorizontalSolidity_[metatileNum],
                 Box(i * MetatileStructure::metatileWidth,
                     j * MetatileStructure::metatileHeight,
                     MetatileStructure::metatileWidth,
                     MetatileStructure::metatileHeight),
                 Graphic::noTransUpdate);
      }
      
      ++metatileNum;
    }
  }
      
  if (gridLayerEnabled_) {
    gridLayer_.render(dst,
                      Box(srcbox.x(),
                          srcbox.y(),
                          dst.w(),
                          dst.h()),
                      1.00);
  }
  
  if ((highlightedMetatileBoxEnabled_)) {
    dst.drawRectBorder(metatileIndexToX(highlightedMetatileIndex_),
                       metatileIndexToY(highlightedMetatileIndex_),
                       MetatileStructure::metatileWidth,
                       MetatileStructure::metatileHeight,
                       Color(0xFF, 0xFF, 0x00, Color::fullAlphaOpacity),
                       2);
  }
  
  if ((toolManager_->currentTool() == LevelEditorTools::metatilePaint)) {
    dst.drawRectBorder(metatileIndexToX(toolManager_->pickedMetatileIndex()),
                       metatileIndexToY(toolManager_->pickedMetatileIndex()),
                       MetatileStructure::metatileWidth,
                       MetatileStructure::metatileHeight,
                       Color(0xFF, 0x00, 0x00, Color::fullAlphaOpacity),
                       2);
  }
}
コード例 #5
0
void MetatileStructureEditor::drawMetatilePickerGraphic(Graphic& dst) {
  metatilePicker_.render(dst,
                         Box(0, 0,
                             dst.w(), dst.h()),
                         1.00);
}
コード例 #6
0
void GridGraphicSceneLayer::render(Graphic& dst,
            Box srcbox,
            double scale) {
  if (!visible_) {
    return;
  }
  
//  int maxPos = basePos + (srcbox.w() * scale);
  int realSpacing = lineSpacing_ * scale;
  
  int realXLimit = xLimit_ * scale;
  int realYLimit = yLimit_ * scale;
  
  if (xLimit_ == 0) {
//    realXLimit = (srcbox.x() + srcbox.w()) * scale;
    realXLimit = dst.w();
  }
  
  if (yLimit_ == 0) {
//    realYLimit = (srcbox.y() + srcbox.h()) * scale;
    realYLimit = dst.h();
  }
  
  if (dst.w() < realXLimit) {
    realXLimit = dst.w();
  }
  
  if (dst.h() < realYLimit) {
    realYLimit = dst.h();
  }
  
  int realLineWidth = lineWidth_;
  if (enlargeOnZoom_) {
    realLineWidth *= scale;
  }
  
  // Compute where to start drawing lines
  int baseXPos = srcbox.x() * scale;
//  int baseXPos = srcbox.x();
  int drawXBase = -(baseXPos % realSpacing);
  
  int baseYPos = srcbox.y() * scale;
//  int baseYPos = srcbox.y();
  int drawYBase = -(baseYPos % realSpacing);
  
  // Draw vertical lines
  for (int i = drawXBase; i < realXLimit; i += realSpacing) {
    dst.drawLine(i, 0,
                 i, realYLimit,
                 color_,
                 realLineWidth,
                 Graphic::noTransUpdate);
  }
  
  // Draw horizontal lines
  for (int i = drawYBase; i < realYLimit; i += realSpacing) {
    dst.drawLine(0, i,
                 realXLimit, i,
                 color_,
                 realLineWidth,
                 Graphic::noTransUpdate);
  }
}
コード例 #7
0
void VRAMEditorLayeredGraphicScene::render(
                    Graphic& dst,
                    Box srcbox,
                    double scale) {
  // Create empty graphic with white background (TODO: selectable BG color)
  // The normal background color is black, so unused tiles will show up
  // as white
//  Graphic g(nativeWidth(), nativeHeight());
//  g.clear(Color(0, 0, 0, 0));
  g_.clear();
  
  // Get level graphics header containing graphics to render
  int levelGraphicsHeaderIndex
    = levelGraphicsData_.levelHeaderIndexByMapnum(areaNum_,
                                                  mapNum_);
  LevelGraphicsHeader& levelGraphicsHeader
    = levelGraphicsData_.levelGraphicsHeader(levelGraphicsHeaderIndex);
    
  // Look up palette header for this level
  LevelPaletteHeader& levelPaletteHeader
    = paletteHeaders_.headerByIndex(
        paletteHeaders_.indexOfMapNum(areaNum_,
                                      mapNum_));
  
  // Get level palettes
  GGPalette palette0
    = palettes_.palette(levelPaletteHeader.palette0Index());
  GGPalette palette1
    = palettes_.palette(levelPaletteHeader.palette1Index());
  
  // Get map graphic index
  int mapGraphicIndex = levelGraphicsHeader.mapGraphicIndex();
  
  // Get map graphic
  GGTileSet mapGraphic
    = levelGraphicsData_.compressedGraphic(mapGraphicIndex);
  
  // Get index of the start of the map tiles
  int mapTileIndex
    = vramAddressToTileIndex(levelGraphicsHeader.vdpWriteAddress());
    
  // Render map graphic
  renderTiles(g_,
              mapTileIndex,
              mapGraphic,
              palette0,
              Graphic::noTileTrans);
    
  // Get object graphics header index
  int objectGraphicsHeaderIndex
    = levelGraphicsHeader.objectGraphicsHeaderIndex();
    
  // Get object graphics header
  ObjectGraphicsHeader& objectGraphicsHeader
    = levelGraphicsData_.objectGraphicsHeader(objectGraphicsHeaderIndex);
    
  // Iterate over graphics subheaders and add object graphics to render
  for (int i = 0; i < objectGraphicsHeader.size(); i++) {
    ObjectGraphicSubheader& subheader
      = objectGraphicsHeader.subheader(i);
    
    int objectGraphicIndex = subheader.objectGraphicIndex();
    
    // Get graphic
    GGTileSet objectGraphic
      = levelGraphicsData_.compressedGraphic(objectGraphicIndex);
      
    // Flip tiles if horizontal flip flag is set
    if (subheader.substitutionOption()
          == ObjectGraphicSubheader::substitutionEnabled) {
      for (int j = 0; j < objectGraphic.numTiles(); j++) {
        objectGraphic[j].flipHorizontal();
      }
    }
    
    // Get index of the tile
    int tileIndex = vramAddressToTileIndex(subheader.vdpWriteAddress());
    
    // Render object graphic.
    // Use palette 1 (sprite palette) for objects.
    // Technically we "should" use transparency here, but it's possible
    // to overwrite one graphic with another and we don't want to leave
    // scraps of the previous graphic visible when that happens.
    // TODO: add some concept of background color (maybe change color 0
    // in palette?)
    renderTiles(g_,
                tileIndex,
                objectGraphic,
                palette1,
                Graphic::noTileTrans);
    
    // Draw full graphic selection box if enabled and needed
    // (this will be scaled with the graphic, negating the benefits of vector-
    // based drawing!)
    if ((i == fullSelectionBoxGraphicIndex_)
        && fullSelectionBoxEnabled_) {
        
/*      // Draw line on left side of first tile
      int firstXPos = tileIndexToXPos(tileIndex);
      int firstYPos = tileIndexToYPos(tileIndex);
      g.drawLine(firstXPos, firstYPos,
                 firstXPos, firstYPos + GGTile::height,
                 Color(255, 255, 255, Color::fullAlphaOpacity),
                 2,
                 Graphic::noTransUpdate);
        
      // Draw line on right side of last tile
      int lastXPos = tileIndexToXPos(tileIndex + objectGraphic.numTiles());
      int lastYPos = tileIndexToYPos(tileIndex + objectGraphic.numTiles());
      g.drawLine(lastXPos + GGTile::width, lastYPos,
                 lastXPos + GGTile::width, lastYPos + GGTile::height,
                 Color(255, 255, 255, Color::fullAlphaOpacity),
                 2,
                 Graphic::noTransUpdate);
      
      // Box each tile in the graphic
      for (int j = 0; j < objectGraphic.numTiles(); j++) {
        // Calculate position in Graphic
        int xPos = tileIndexToXPos(tileIndex);
        int yPos = tileIndexToYPos(tileIndex);
        
        // Draw lines above and below tile
        g.drawLine(xPos, yPos,
                   xPos + GGTile::width, yPos,
                   Color(255, 255, 255, Color::fullAlphaOpacity),
                   2,
                   Graphic::noTransUpdate);
        g.drawLine(xPos, yPos + GGTile::height,
                   xPos + GGTile::width, yPos + GGTile::height,
                   Color(255, 255, 255, Color::fullAlphaOpacity),
                   2,
                   Graphic::noTransUpdate);
        
        // Move to next tile position
        ++tileIndex;
      } */
      
/*      for (int j = 0; j < objectGraphic.numTiles(); j++) {
        // Calculate position in Graphic
        int xPos = tileIndexToXPos(tileIndex + j);
        int yPos = tileIndexToYPos(tileIndex + j);
        BoxGraphicSceneObject box(Color(255, 0, 255, Color::fullAlphaOpacity),
                                  2,
                                  GGTile::width,
                                  GGTile::height,
                                  xPos,
                                  yPos,
                                  true);
        
        box.render(g,
                   Box(0, 0, dst.w(), dst.h()),
                   1.00);
      } */
    }
  }
    
/*  GenericGraphicSceneLayer graphics;
  Graphic testG(nativeWidth(), nativeHeight());
  renderTiles(testG,
              0,
              mapGraphic,
              palette0,
              Graphic::noTileTrans);
  BitmapGraphicSceneObject* testBitmap
    = new BitmapGraphicSceneObject(testG,
                           0,
                           0,
                           true);
  graphics.addObject(testBitmap);
  graphics.render(g,
                  Box(0, 0, nativeWidth(), nativeHeight()),
                  1.00,
                  1.00); */
                  
/*  GenericGraphicSceneLayer graphics;
  BoxGraphicSceneObject* testBox
    = new BoxGraphicSceneObject(Color(255, 0, 0, 0),
                                3,
                                45,
                                45,
                                20,
                                20,
                                true);
  graphics.addObject(testBox);
  graphics.render(g,
                  Box(0, 0, nativeWidth(), nativeHeight()),
                  3.00,
                  1.00); */
              
  int width = srcbox.w();
  int height = srcbox.h();
  
  // If width or height parameter is zero, replace with maximum
  if (width == 0) {
    width = nativeWidth();
  }
  
  if (height == 0) {
    height = nativeHeight();
  }
              
  // Crop if necessary
  if ((srcbox.x() != 0) || (srcbox.y() != 0)) {
    Graphic tmp(width, height);
    
    // Copy desired portion to temp graphic
    tmp.copy(g_,
             Box(0, 0, width, height),
             Box(srcbox.x(),
                 srcbox.y(),
                 width,
                 height),
             Graphic::noTransUpdate);
             
    // Copy temp graphic to primary
    g_ = tmp;
  }
  
  // Scale graphic if necessary
  if (scale == 1.00) {
    dst = g_;
  }
  else {
//    dst = Graphic(width * scale, height * scale);
    g_.scale(dst,
             Box(0, 0, width * scale, height * scale),
             Graphic::noTransUpdate);
  }
    
  // Draw grid if enabled
  if (gridEnabled_) {
    grid_.render(dst,
                 Box(srcbox.x(),
                     srcbox.y(),
                     width * scale,
                     height * scale),
                 scale);
  }
  
  if (EditorMetadata::areaNumHasVRAMIndices(areaNum_)) {
//    std::cerr << areaNum_ << " " << mapNum_ << std::endl;
    // Draw leaf box if enabled
    if (showLeaf_) {
      boxGenericLength(dst,
                       leafGraphicsTable_.entry(areaNum_),
                       EditableLeafGraphicsTable::numGraphicTiles,
                       leafBoxColor,
                       2,
                       scale);
    }
    
    // Draw water splash box if enabled
    if (showWaterSplash_) {
      boxGenericLength(dst,
                       waterSplashGraphicTable_.entry(areaNum_, mapNum_)
                        .leftTileIndex(),
                       EditableWaterSplashGraphicTable::numGraphicTiles,
                       waterSplashBoxColor,
                       2,
                       scale);
    }
    
    // Draw smoke puff box if enabled
    if (showSmokePuff_) {
      boxGenericLength(dst,
                       smokePuffGraphicTable_.entry(areaNum_, mapNum_)
                        .leftTileIndex(),
                       EditableSmokePuffGraphicTable::numGraphicTiles,
                       smokePuffBoxColor,
                       2,
                       scale);
    }
  }
  
  // Draw full graphic selection box if enabled
  if (fullSelectionBoxEnabled_) {
    ObjectGraphicSubheader& subheader
      = objectGraphicsHeader.subheader(fullSelectionBoxGraphicIndex_);
    
    int tileIndex = vramAddressToTileIndex(subheader.vdpWriteAddress());
    GGTileSet objectGraphic
      = levelGraphicsData_.compressedGraphic(
          subheader.objectGraphicIndex());
    
    // Box each tile in the graphic
    for (int i = 0; i < objectGraphic.numTiles(); i++) {
      // Calculate position in Graphic
      int xPos = tileIndexToXPos(tileIndex);
      int yPos = tileIndexToYPos(tileIndex);
    
      BoxGraphicSceneObject box(fullGraphicSelectionBoxColor,
                                2,
                                GGTile::width * scale,
                                GGTile::height * scale,
                                xPos * scale,
                                yPos * scale,
                                true);
      
      box.render(dst,
                 Box(0, 0, dst.w(), dst.h()),
                 1.00);
      
      // Move to next tile position
      ++tileIndex;
    }
  }
  
  // Draw selection box if enabled
  if (selectionBoxEnabled_) {
    BoxGraphicSceneObject box(selectionBoxColor,
                              3,
                              GGTile::width * scale,
                              GGTile::height * scale,
                              (selectionBoxX_ - srcbox.x())
                                * GGTile::width * scale,
                              (selectionBoxY_ - srcbox.y())
                                * GGTile::height * scale,
                              true);
    
    box.render(dst,
               Box(0, 0, dst.w(), dst.h()),
               1.00);
  }
  
  // Draw tile picker selection box if enabled
  if (tilePickerPreviewEnabled_) {
      boxGenericLength(dst,
                       tilePickerPreviewIndex_,
                       tilePickerPreviewLength_,
                       tilePickerPreviewColor_,
                       2,
                       scale);
  }
}
コード例 #8
0
ファイル: LevelEditor.cpp プロジェクト: suppertails66/tales
void LevelEditor::drawPreviewGraphic(Graphic& dst) {
//  dst.copy(levelGraphicsData_.compressedGraphic(0).toGrayscaleGraphic(16),
//          Box(0, 0, 0, 0),
//          Graphic::noTransUpdate);

//  levelGraphicsData_.compressedGraphic(0).toGrayscaleGraphic(16)
//    .scale(dst,
//           Graphic::noTransUpdate);

  previewScene_.render(dst,
                       Box(scrollX(),
                           scrollY(),
                           dst.w() / scale(),
                           dst.h() / scale()),
                       scale());

/*  if ((needWrapCacheRefresh_)
      || (wrapScrollCache_.surface().w() != (int)(dst.w() / scale()))
      || (wrapScrollCache_.surface().h() != (int)(dst.h() / scale()))) {
    wrapScrollCache_ = WrapScrollGraphic(dst.w() / scale(),
                                         dst.h() / scale());
//    std::cout << wrapScrollCache_.surface().w() << " " << dst.w() << std::endl;
    previewScene_.render(dst,
                         wrapScrollCache_,
                         Box(scrollX_,
                             scrollY_,
                             dst.w() / scale(),
                             dst.h() / scale()),
                         scale());
    needWrapCacheRefresh_ = false;
    return;
  }
  
  if (lastRenderedScrollX_ != scrollX_) {
    wrapScrollCache_.scrollInX(scrollX_ - lastRenderedScrollX_);
    
    Box scrollBox(scrollX_, scrollY_,
                  scrollX_ - lastRenderedScrollX_,
                  wrapScrollCache_.surface().h());
    // If width is negative, adjust x-position and make width positive
    if (scrollBox.w() < 0) {
      scrollBox.setX(scrollBox.x() + scrollBox.w());
      scrollBox.setW(-(scrollBox.w()));
    }
  
    // Render changed columns
    previewScene_.render(dst,
                         wrapScrollCache_,
                         scrollBox,
                         scale());
  }
  
  if (lastRenderedScrollY_ != scrollY_) {
    wrapScrollCache_.scrollInY(scrollY_ - lastRenderedScrollY_);
    
    Box scrollBox(scrollX_, scrollY_,
                  wrapScrollCache_.surface().w(),
                  scrollY_ - lastRenderedScrollY_);
    // If height is negative, adjust y-position and make height positive
    if (scrollBox.h() < 0) {
      scrollBox.setY(scrollBox.y() + scrollBox.h());
      scrollBox.setH(-(scrollBox.h()));
    }
  
    // Render changed rows
    previewScene_.render(dst,
                         wrapScrollCache_,
                         scrollBox,
                         scale());
  }
                       
  lastRenderedScrollX_ = scrollX_;
  lastRenderedScrollY_ = scrollY_; */
}