yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
draw_sampling.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GUI_CORE_DRAW_SAMPLING_H_
2#define YAZE_APP_GUI_CORE_DRAW_SAMPLING_H_
3
4#include "imgui/imgui.h"
5
6namespace yaze {
7namespace gui {
8
35 public:
36 explicit ScopedNearestSampling(ImDrawList* draw_list) {
37 if (draw_list == nullptr || IsActiveOn(draw_list)) {
38 return;
39 }
40 ImDrawCallback set_nearest =
41 ImGui::GetPlatformIO().DrawCallback_SetSamplerNearest;
42 if (set_nearest == nullptr) {
43 return;
44 }
45 draw_list->AddCallback(set_nearest, nullptr);
46 draw_list_ = draw_list;
48 innermost_ = this;
49 }
50
52 if (draw_list_ == nullptr) {
53 return;
54 }
56 const ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
57 if (platform_io.DrawCallback_SetSamplerLinear != nullptr) {
58 draw_list_->AddCallback(platform_io.DrawCallback_SetSamplerLinear,
59 nullptr);
60 } else if (platform_io.DrawCallback_ResetRenderState != nullptr) {
61 draw_list_->AddCallback(platform_io.DrawCallback_ResetRenderState,
62 nullptr);
63 }
64 }
65
68
69 // True when this scope added the nearest callback and will restore it.
70 bool active() const { return draw_list_ != nullptr; }
71
72 private:
73 static bool IsActiveOn(const ImDrawList* draw_list) {
74 for (const ScopedNearestSampling* scope = innermost_; scope != nullptr;
75 scope = scope->outer_) {
76 if (scope->draw_list_ == draw_list) {
77 return true;
78 }
79 }
80 return false;
81 }
82
83 ImDrawList* draw_list_ = nullptr;
84 const ScopedNearestSampling* outer_ = nullptr;
85
86 // Innermost active scope on this thread; scopes link to the one they nest
87 // in through outer_.
88 static inline thread_local const ScopedNearestSampling* innermost_ = nullptr;
89};
90
91} // namespace gui
92} // namespace yaze
93
94#endif // YAZE_APP_GUI_CORE_DRAW_SAMPLING_H_
RAII scope that samples the images drawn inside it with nearest-neighbor filtering.
ScopedNearestSampling(ImDrawList *draw_list)
ScopedNearestSampling(const ScopedNearestSampling &)=delete
static thread_local const ScopedNearestSampling * innermost_
static bool IsActiveOn(const ImDrawList *draw_list)
const ScopedNearestSampling * outer_
ScopedNearestSampling & operator=(const ScopedNearestSampling &)=delete