[Mesa-dev] [PATCH 5/6] gallium/hud: generalize code for drawing numbers next to graphs
Marek Olšák
maraeo at gmail.com
Thu Aug 18 19:56:32 UTC 2016
From: Marek Olšák <marek.olsak at amd.com>
---
src/gallium/auxiliary/hud/hud_context.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
index f7baccd..ac971d8 100644
--- a/src/gallium/auxiliary/hud/hud_context.c
+++ b/src/gallium/auxiliary/hud/hud_context.c
@@ -337,33 +337,35 @@ hud_draw_graph_line_strip(struct hud_context *hud, const struct hud_graph *gr,
}
static void
hud_pane_accumulate_vertices(struct hud_context *hud,
const struct hud_pane *pane)
{
struct hud_graph *gr;
float *line_verts = hud->whitelines.vertices + hud->whitelines.num_vertices*2;
unsigned i, num = 0;
char str[32];
+ const unsigned last_line = 5;
/* draw background */
hud_draw_background_quad(hud,
pane->x1, pane->y1,
pane->x2, pane->y2);
/* draw numbers on the right-hand side */
- for (i = 0; i < 6; i++) {
+ for (i = 0; i <= last_line; i++) {
unsigned x = pane->x2 + 2;
- unsigned y = pane->inner_y1 + pane->inner_height * (5 - i) / 5 -
+ unsigned y = pane->inner_y1 +
+ pane->inner_height * (last_line - i) / last_line -
hud->font.glyph_height / 2;
- number_to_human_readable(pane->max_value * i / 5, pane->max_value,
+ number_to_human_readable(pane->max_value * i / last_line, pane->max_value,
pane->type, str);
hud_draw_string(hud, x, y, "%s", str);
}
/* draw info below the pane */
i = 0;
LIST_FOR_EACH_ENTRY(gr, &pane->graph_list, head) {
unsigned x = pane->x1 + 2;
unsigned y = pane->y2 + 2 + i*hud->font.glyph_height;
@@ -389,22 +391,23 @@ hud_pane_accumulate_vertices(struct hud_context *hud,
line_verts[num++] = (float) pane->y2;
line_verts[num++] = (float) pane->x2;
line_verts[num++] = (float) pane->y2;
line_verts[num++] = (float) pane->x1;
line_verts[num++] = (float) pane->y1;
line_verts[num++] = (float) pane->x1;
line_verts[num++] = (float) pane->y2;
/* draw horizontal lines inside the graph */
- for (i = 0; i <= 5; i++) {
- float y = round((pane->max_value * i / 5.0) * pane->yscale + pane->inner_y2);
+ for (i = 0; i <= last_line; i++) {
+ float y = round((pane->max_value * i / (double)last_line) *
+ pane->yscale + pane->inner_y2);
assert(hud->whitelines.num_vertices + num/2 + 2 <= hud->whitelines.max_num_vertices);
line_verts[num++] = pane->x1;
line_verts[num++] = y;
line_verts[num++] = pane->x2;
line_verts[num++] = y;
}
hud->whitelines.num_vertices += num/2;
}
--
2.7.4
More information about the mesa-dev
mailing list