简体   繁体   中英

How can I find out the size of the title bar using SDL?

Faced the following problem: I have a grid and a beam, in the form of a circle. At this stage, you just need to draw them.

Grid::render() :

for (int i = 0; i < cellsInColumn; i++) {
    for (int j = 0; j < cellsInRow; j++) {
        SDL_Rect outlineRect = { this->x + this->bord_x + (cellWidth*j), this->y+this->bord_y, this->cellWidth, this->cellHeight  };
        SDL_RenderDrawRect( this->rend, &outlineRect );
    }
    y+=cellHeight;
}

Beam::render() :

for (int w = 0; w < radius * 2; w++) {
    for (int h = 0; h < radius * 2; h++) {
        double dx = radius - w;
        double dy = radius - h;
        if ((dx*dx + dy*dy) <= (radius * radius)) {
            SDL_RenderDrawPoint(this->rend, x + dx, y + dy);
        }
    }
}

But my screen seems to have "eaten" the top line of the grid. It turned out that the top of the grid, along with the "beam", was drawn under the title bar.

bord_y == 0

bord_y == 70

Question for the connoisseurs : how do I now draw the grid and the circle? Does the SDL know how many pixels are in the title bar, or should this indent be "by eye"? If it knows, where is this information stored?

UPD :

Grid and beam values are set in the following function:

void setStartValues(int screenWidth, int screenHeight){
    Grid::setBord(screenWidth, screenHeight);
    Grid::setCellSize(screenHeight);

    Beam::setValues(Grid::getCellHeight(), Grid::getBord());

}

And here are all the getters and setters that are used above:

void setBord(int scrW, int scrH) {
    this->bord_x = this->cellsInRow <= this->cellsInColumn? (scrW-scrH)/2 : (scrW-scrH)/6;
    this->bord_y = 0;
}

void setCellSize(int scrH) {
    this->cellWidth = this->cellHeight = scrH/cellsInColumn;
}

double getCellHeight() {
    return this->cellHeight;
}

double getBord() {
    return this->bord_x;
}

void setValues(double cellH, double bord) { //Beam
    this->x = cellH/2 + bord;
    this->y = cellH/2;
    this->radius = cellH/4;
}

The best I could come up with was to hardcode the upper bound values ( bord_y ). 40 for grid and 80 for beam.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM