void GraphCanvas::DrawGraph(int x, int y, int w, int h) const { if (!IsVisible()) return; Surface &surface = GetMainWindow(); uint graph_h = h-xaxis.GetHeight()-8; uint graph_w = w-yaxis.GetWidth()-8; uint graph_x = x+yaxis.GetWidth()+8; if (!results.empty()) { // Value to determine normalization float max_value = 0; float xmax = 0; float xmin = std::numeric_limits<float>::max(); for (uint i=0; i<results.size(); i++) { if (results[i].ymax > max_value) max_value = results[i].ymax; if (results[i].xmax > xmax) xmax = results[i].xmax; if (results[i].list[0].first < xmin) xmin = results[i].list[0].first; } // needed to see correctly energy at the end if two teams have same // energy just before the final blow xmax += xmax/50.0f; char buffer[16]; snprintf(buffer, 16, "%.1f", xmax); surface.Blit(Font::GetInstance(Font::FONT_MEDIUM, Font::FONT_BOLD)->CreateSurface(buffer, black_color), Point2i(x+graph_w-20, y+graph_h+8)); #if 0 // Display max y snprintf(buffer, 16, "%.1f", max_value); surface.Blit(Font::GetInstance(Font::FONT_MEDIUM, Font::FONT_BOLD)->CreateSurface(buffer, black_color), Point2i(x+4, y+8)); #endif // Draw each team graph float yscale = graph_h / (1.05f*max_value); float xscale = graph_w / (1.05f*(xmax-xmin)); for (uint i=0; i<results.size(); i++) { if (results[i].item) { // Legend line surface.BoxColor(Rectanglei(x+w-112, y+12+i*40, 56, thickness), results[i].color); // Legend icon surface.Blit(*results[i].item, Point2i(x+w-48, y+12+i*40-20)); } DrawGraph(i, xmax, xmin, graph_x, xscale, y+graph_h, yscale); } } // Draw here the axis surface.BoxColor(Rectanglei(graph_x, y, thickness, graph_h), black_color); surface.BoxColor(Rectanglei(graph_x, y+graph_h, graph_w, thickness), black_color); surface.Blit(xaxis, Point2i(graph_x+graph_w/2, y+graph_h+8)); surface.Blit(yaxis, Point2i(x+4, y+graph_h/2)); }
void PictureWidget::Draw(const Point2i &/*mousePosition*/) { if (!loaded) { if (name.empty()) return; Profile *res = GetResourceManager().LoadXMLProfile("graphism.xml", false); SetSurface(LOAD_RES_IMAGE(name), type); // Needed to set the resizing ApplyScaling(type); } if (!spr) return; Surface & surf = GetMainWindow(); Point2i pos = GetPicturePosition(); spr->Blit(surf, pos); // Draw a transparency mask if (disabled) { surf.BoxColor(Rectanglei(pos, spr->GetSize()), defaultOptionColorBox); } }
void Font::Write(const Point2i & pos, const Surface & surface) const { GetMainWindow().Blit(surface, pos); // TODO: Remove this line! (and use GameFont instead of Font) GetWorld().ToRedrawOnScreen( Rectanglei(pos, surface.GetSize()) ); }
Rectanglei QtNativeFont::nativeFontMeasure(String const &text) const { Rectanglei rect = Rectanglei::fromQRect(d->metrics->boundingRect(text)); if(rect.height() == 0) { // It seems measuring the bounds of a Tab character produces // strange results (position 100000?). rect = Rectanglei(0, 0, rect.width(), 0); } return rect; }
void GraphCanvas::DrawGraph(uint i, float xmax, float xmin, int x, float xscale, int y, float yscale) const { const Result &res = results[i]; const Color& color = res.color; if (!res.list.size()) { MSG_DEBUG("menu", " No point !?!"); return; } int sx = x+int((res.list[0].first-xmin)*xscale)+thickness, sy = y-int(res.list[0].second*yscale); Surface &surface = GetMainWindow(); MSG_DEBUG("menu", " First point: (%.3f,%.3f) -> (%i,%i)", res.list[0].first, res.list[0].second, sx, sy); for (uint i=0; i<res.list.size(); i++) { const Value& val = res.list[i]; int ex = x+int((val.first-xmin)*xscale), ey = y-int(val.second*yscale); MSG_DEBUG("menu", " Next point: (%.3f,%.3f) -> (%i,%i)", val.first, val.second, ex, ey); surface.BoxColor(Rectanglei(sx, sy, ex-sx, thickness), color); surface.BoxColor(Rectanglei(ex, std::min(sy,ey), thickness, abs(ey-sy)), color); sx = ex; sy = ey; } // Missing point if (res.list[res.list.size()-1].first < xmax) { int ex = x+int((xmax-xmin)*xscale); MSG_DEBUG("menu", " Last point -> (%i,%i)", ex, sy); surface.BoxColor(Rectanglei(sx, sy, ex-sx, thickness), color); } }
Rectanglei ScrollBox::GetScrollThumb() const { // Height: (part of the vbox that is displayed / vbox size) * scrollbar height const Rectanglei& scroll_track = GetScrollTrack(); uint tmp_h = ((size.y - 2*border_size) * scroll_track.GetSizeY()) / ((size.y - 2*border_size) + GetMaxOffset()); // Start position: from the offset uint h = size.y + GetMaxOffset(); uint tmp_y = scroll_track.GetPositionY() + (offset * scroll_track.GetSizeY() + h/2) / h; if (tmp_h < 6) tmp_h = 6; return Rectanglei(scroll_track.GetPositionX(), tmp_y, scrollbar_width, tmp_h); }
void CompositeShape::DrawOnScreen() { Point2d min, max; Point2i tmp; int i = 0; for(std::vector<Polygon *>::iterator poly = layers.begin(); poly != layers.end(); poly++, i++) { (*poly)->Draw(&GetMainWindow()); if(i == 0) { min = (*poly)->GetMin(); max = (*poly)->GetMax(); } else { min = min.min((*poly)->GetMin()); max = max.max((*poly)->GetMax()); } } tmp = Point2i(max) - Point2i(min) + 1; GetWorld().ToRedrawOnScreen(Rectanglei(Point2i(min), Point2i(tmp) + 2)); }
TileGridView TileGrid::default_view() { return TileGridView(*this, Rectanglei(0, 0, m_width, m_height)); }
/** * Submits the image to the backing store, or commits it if no backing * store is available. * * @param image Image. * @param rect Rectangle for the image determined by an IAllocator. */ void submitImage(Image const &image, Rectanglei const &rect) { Rectanglei const noBorders = rect.shrunk(border); Rectanglei const withMargin = rect.expanded(margin); if (hasBacking()) { // The margin is cleared to transparent black. backing.fill(withMargin, Image::Color(0, 0, 0, 0)); if (border > 0) { if (flags.testFlag(WrapBordersInBackingStore)) { // Wrap using the source image (left, right, top, bottom edges). backing.drawPartial(image, Rectanglei(0, 0, border, image.height()), rect.topRight() + Vector2i(-border, border)); backing.drawPartial(image, Rectanglei(image.width() - border, 0, border, image.height()), rect.topLeft + Vector2i(0, border)); backing.drawPartial(image, Rectanglei(0, 0, image.width(), border), rect.bottomLeft() + Vector2i(border, -border)); backing.drawPartial(image, Rectanglei(0, image.height() - border, image.width(), border), rect.topLeft + Vector2i(border, 0)); } } backing.draw(image, noBorders.topLeft); //backing.toQImage().save(QString("backing-%1.png").arg(uint64_t(this))); markAsChanged(rect); } else { // No backing, must commit immediately. if (border > 0) { // Expand with borders (repeat edges). QImage const srcImg = image.toQImage(); int const sw = srcImg.width(); int const sh = srcImg.height(); QImage bordered(QSize(rect.width(), rect.height()), srcImg.format()); int const w = bordered.width(); int const h = bordered.height(); QPainter painter(&bordered); painter.setCompositionMode(QPainter::CompositionMode_Source); painter.fillRect(bordered.rect(), QColor(0, 0, 0, 0)); /// @todo This really only works for a border of 1 pixels. Should /// repeat the same outmost edge pixels for every border. -jk painter.drawImage(border, border, srcImg); painter.drawImage(border, 0, srcImg, 0, 0, sw, 1); // top painter.drawImage(border, h - 1, srcImg, 0, sh - 1, sw, 1); // bottom painter.drawImage(0, border, srcImg, 0, 0, 1, sh); // left painter.drawImage(w - 1, border, srcImg, sw - 1, 0, 1, sh); // right // Corners. painter.drawImage(0, 0, srcImg, 0, 0, 1, 1); painter.drawImage(w - 1, 0, srcImg, sw - 1, 0, 1, 1); painter.drawImage(0, h - 1, srcImg, 0, sh - 1, 1, 1); painter.drawImage(w - 1, h - 1, srcImg, sw - 1, sh - 1, 1, 1); self().commit(bordered, rect.topLeft); } else { self().commit(image, noBorders.topLeft); } } }