2001-11-27 18:50:04 -07:00
|
|
|
// overlay.h
|
|
|
|
//
|
|
|
|
// Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
#ifndef _OVERLAY_H_
|
|
|
|
#define _OVERLAY_H_
|
|
|
|
|
2019-12-18 11:56:34 -07:00
|
|
|
#include <iosfwd>
|
2019-10-08 14:00:19 -06:00
|
|
|
#include <string>
|
2020-05-10 01:06:48 -06:00
|
|
|
#include <vector>
|
2021-10-20 10:48:58 -06:00
|
|
|
#include <fmt/printf.h>
|
2020-05-12 09:51:25 -06:00
|
|
|
#include <Eigen/Core>
|
2001-11-27 18:50:04 -07:00
|
|
|
|
2020-05-10 01:06:48 -06:00
|
|
|
class Color;
|
2001-11-27 18:50:04 -07:00
|
|
|
class Overlay;
|
2019-08-02 04:38:19 -06:00
|
|
|
class Renderer;
|
2019-12-18 11:56:34 -07:00
|
|
|
class TextureFont;
|
2001-11-27 18:50:04 -07:00
|
|
|
|
2021-05-22 01:10:05 -06:00
|
|
|
namespace celestia
|
|
|
|
{
|
|
|
|
class Rect;
|
|
|
|
}
|
|
|
|
|
2001-11-27 18:50:04 -07:00
|
|
|
// Custom streambuf class to support C++ operator style output. The
|
|
|
|
// output is completely unbuffered so that it can coexist with printf
|
|
|
|
// style output which the Overlay class also supports.
|
|
|
|
class OverlayStreamBuf : public std::streambuf
|
|
|
|
{
|
|
|
|
public:
|
2004-01-03 14:30:42 -07:00
|
|
|
OverlayStreamBuf();
|
2001-11-27 18:50:04 -07:00
|
|
|
|
|
|
|
void setOverlay(Overlay*);
|
|
|
|
|
|
|
|
int overflow(int c = EOF);
|
|
|
|
|
2004-01-03 14:30:42 -07:00
|
|
|
enum UTF8DecodeState
|
|
|
|
{
|
|
|
|
UTF8DecodeStart = 0,
|
|
|
|
UTF8DecodeMultibyte = 1,
|
|
|
|
};
|
|
|
|
|
2001-11-27 18:50:04 -07:00
|
|
|
private:
|
2018-09-22 07:13:49 -06:00
|
|
|
Overlay* overlay{ nullptr };
|
2006-09-15 07:22:33 -06:00
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
UTF8DecodeState decodeState{ UTF8DecodeStart };
|
2018-10-30 12:57:10 -06:00
|
|
|
wchar_t decodedChar{ 0 };
|
|
|
|
unsigned int decodeShift{ 0 };
|
2001-11-27 18:50:04 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Overlay : public std::ostream
|
|
|
|
{
|
|
|
|
public:
|
2020-03-14 04:48:24 -06:00
|
|
|
Overlay(Renderer&);
|
2019-08-02 04:38:19 -06:00
|
|
|
Overlay() = delete;
|
2018-09-22 07:13:49 -06:00
|
|
|
~Overlay() = default;
|
2001-11-27 18:50:04 -07:00
|
|
|
|
|
|
|
void begin();
|
|
|
|
void end();
|
|
|
|
|
|
|
|
void setWindowSize(int, int);
|
2021-05-23 06:13:35 -06:00
|
|
|
void setFont(const std::shared_ptr<TextureFont>&);
|
2001-11-27 18:50:04 -07:00
|
|
|
|
2020-03-31 14:21:55 -06:00
|
|
|
void setColor(float r, float g, float b, float a);
|
|
|
|
void setColor(const Color& c);
|
|
|
|
|
2020-05-10 01:06:48 -06:00
|
|
|
void moveBy(float dx, float dy);
|
2020-03-31 14:21:55 -06:00
|
|
|
void savePos();
|
|
|
|
void restorePos();
|
2019-10-08 14:00:19 -06:00
|
|
|
|
2020-03-14 04:48:24 -06:00
|
|
|
Renderer& getRenderer() const
|
2019-08-02 04:38:19 -06:00
|
|
|
{
|
2019-10-08 14:00:19 -06:00
|
|
|
return renderer;
|
2019-08-02 04:38:19 -06:00
|
|
|
};
|
|
|
|
|
2021-05-22 01:10:05 -06:00
|
|
|
void drawRectangle(const celestia::Rect&);
|
2001-11-27 18:50:04 -07:00
|
|
|
|
|
|
|
void beginText();
|
|
|
|
void endText();
|
2004-01-03 14:30:42 -07:00
|
|
|
void print(wchar_t);
|
2001-11-27 18:50:04 -07:00
|
|
|
void print(char);
|
2021-10-20 10:48:58 -06:00
|
|
|
template <typename... T>
|
|
|
|
void print(const char* format, const T&... args)
|
|
|
|
{
|
|
|
|
print_impl(fmt::format(format, args...));
|
|
|
|
}
|
|
|
|
template <typename... T>
|
|
|
|
void printf(const char* format, const T&... args)
|
|
|
|
{
|
|
|
|
print_impl(fmt::sprintf(format, args...));
|
|
|
|
}
|
2001-11-27 18:50:04 -07:00
|
|
|
|
|
|
|
private:
|
2021-10-20 10:48:58 -06:00
|
|
|
void print_impl(const std::string&);
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
int windowWidth{ 1 };
|
|
|
|
int windowHeight{ 1 };
|
2021-05-23 06:13:35 -06:00
|
|
|
std::shared_ptr<TextureFont> font{ nullptr };
|
2018-09-22 07:13:49 -06:00
|
|
|
bool useTexture{ false };
|
|
|
|
bool fontChanged{ false };
|
|
|
|
int textBlock{ 0 };
|
|
|
|
|
|
|
|
float xoffset{ 0.0f };
|
|
|
|
float yoffset{ 0.0f };
|
2009-08-13 19:27:29 -06:00
|
|
|
|
2001-11-27 18:50:04 -07:00
|
|
|
OverlayStreamBuf sbuf;
|
2019-08-02 04:38:19 -06:00
|
|
|
|
2020-03-14 04:48:24 -06:00
|
|
|
Renderer& renderer;
|
2020-05-10 01:06:48 -06:00
|
|
|
|
|
|
|
struct CursorPosition
|
|
|
|
{
|
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
x = y = 0.125f;
|
|
|
|
}
|
|
|
|
float x, y;
|
|
|
|
};
|
|
|
|
CursorPosition global { 0.0f, 0.0f };
|
|
|
|
std::vector<CursorPosition> posStack;
|
2020-09-29 20:27:22 -06:00
|
|
|
Eigen::Matrix4f projection;
|
2001-11-27 18:50:04 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _OVERLAY_H_
|