Nugget
font.hh
1 /*
2 
3 MIT License
4 
5 Copyright (c) 2022 PCSX-Redux authors
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 
25 */
26 
27 #pragma once
28 
29 #include <EASTL/array.h>
30 #include <EASTL/atomic.h>
31 #include <EASTL/functional.h>
32 #include <stdarg.h>
33 
34 #include "psyqo/fragments.hh"
35 #include "psyqo/gpu.hh"
36 #include "psyqo/primitives.hh"
37 
38 namespace psyqo {
39 
40 template <size_t Fragments = 16>
41 class Font;
42 
51 class FontBase {
52  public:
53  virtual ~FontBase() {}
54  // Blocking call that will unpack the built-in system font and upload it to vram at a fixed location.
55  void uploadSystemFont(GPU& gpu);
56 
57  void print(GPU& gpu, const char* text, Vertex pos, Color color);
58  void print(GPU& gpu, const char* text, Vertex pos, Color color, eastl::function<void()>&& callback,
59  DMA::DmaCallback dmaCallback);
60  void printf(GPU& gpu, Vertex pos, Color color, const char* format, ...) {
61  va_list args;
62  va_start(args, format);
63  vprintf(gpu, pos, color, format, args);
64  va_end(args);
65  }
66  void printf(GPU& gpu, Vertex pos, Color color, eastl::function<void()>&& callback, DMA::DmaCallback dmaCallback,
67  const char* format, ...) {
68  va_list args;
69  va_start(args, format);
70  vprintf(gpu, pos, color, eastl::move(callback), dmaCallback, format, args);
71  va_end(args);
72  }
73  void vprintf(GPU& gpu, Vertex pos, Color color, const char* format, va_list ap);
74  void vprintf(GPU& gpu, Vertex pos, Color color, eastl::function<void()>&& callback, DMA::DmaCallback dmaCallback,
75  const char* format, va_list ap);
76 
77  void chainprint(GPU& gpu, const char* text, Vertex pos, Color color);
78  void chainprintf(GPU& gpu, Vertex pos, Color color, const char* format, ...) {
79  va_list args;
80  va_start(args, format);
81  vprintf(gpu, pos, color, format, args);
82  va_end(args);
83  }
84  void chainvprintf(GPU& gpu, Vertex pos, Color color, const char* format, va_list ap);
85 
86  protected:
88  Prim::VRAMUpload upload;
89  uint32_t pixel;
90  Prim::FlushCache flushCache;
91  Prim::TPage tpage;
92  };
94  virtual GlyphsFragment& getGlyphFragment(bool increment) = 0;
95  virtual void forEach(eastl::function<void(GlyphsFragment&)>&& cb) = 0;
96 
97  void innerprint(GlyphsFragment& fragment, GPU& gpu, const char* text, Vertex pos, Color color);
98  void innervprintf(GlyphsFragment& fragment, GPU& gpu, Vertex pos, Color color, const char* format, va_list ap);
99 
100  private:
101  struct XPrintfInfo;
102  GlyphsFragment& printToFragment(GPU& gpu, const char* text, Vertex pos, Color color);
104  Vertex m_size;
105 
106  friend struct XPrintfInfo;
107 };
108 
109 } // namespace psyqo
110 
111 #include "psyqo/internal/font.hh"
Definition: function.h:30
The Font drawing class.
Definition: font.hh:51
The singleton GPU class.
Definition: gpu.hh:57
OutputIterator move(InputIterator first, InputIterator last, OutputIterator result)
Definition: copy_help.h:170
Definition: array.h:59
Definition: font.cpp:175
A maximum fixed sized fragment of similar primitives.
Definition: fragments.hh:95
The FlushCache primitive.
Definition: misc.hh:45
Definition: control.hh:37
Initiates a VRAM upload.
Definition: control.hh:116
The Color struct.
Definition: common.hh:91
The Vertex struct.
Definition: common.hh:47