SimulationState_Button.cpp
Go to the documentation of this file.
2 #include "../Defs.hpp"
3 
4 using namespace iv;
5 
6 namespace comp
7 {
8 
9 SimulationState_Button::SimulationState_Button( iv::Instance * inst, SimulationState * sim, LumaStyleId style_id ) :
10  LumaButton( inst, style_id ),
11  cm( inst, this, "SimulationState_Button" ),
12  sim( sim ),
13  heap( inst, &this->cm ),
14  anim( inst ),
15  previous_state( SimulationState::Empty )
16 {
17  this->cm.inherits( this->iv::LumaButton::cm );
18  this->cm.owns( this->anim.cm );
19 
20  this->sufraceNeutralColor( float4( 0.384, 0.000, 0.933, 1 ) );
21  this->attr_surface.Set( "/CoreModels/Simulation/SimulationState_Button/surface.png" );
22  this->attr_hot.Set( "/CoreModels/Simulation/SimulationState_Button/hot.png" );
23 
24  //----------- input ---------------------------------------------------------------
25  auto activation =
27  &this->cm,
28  [ this, sim ]()
29  {
31  if( st == SimulationState::Paused )
32  sim->pause.Modify( &this->cm, false );
33  else if( st == SimulationState::Running )
34  sim->pause.Modify( &this->cm, true );
35  else
36  sim->restart.Modify( &this->cm, sim->restart.Get().MakeActivated() );
37  }
38  );
39 
40  //
41  this->input.field_release.Assign_Attribute_RW( activation );
42 
43  //
45  space_key->field_press.Assign_Attribute_RW( activation );
46  this->Add_InputNode( space_key );
47 
48  //----- visuals -------------------------------------------------------------------
49  this->border = this->surface_slot.createChild< iv::Image >()
50  ->filename( "/CoreModels/Simulation/SimulationState_Button/border.png" );
51 
52  this->icon = this->surface_slot.createChild< iv::Border >()
53  ->leftRight( 10, 10 )
54  ->topBottom( 10, 10 )
56  ->prefsize( float3( 0, 0, 0 ) )
57  ->createChild< iv::Image >()
58  ->resizeStage( iv::FlatShader::ResizeStage::Scale );
59 
60  //---------------------------- animation -----------------------------------------------
61  // in
63  ->label( "in_game_state" );
64 
65  // lambda connector
66  auto lambda = this->anim.Make_Lambda_Connector()
67  ->AddParent( in_state );
68 
69  lambda->Retargeting(
70  [ = ]( bool warping )
71  {
72  if( this->previous_state != in_state->Target() )
73  {
74  this->previous_state = in_state->Target();
75  this->input.interruptActivation();
76  }
77 
78  switch( in_state->Target() )
79  {
81  {
82  this->icon->filename( "/ivorium_UI/icons/play.png" );
83  } break;
84 
86  {
87  this->icon->filename( "/ivorium_UI/icons/resume.png" );
88  } break;
89 
91  {
92  this->icon->filename( "/ivorium_UI/icons/pause.png" );
93  } break;
94 
96  {
97  this->icon->filename( "/ivorium_UI/icons/restart.png" );
98  } break;
99  }
100  }
101  );
102 
103  this->CallColorsChanged();
104 }
105 
107 {
108  this->icon->preblend( surface );
109  this->icon->colorTransform( ColorTransform::Change( float4( 0.384, 0.000, 0.933, 1 ), on_surface ) );
110  this->border->preblend( surface );
111  this->border->colorTransform( ColorTransform::Change( float4( 0.800, 0.800, 0.800, 1 ), on_surface ) );
112 }
113 
114 }