blob: c32d8ae2829ef8d42a05c165ad49ecffbc069a01 [file] [log] [blame]
// Copyright 2024 The Pigweed Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
#pragma once
#include <math.h>
#include <string_view>
#include "pw_color/color.h"
#include "pw_draw/font_set.h"
#include "pw_draw/sprite_sheet.h"
#include "pw_framebuffer/framebuffer.h"
#include "pw_geometry/size.h"
#include "pw_geometry/vector2.h"
/// @defgroup pw_draw
namespace pw::draw {
/// @ingroup pw_draw
///
/// Draw a line using Bresenham's line algorithm from point (x1, y1) to (x2,
/// y2).
void DrawLine(pw::framebuffer::Framebuffer& fb,
int x1,
int y1,
int x2,
int y2,
pw::color::color_rgb565_t pen_color);
/// @ingroup pw_draw
///
/// Draw a circle at (center_x, center_y) with given radius and color. Only a
/// one-pixel outline is drawn if filled is false.
void DrawCircle(pw::framebuffer::Framebuffer& fb,
int center_x,
int center_y,
int radius,
pw::color::color_rgb565_t pen_color,
bool filled);
/// @ingroup pw_draw
///
/// Draw a horizontal line from (x1, y) to (x2, y).
void DrawHLine(pw::framebuffer::Framebuffer& fb,
int x1,
int x2,
int y,
pw::color::color_rgb565_t pen_color);
/// @ingroup pw_draw
///
/// Draw a rectangle defined by two opposite corner points (x1, y1) and (x2,
/// y2).
void DrawRect(pw::framebuffer::Framebuffer& fb,
int x1,
int y1,
int x2,
int y2,
pw::color::color_rgb565_t pen_color,
bool filled);
/// @ingroup pw_draw
///
/// Draw a rectangle defined by an upper left point (x, y) and width height
/// parameters.
void DrawRectWH(pw::framebuffer::Framebuffer& fb,
int x,
int y,
int w,
int h,
pw::color::color_rgb565_t pen_color,
bool filled);
/// @ingroup pw_draw
///
/// Fill an entire framebuffer with a single color.
void Fill(pw::framebuffer::Framebuffer& fb,
pw::color::color_rgb565_t pen_color);
/// @ingroup pw_draw
///
/// Draw a sprite at positon (x, y).
void DrawSprite(pw::framebuffer::Framebuffer& fb,
int x,
int y,
pw::draw::SpriteSheet* sprite_sheet,
int integer_scale);
void DrawTestPattern();
/// @ingroup pw_draw
///
/// Draw a single character with a given foreground and background color.
pw::geometry::Size<int> DrawCharacter(
int ch,
pw::geometry::Vector2<int> pos,
pw::color::color_rgb565_t fg_color,
pw::color::color_rgb565_t bg_color,
const FontSet& font,
pw::framebuffer::Framebuffer& framebuffer);
/// @ingroup pw_draw
///
/// Draw a string of characters onto a framebuffer. No text wrapping or line
/// break characters are handled.
pw::geometry::Size<int> DrawString(std::wstring_view str,
pw::geometry::Vector2<int> pos,
pw::color::color_rgb565_t fg_color,
pw::color::color_rgb565_t bg_color,
const FontSet& font,
pw::framebuffer::Framebuffer& framebuffer);
} // namespace pw::draw