27
27
28
28
#include < godot_cpp/classes/button.hpp>
29
29
#include < godot_cpp/classes/editor_inspector.hpp>
30
+ #include < godot_cpp/classes/gradient.hpp>
31
+ #include < godot_cpp/classes/gradient_texture2d.hpp>
30
32
#include < godot_cpp/classes/input.hpp>
31
33
#include < godot_cpp/classes/input_event_action.hpp>
32
34
#include < godot_cpp/classes/input_event_mouse_button.hpp>
36
38
#include < godot_cpp/classes/script_editor.hpp>
37
39
#include < godot_cpp/classes/script_editor_base.hpp>
38
40
#include < godot_cpp/classes/style_box_flat.hpp>
41
+ #include < godot_cpp/classes/style_box_texture.hpp>
39
42
40
43
OrchestratorGraphNode::OrchestratorGraphNode (OrchestratorGraphEdit* p_graph, const Ref<OScriptNode>& p_node)
41
44
{
@@ -341,37 +344,68 @@ void OrchestratorGraphNode::_update_styles()
341
344
apply_style_defaults = false ;
342
345
Color color = os->get_setting (key);
343
346
344
- Ref<StyleBoxFlat > panel = _make_colored_style (" panel_selected" , color);
347
+ Ref<StyleBox > panel = _make_colored_style (" panel_selected" , color);
345
348
if (panel.is_valid ())
346
349
add_theme_stylebox_override (" panel" , panel);
347
350
348
- Ref<StyleBoxFlat > panel_selected = _make_selected_style (" panel" );
351
+ Ref<StyleBox > panel_selected = _make_selected_style (" panel" );
349
352
if (panel_selected.is_valid ())
350
353
add_theme_stylebox_override (" panel_selected" , panel_selected);
351
354
352
- Ref<StyleBoxFlat> titlebar = _make_colored_style (" titlebar_selected" , color, true );
353
- if (titlebar.is_valid ())
354
- add_theme_stylebox_override (" titlebar" , titlebar);
355
+ if (_use_gradient_color_style ())
356
+ {
357
+ Ref<StyleBox> sb = _make_colored_style (" titlebar_selected" , color, true );
358
+ if (sb.is_valid ())
359
+ add_theme_stylebox_override (" titlebar" , sb);
360
+
361
+ Ref<StyleBox> sb_selected = _make_selected_style (" titlebar" , true );
362
+ if (sb_selected.is_valid ())
363
+ add_theme_stylebox_override (" titlebar_selected" , sb_selected);
364
+
365
+ Ref<StyleBox> sb2 = _make_gradient_titlebar_style (" titlebar_selected" , color, false );
366
+ if (sb2.is_valid ())
367
+ add_theme_stylebox_override (" titlebar" , sb2);
368
+ }
369
+ else
370
+ {
371
+ Ref<StyleBox> sb = _make_colored_style (" titlebar_selected" , color, true );
372
+ if (sb.is_valid ())
373
+ add_theme_stylebox_override (" titlebar" , sb);
355
374
356
- Ref<StyleBoxFlat> titlebar_selected = _make_selected_style (" titlebar" , true );
357
- if (titlebar_selected.is_valid ())
358
- add_theme_stylebox_override (" titlebar_selected" , titlebar_selected);
375
+ Ref<StyleBox> sb_selected = _make_selected_style (" titlebar" , true );
376
+ if (sb_selected.is_valid ())
377
+ add_theme_stylebox_override (" titlebar_selected" , sb_selected);
378
+ }
359
379
}
360
380
}
361
381
362
382
if (apply_style_defaults)
363
383
{
364
- Ref<StyleBoxFlat > panel_selected = _make_selected_style (" panel_selected" );
384
+ Ref<StyleBox > panel_selected = _make_selected_style (" panel_selected" );
365
385
if (panel_selected.is_valid ())
366
386
add_theme_stylebox_override (" panel_selected" , panel_selected);
367
387
368
- Ref<StyleBoxFlat > titlebar_selected = _make_selected_style (" titlebar_selected" , true );
388
+ Ref<StyleBox > titlebar_selected = _make_selected_style (" titlebar_selected" , true );
369
389
if (titlebar_selected.is_valid ())
370
390
add_theme_stylebox_override (" titlebar_selected" , titlebar_selected);
371
391
}
372
392
}
373
393
374
- Ref<StyleBoxFlat> OrchestratorGraphNode::_make_colored_style (const String& p_existing_name, const Color& p_color, bool p_titlebar)
394
+ Color OrchestratorGraphNode::_get_selection_color () const
395
+ {
396
+ return { 0 .68f , 0 .44f , 0 .09f };
397
+ }
398
+
399
+ bool OrchestratorGraphNode::_use_gradient_color_style () const
400
+ {
401
+ OrchestratorSettings* os = OrchestratorSettings::get_singleton ();
402
+ if (os)
403
+ return os->get_setting (" ui/nodes/titlebar/use_gradient_colors" , false );
404
+
405
+ return false ;
406
+ }
407
+
408
+ Ref<StyleBox> OrchestratorGraphNode::_make_colored_style (const String& p_existing_name, const Color& p_color, bool p_titlebar)
375
409
{
376
410
Ref<StyleBoxFlat> sb = get_theme_stylebox (p_existing_name);
377
411
if (sb.is_valid ())
@@ -381,26 +415,98 @@ Ref<StyleBoxFlat> OrchestratorGraphNode::_make_colored_style(const String& p_exi
381
415
dup->set_bg_color (p_color);
382
416
else
383
417
dup->set_border_color (p_color);
418
+
419
+ _apply_corner_radius (dup, p_titlebar);
420
+
384
421
return dup;
385
422
}
386
423
return sb;
387
424
}
388
425
389
- Ref<StyleBoxFlat > OrchestratorGraphNode::_make_selected_style (const String& p_existing_name, bool p_titlebar)
426
+ Ref<StyleBox > OrchestratorGraphNode::_make_selected_style (const String& p_existing_name, bool p_titlebar)
390
427
{
391
428
Ref<StyleBoxFlat> sb = get_theme_stylebox (p_existing_name);
392
429
if (sb.is_valid ())
393
430
{
394
431
Ref<StyleBoxFlat> dup = sb->duplicate (true );
395
- dup->set_border_color (Color ( 0 . 68f , 0 . 44f , 0 . 09f ));
432
+ dup->set_border_color (_get_selection_color ( ));
396
433
dup->set_border_width (p_titlebar ? SIDE_TOP : SIDE_BOTTOM, 2 );
397
434
dup->set_border_width (SIDE_LEFT, 2 );
398
435
dup->set_border_width (SIDE_RIGHT, 2 );
436
+
437
+ _apply_corner_radius (dup, p_titlebar);
438
+
399
439
return dup;
400
440
}
401
441
return sb;
402
442
}
403
443
444
+ Ref<StyleBox> OrchestratorGraphNode::_make_gradient_titlebar_style (const String& p_existing_name, const Color& p_color,
445
+ bool p_selected)
446
+ {
447
+ Ref<Gradient> gradient (memnew (Gradient));
448
+
449
+ PackedFloat32Array offsets;
450
+ offsets.push_back (0 );
451
+ offsets.push_back (1 );
452
+ gradient->set_offsets (offsets);
453
+
454
+ PackedColorArray colors = gradient->get_colors ();
455
+ colors.reverse ();
456
+ gradient->set_colors (colors);
457
+
458
+ Ref<GradientTexture2D> texture (memnew (GradientTexture2D));
459
+ texture->set_gradient (gradient);
460
+ texture->set_width (64 );
461
+ texture->set_height (64 );
462
+ texture->set_fill_to (Vector2 (1.1 , 0 ));
463
+
464
+ Ref<StyleBoxTexture> titlebar_tex (memnew (StyleBoxTexture));
465
+ titlebar_tex->set_texture (texture);
466
+ titlebar_tex->set_modulate (p_color);
467
+
468
+ Ref<StyleBox> sb = get_theme_stylebox (p_existing_name);
469
+ if (sb.is_valid ())
470
+ {
471
+ titlebar_tex->set_content_margin (SIDE_TOP, sb->get_content_margin (SIDE_TOP));
472
+ titlebar_tex->set_content_margin (SIDE_RIGHT, sb->get_content_margin (SIDE_RIGHT));
473
+ titlebar_tex->set_content_margin (SIDE_BOTTOM, sb->get_content_margin (SIDE_BOTTOM));
474
+ titlebar_tex->set_content_margin (SIDE_LEFT, sb->get_content_margin (SIDE_LEFT));
475
+ }
476
+
477
+ if (p_selected)
478
+ titlebar_tex->set_modulate (_get_selection_color ());
479
+
480
+ return titlebar_tex;
481
+ }
482
+
483
+ void OrchestratorGraphNode::_apply_corner_radius (Ref<StyleBoxFlat>& p_stylebox, bool p_titlebar)
484
+ {
485
+ if (p_stylebox.is_valid () && _use_gradient_color_style ())
486
+ {
487
+ // In this case, we explicitly only support a border radius of 6 on the bottom part.
488
+ p_stylebox->set_corner_radius (CORNER_BOTTOM_LEFT, 6 );
489
+ p_stylebox->set_corner_radius (CORNER_BOTTOM_RIGHT, 6 );
490
+ return ;
491
+ }
492
+
493
+ OrchestratorSettings* os = OrchestratorSettings::get_singleton ();
494
+ if (p_stylebox.is_valid () && os)
495
+ {
496
+ int border_radius = os->get_setting (" ui/nodes/border_radius" , 6 );
497
+ if (p_titlebar)
498
+ {
499
+ p_stylebox->set_corner_radius (CORNER_TOP_LEFT, border_radius);
500
+ p_stylebox->set_corner_radius (CORNER_TOP_RIGHT, border_radius);
501
+ }
502
+ else
503
+ {
504
+ p_stylebox->set_corner_radius (CORNER_BOTTOM_LEFT, border_radius);
505
+ p_stylebox->set_corner_radius (CORNER_BOTTOM_RIGHT, border_radius);
506
+ }
507
+ }
508
+ }
509
+
404
510
void OrchestratorGraphNode::_update_node_attributes ()
405
511
{
406
512
// Attempt to shrink the container
0 commit comments