Gradient.cpp 745 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "Gradient.h"
  7. #include <LibGUI/Painter.h>
  8. namespace Profiler {
  9. static Gfx::Bitmap const& heat_gradient()
  10. {
  11. static RefPtr<Gfx::Bitmap> bitmap;
  12. if (!bitmap) {
  13. bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { 101, 1 }).release_value_but_fixme_should_propagate_errors();
  14. GUI::Painter painter(*bitmap);
  15. painter.fill_rect_with_gradient(Orientation::Horizontal, bitmap->rect(), Color::from_rgb(0xffc080), Color::from_rgb(0xff3000));
  16. }
  17. return *bitmap;
  18. }
  19. Color color_for_percent(u8 percent)
  20. {
  21. VERIFY(percent <= 100);
  22. return heat_gradient().get_pixel(percent, 0);
  23. }
  24. }