git.haldean.org qb / main ui.cpp
main

Tree @main (Download .tar.gz)

ui.cpp @mainraw · history · blame

#include "ui.hpp"

#include "colors.hpp"

#include "cimgui/imgui/imgui.h"

namespace qb {
  void draw_playhead(const qb::context &ctx)
  {
    ImDrawList * const drawlist = ImGui::GetWindowDrawList();
    const float f0x = (float) ctx.frame2pixel(ctx.playhead());
    const float f1x = (float) ctx.frame2pixel(ctx.playhead() + 1);
    if (f1x > 0 && f1x != f0x) {
      drawlist->AddRectFilled(
        ImVec2(f0x, 0.0), ImVec2(f1x, (float) ctx.height()),
        qb::theme::colors[qb::theme::color::playhead]);
    } else {
      drawlist->AddLine(
        ImVec2(f0x, 0), ImVec2(f0x, (float) ctx.height()),
        qb::theme::colors[qb::theme::color::playhead]);
    }
  }

  static constexpr float ruler_height = 16;

  void draw_ruler(const qb::context &ctx)
  {
    ImDrawList * const drawlist = ImGui::GetWindowDrawList();
    const float playheadx = (float) ctx.frame2pixel(ctx.playhead() + 1);
    /*
    drawlist->AddRectFilled(
      ImVec2(0, 0), ImVec2(ctx.width(), ruler_height),
      qb::theme::colors[qb::theme::color::ruler]);
    */

    char buf[32] = {};
    snprintf(buf, 32, "%.0f", ctx.playhead());
    drawlist->AddText(
      ImGui::GetIO().Fonts->Fonts[0],
      ruler_height,
      ImVec2(playheadx, 30),
      qb::theme::color::ruler,
      "hello!");
  }
}