Exemple #1
0
int MapsWindow::MapArea::mousePosToMapIndex(int x, int y)
{
    int offsetX = x/SIZE_; // offsetX is map index on line
    if (offsetX < mapsPerLine())
    {
        int index = mapsPerLine()*((pos_ + y)/SIZE_) + offsetX;
        if (index < names_.size())
        {
            return index;
        }
    }
    return -1;
}
Exemple #2
0
void MapsWindow::MapArea::draw()
{
    fl_color(FL_BACKGROUND_COLOR);
    fl_rectf(0, 0, w(), h());

    int line = pos_/SIZE_;
    int first = line*mapsPerLine();

    int x = 0;
    int y = line*SIZE_ - pos_;
    for (int i=first; i<images_.size(); ++i)
    {
        auto im = images_[i];
        if (x > (w()-SIZE_) && x != 0)
        {
            x = 0;
            y += SIZE_;
        }

        if (y > h())
            break;

        if (im)
            im->draw(x + SIZE_/2 - im->w()/2, y + SIZE_/2 - im->h()/2);

        x += SIZE_;
    }
}
Exemple #3
0
void MapsWindow::MapArea::updateMapInfoWin(int x, int y)
{
    int offsetX = x/SIZE_; // offsetX is map index on line
    if (offsetX < mapsPerLine())
    {
        int index = mapsPerLine()*((pos_ + y)/SIZE_) + offsetX;
        if (index < names_.size())
        {
            std::ostringstream oss;
            oss << names_[index];
            mapInfoWin_->position(Fl::event_x_root(), Fl::event_y_root()+20);
            mapInfoWin_->info(oss.str());
            mapInfoWin_->show();
            return;
        }
    }

    mapInfoWin_->hide();
}
Exemple #4
0
int MapsWindow::MapArea::lines() const
{
    int const lines = 1 + names_.size()/mapsPerLine();
    return lines;
}