@@ -3229,15 +3229,30 @@ static void draw_flyline_timing_edge(ezgl::point2d start, ezgl::point2d end, flo
3229
3229
ss << 1e9 * incr_delay; // In nanoseconds
3230
3230
std::string incr_delay_str = ss.str ();
3231
3231
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
+
3232
3239
// Set the text colour to black to differentiate it from the line
3233
- g->set_color (ezgl::color (0 , 0 , 0 ));
3234
3240
g->set_font_size (16 );
3241
+ g->set_color (ezgl::color (0 , 0 , 0 ));
3242
+
3243
+ g->set_coordinate_system (ezgl::SCREEN);
3235
3244
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 ));
3237
3248
3249
+ ezgl::point2d offset_text_bbox (x_offset, y_offset);
3238
3250
g->draw_text (offset_text_bbox, incr_delay_str.c_str (), text_bbox.width (), text_bbox.height ());
3239
3251
3240
3252
g->set_font_size (14 );
3253
+
3254
+ g->set_text_rotation (0 );
3255
+ g->set_coordinate_system (ezgl::WORLD);
3241
3256
}
3242
3257
}
3243
3258
0 commit comments