ドキュメント

View Categories

ScaleComponent

1 min read

ScaleComponent

Scaleコンポーネントは指定したスケールに拡大縮小するコンポーネントです。

scale_component.hpp

class ScaleComponent : public Component
{
public:
  using SCALE = spa::gui::Scale<>;
  using CTL = spa::gui::ScaleCtl<>;

public:
  class Update
  {
  public:
    Update(SCALE* scale);
    void operator()(CTL* ctl);

  private:
    SCALE* scale;
  };

public:
  ScaleComponent(MOD mod);

  ~ScaleComponent() = default;

  SCALE* get();

  std::function<void(CTL*)> update();

  void configure();

private:
  std::shared_ptr<SCALE> scale;
};



ScaleオブジェクトはScaleCtlオブジェクトを使って制御します。

scale_component.cpp

void ScaleComponent::Update::operator()(CTL* ctl)
{
  spa::utils::check::boolean((ctl->ctl_scale>0), __FILE__, __LINE__, "[SCALE CTL] SCALE <= 0");

  unsigned int negative_margin_x = ctl->ctl_x * scale->width / ctl->width;
  unsigned int negative_margin_y = ctl->ctl_y * scale->height / ctl->height;

  scale->margin_x = -negative_margin_x;
  scale->margin_y = -negative_margin_y;
  scale->margin_scale = ctl->ctl_scale;
}


ScaleCtlを渡してScaleオブジェクトのマージンとスケールを更新します。

ペンディング:unsigned int 以外の型に対応する。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です