MCPcopy Create free account
hub / github.com/ErrorFlynn/ytdlp-interface / create

Method create

ytdlp-interface/progress_ex.cpp:5–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3
4
5bool nana::progress_ex::create(window parent, const rectangle &r, bool visible, nana::form *pform)
6{
7 main_thread_id = std::this_thread::get_id();
8 parent_form = pform;
9 if(pform)
10 parent_hwnd = reinterpret_cast<HWND>(pform->native_handle());
11
12 if(progress::create(parent, r, visible))
13 {
14 typeface(paint::font_info {typeface().name(), typeface().size(), paint::font::font_style{800}});
15 presets[color_presets::nana] = {
16 scheme().lower_foreground, scheme().foreground, scheme().background, scheme().lower_background
17 };
18
19 drawing(*this).draw([this](paint::graphics &graph)
20 {
21 if(!img.empty() && !graph.empty())
22 {
23 const double unit {static_cast<double>(amount()) / static_cast<double>(graph.width() - 2)};
24 unsigned pixels {static_cast<unsigned>(static_cast<double>(value()) / unit)};
25 if(value() == amount()) pixels = graph.width();
26 paint::graphics g {{pixels + 1, graph.height() - 2}};
27 if(img.alpha())
28 g.bitblt({0, 0, pixels + 1, graph.height()}, graph, {0, 1});
29 unsigned img_h {graph.height() - 2}, img_w {img.size().width};
30 if(img_h > img.size().height)
31 img_w += img_h - img.size().height;
32
33 for(int x {0}; x < g.width(); x += img_w)
34 img.stretch(rectangle {img.size()}, g, rectangle {x, 0, img_w, img_h});
35 graph.bitblt({1, 1, pixels, g.height()}, g);
36 if(darkbg)
37 graph.frame_rectangle(rectangle {graph.size()}, color {"#777"}, 0);
38 auto width {graph.width()}, height {graph.height()};
39 if(shadow_amount)
40 {
41 const double unit {static_cast<double>(shadow_amount) / static_cast<double>(width - 2)};
42 const unsigned pixels {static_cast<unsigned>(static_cast<double>(shadow_value) / unit) + 2};
43 rectangle r { 1, 1, pixels, height };
44 graph.blend(r, colors::grey, darkbg ? .3 : .2);
45 }
46 }
47
48 switch(tmode)
49 {
50 case text_modes::caption:
51 if(!text.empty())
52 render_text(graph, text);
53 break;
54
55 case text_modes::value:
56 if(!unknown())
57 render_text(graph, std::to_string(value()) + " / " + std::to_string(amount()));
58 break;
59
60 case text_modes::percentage:
61 if(!unknown())
62 render_text(graph, std::to_string(value() / (amount() / 100)) + '%');

Callers

nothing calls this directly

Calls 8

createFunction · 0.85
schemeClass · 0.85
valueFunction · 0.85
to_stringFunction · 0.85
native_handleMethod · 0.80
drawMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected