Skip to content

Commit 6cf5883

Browse files
dpbainesvaughnbetz
authored andcommitted
Rotate and offset text independent of zoom, using screen coordinates
1 parent aff3410 commit 6cf5883

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

vpr/src/draw/draw.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3229,15 +3229,30 @@ static void draw_flyline_timing_edge(ezgl::point2d start, ezgl::point2d end, flo
32293229
ss << 1e9 * incr_delay; //In nanoseconds
32303230
std::string incr_delay_str = ss.str();
32313231

3232+
// Get the angle of line, to rotate the text
3233+
float text_angle = (180/M_PI) * atan((end.y - start.y)/(end.x - start.x));
3234+
3235+
// Get the screen coordinates for text drawing
3236+
ezgl::rectangle screen_coords = g->world_to_screen(text_bbox);
3237+
g->set_text_rotation(text_angle);
3238+
32323239
// Set the text colour to black to differentiate it from the line
3233-
g->set_color(ezgl::color(0, 0, 0));
32343240
g->set_font_size(16);
3241+
g->set_color(ezgl::color(0, 0, 0));
3242+
3243+
g->set_coordinate_system(ezgl::SCREEN);
32353244

3236-
ezgl::point2d offset_text_bbox(text_bbox.center().x + 2, text_bbox.center().y + 2);
3245+
// Find an offset so it is sitting on top/below of the line
3246+
float x_offset = screen_coords.center().x - 8 * sin(text_angle * (M_PI/180));
3247+
float y_offset = screen_coords.center().y - 8 * cos(text_angle * (M_PI/180));
32373248

3249+
ezgl::point2d offset_text_bbox(x_offset, y_offset);
32383250
g->draw_text(offset_text_bbox, incr_delay_str.c_str(), text_bbox.width(), text_bbox.height());
32393251

32403252
g->set_font_size(14);
3253+
3254+
g->set_text_rotation(0);
3255+
g->set_coordinate_system(ezgl::WORLD);
32413256
}
32423257
}
32433258

0 commit comments

Comments
 (0)