8
8
#include < string>
9
9
#include < thread>
10
10
#include " ffmpeg.h"
11
+ #include " controls.h"
11
12
#include " source_code_pro_regular_ttf.h"
12
13
#include " string_utils.h"
13
14
extern " C" {
@@ -23,6 +24,8 @@ static const SDL_Color LOOP_OFF_LABEL_COLOR = {0, 0, 0, 0};
23
24
static const SDL_Color LOOP_FW_LABEL_COLOR = {80 , 127 , 255 , 0 };
24
25
static const SDL_Color LOOP_PP_LABEL_COLOR = {191 , 95 , 60 , 0 };
25
26
static const SDL_Color TEXT_COLOR = {255 , 255 , 255 , 0 };
27
+ static const SDL_Color HELP_TEXT_PRIMARY_COLOR = {255 , 255 , 255 , 0 };
28
+ static const SDL_Color HELP_TEXT_ALTERNATE_COLOR = {255 , 255 , 192 , 0 };
26
29
static const SDL_Color POSITION_COLOR = {255 , 255 , 192 , 0 };
27
30
static const SDL_Color TARGET_COLOR = {200 , 200 , 140 , 0 };
28
31
static const SDL_Color ZOOM_COLOR = {255 , 165 , 0 , 0 };
@@ -231,6 +234,34 @@ Display::Display(const int display_number,
231
234
232
235
diff_planes_ = {diff_plane_0, nullptr , nullptr };
233
236
diff_pitches_ = {video_width_ * 3 * (use_10_bpc ? sizeof (uint16_t ) : sizeof (uint8_t )), 0 , 0 };
237
+
238
+ // initialize help texts
239
+ bool primary_color = true ;
240
+
241
+ auto add_help_texture = [&](const std::string& text) {
242
+ SDL_Surface* surface = TTF_RenderText_Blended_Wrapped (small_font_, text.c_str (), primary_color ? HELP_TEXT_PRIMARY_COLOR : HELP_TEXT_ALTERNATE_COLOR, drawable_width_ - 20 );
243
+ SDL_Texture* texture = SDL_CreateTextureFromSurface (renderer_, surface);
244
+ int h;
245
+ SDL_QueryTexture (texture, NULL , NULL , NULL , &h);
246
+ help_textures_.push_back (texture);
247
+ SDL_FreeSurface (surface);
248
+
249
+ help_total_height_ += h;
250
+ primary_color = !primary_color;
251
+ };
252
+
253
+ add_help_texture (" Controls:" );
254
+ add_help_texture (" " );
255
+
256
+ for (auto & key_description_pair : get_controls ()) {
257
+ add_help_texture (string_sprintf (" %-12s %s" , key_description_pair.first .c_str (), key_description_pair.second .c_str ()));
258
+ }
259
+
260
+ add_help_texture (" " );
261
+
262
+ for (auto & text : get_instructions ()) {
263
+ add_help_texture (text);
264
+ }
234
265
}
235
266
236
267
Display::~Display () {
@@ -242,6 +273,10 @@ Display::~Display() {
242
273
SDL_DestroyTexture (message_texture_);
243
274
}
244
275
276
+ for (auto help_texture : help_textures_) {
277
+ SDL_DestroyTexture (help_texture);
278
+ }
279
+
245
280
TTF_CloseFont (small_font_);
246
281
TTF_CloseFont (big_font_);
247
282
@@ -526,6 +561,23 @@ std::string Display::get_and_format_rgb_yuv_pixel(uint8_t* rgb_plane, const size
526
561
return " RGB" + format_pixel (rgb) + " , YUV" + format_pixel (yuv);
527
562
}
528
563
564
+ void Display::render_help () {
565
+ int y = help_y_offset_; // yOffset
566
+
567
+ SDL_SetRenderDrawBlendMode (renderer_, SDL_BLENDMODE_BLEND);
568
+ SDL_SetRenderDrawColor (renderer_, 0 , 0 , 0 , 160 );
569
+ SDL_Rect rect = {0 , 0 , drawable_width_, drawable_height_};
570
+ SDL_RenderFillRect (renderer_, &rect);
571
+
572
+ for (size_t i = 0 ; i < help_textures_.size (); i++) {
573
+ int w, h;
574
+ SDL_QueryTexture (help_textures_[i], NULL , NULL , &w, &h);
575
+ SDL_Rect dst = {10 , y, w, h};
576
+ SDL_RenderCopy (renderer_, help_textures_[i], NULL , &dst);
577
+ y += h + 5 ;
578
+ }
579
+ }
580
+
529
581
void Display::refresh (std::array<uint8_t *, 3 > planes_left,
530
582
std::array<size_t , 3 > pitches_left,
531
583
std::array<size_t , 2 > original_dims_left,
@@ -942,6 +994,10 @@ void Display::refresh(std::array<uint8_t*, 3> planes_left,
942
994
}
943
995
}
944
996
997
+ if (show_help_) {
998
+ render_help ();
999
+ }
1000
+
945
1001
SDL_RenderPresent (renderer_);
946
1002
}
947
1003
@@ -1034,6 +1090,10 @@ void Display::input() {
1034
1090
1035
1091
update_move_offset (move_offset_ + pan_offset);
1036
1092
}
1093
+
1094
+ help_y_offset_ += -event_.motion .yrel * (help_total_height_ * 3 / drawable_height_);
1095
+ help_y_offset_ = std::max (help_y_offset_, drawable_height_ - help_total_height_ - int (help_textures_.size ()) * 5 );
1096
+ help_y_offset_ = std::min (help_y_offset_, 0 );
1037
1097
break ;
1038
1098
case SDL_MOUSEBUTTONDOWN:
1039
1099
if (event_.button .button != SDL_BUTTON_RIGHT) {
@@ -1043,6 +1103,9 @@ void Display::input() {
1043
1103
break ;
1044
1104
case SDL_KEYDOWN:
1045
1105
switch (event_.key .keysym .sym ) {
1106
+ case SDLK_h:
1107
+ show_help_ = !show_help_;
1108
+ break ;
1046
1109
case SDLK_ESCAPE:
1047
1110
quit_ = true ;
1048
1111
break ;
0 commit comments