本文整理汇总了C++中Tileset::getYOffset方法的典型用法代码示例。如果您正苦于以下问题:C++ Tileset::getYOffset方法的具体用法?C++ Tileset::getYOffset怎么用?C++ Tileset::getYOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tileset
的用法示例。
在下文中一共展示了Tileset::getYOffset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw
void MapperTilesetBox::draw(gcn::Graphics* graphics){
// draw components
InfraellyWindow::draw(graphics);
//draw selection overlay
if( !tilesetList->empty() ){
Tileset *selectedTs = tilesetList->at( tilesetDropDown->getSelected() );
if( selectedTs != NULL ){
if( selectedTs->getImage() != NULL ){
//tile width and height
int tileWidth = selectedTs->getTileWidth();
int tileHeight = selectedTs->getTileHeight();
//calculate amount of px off the screen
int offsetX = tilesetImage->getX();
int offsetY = tilesetImage->getY();
// convert pixel values to row, width
int offCol = offsetX/tileWidth;
int offRow = offsetY/tileHeight;
//get the row and col of the selected tile
int trueCol = selectedTile.getCol();
int trueRow = selectedTile.getRow();
//to find out the reletive row/col to draw to
// we must minus the offscreen tiles from the true tiles co-ords
int drawCol = trueCol + offCol;
int drawRow = trueRow + offRow;
//calculate where to draw in pxs
int drawX = (drawCol * tileWidth) + (tilesetImageScroller->getX() + getFrameSize());
int drawY = (drawRow * tileHeight) + (tilesetImageScroller->getY() + getTitleBarHeight());
//add offsets according to scroller
drawX += offsetX%tileWidth;
drawY += offsetY%tileHeight;
//dimensions of the frame
gcn::Rectangle d( drawX+selectedTs->getXOffset(),
drawY+selectedTs->getYOffset(),
tileWidth, tileHeight );
//only draw if within region
if( ( d.x < tilesetImageScroller->getX()+tilesetImageScroller->getWidth() ) &&
( d.x+d.width > tilesetImageScroller->getX() ) &&
( d.y < tilesetImageScroller->getY()+tilesetImageScroller->getHeight()+getTitleBarHeight() ) &&
( d.y+d.height > tilesetImageScroller->getY()+getTitleBarHeight() )
){
//setcolour to blue
graphics->setColor( gcn::Color( 0, 0, 255) );
//draw a frame
graphics->drawRectangle( d );
//decrease the dimensions by one pixel
++d.x;
++d.y;
d.width -= 2;
d.height -= 2;
//draw another frame (inside prev one)
graphics->drawRectangle( d );
} else {
//not in region, draw a bob
//off the left
if( (d.x+d.width) < tilesetImageScroller->getX() ){
d.x = tilesetImageScroller->getX();
d.y += (tileHeight/2)-5;
};
//off the right
if( d.x > (tilesetImageScroller->getWidth()+tilesetImageScroller->getX()) ){
d.x = tilesetImageScroller->getWidth()-10;
d.y += (tileHeight/2)-5;
};
//off the top
if( (d.y+d.height) < tilesetImageScroller->getY() ){
d.y = tilesetImageScroller->getY()+getTitleBarHeight();
d.x += (tileWidth/2)-5;
};
//off the bottom
if( d.y > (tilesetImageScroller->getHeight()+tilesetImageScroller->getY()+getTitleBarHeight()) ){
d.y = tilesetImageScroller->getY()+tilesetImageScroller->getHeight()+getTitleBarHeight() - 10;
d.x += (tileWidth/2)-5;
};
//draw the bob (5x5px box)
d.width = 10;
d.height = 10;
//setcolour to red
graphics->setColor( gcn::Color( 255, 0, 0) );
graphics->fillRectangle( d );
}
}
}
}
}
示例2: mouseClicked
void MapperTilesetBox::mouseClicked(gcn::MouseEvent& mouseEvent){
InfraellyWindow::mouseClicked(mouseEvent);
if( mouseEvent.isConsumed() ){ return; };
//if click was from closeTilesetButton
if( mouseEvent.getSource() == closeTilesetButton ){
//consume mouse event
mouseEvent.consume();
//get the pointer to the tileset to remove
Tileset *toRemove = tilesetList->at( tilesetDropDown->getSelected() );
//check if the user is trying to dlete teh nullTS
if( toRemove != tilesetList->at(0) ){
//store number to remove
int removeIndex = tilesetDropDown->getSelected();
//change the selected ts to the nullTS
tilesetDropDown->setSelected(0);
//delete the entry from teh list
tilesetList->removeElementAt( removeIndex );
//if there is a map activley associated
if( world != NULL ){
//stip dependency from map working on
//if there IS dependency
if( !world->empty() ){
//cycle through layers
for( size_t i = 0; i < world->size(); ++i ){
//cycle thru tiles
for( size_t j = 0; j < world->getLayer(i).getHeight() * world->getLayer(i).getWidth(); ++j){
if( world->getLayer(i).index(j).getTileset() == toRemove ){
world->getLayer(i).index(j).setTileset(NULL);
}
}
}
}
}
//dependency of tileset stripped
//delete the tileset
cache::tilesets.erase(toRemove);
//remove from selected tile
selectedTile.setSource(NULL,0,0);
}
}
//click from the tilesetImage
if( mouseEvent.getSource() == tilesetImage ){
//consume mouse event
mouseEvent.consume();
if( !tilesetList->empty() ){
Tileset *selectedTs = selectedTile.getTileset();
if( selectedTs != NULL ){
// tileset select
int tileWidth = selectedTs->getTileWidth();
int tileHeight = selectedTs->getTileHeight();
// get the x-y co-ords reletive to the tileset region
int col = mouseEvent.getX() - (tilesetImage->getX()+selectedTs->getXOffset());
int row = mouseEvent.getY() - (tilesetImage->getY()+selectedTs->getYOffset());
// if its a multiple of tilewidth/height (ie in the barrier between)
if( col % tileWidth == 0){ ++col; };
if( row % tileHeight == 0){ ++row; };
// turn co-ords into row/col
col = col/tileWidth;
row = row/tileHeight;
// calculate the amount of tiles off the screen
int trueCol = tilesetImage->getX();
int trueRow = tilesetImage->getY();
// if its a multiple of tilewidth/height (ie in the barrier between)
if( trueCol % tileWidth == 0){ ++col; };
if( trueRow % tileHeight == 0){ ++row; };
// turn co-ords into row/col
trueCol = trueCol/tileWidth;
trueRow = trueRow/tileHeight;
//add the on screen offset to the offsecreen tiles
trueCol += col-1;
trueRow += row-1;
//store the tile's new row-col
selectedTile.setSource( selectedTs, trueCol, trueRow);
//store attribute if on atrib ts
if( selectedTile.getTileset() == attribTs ){
selectedTile.setAttribute(attribGrid[trueCol][trueRow]);
}
}// end if null
}//end if empty list
}//end if event from drop down*/
}