51 lines
1.1 KiB
C++
51 lines
1.1 KiB
C++
#include "api.hxx"
|
|
|
|
#include <stdexcept>
|
|
#include <utility>
|
|
|
|
BoxCore::BoxCore(BoxCore&& b)
|
|
: ptr(std::exchange(b.ptr, {})) {
|
|
}
|
|
|
|
BoxCore::~BoxCore() {
|
|
reset();
|
|
}
|
|
|
|
BoxCore& BoxCore::operator=(BoxCore&& b) {
|
|
if (&b == this)
|
|
return *this;
|
|
std::swap(ptr, b.ptr);
|
|
b.reset();
|
|
return *this;
|
|
}
|
|
|
|
BoxCore BoxCore::from_xcb(xcb_connection_t* connection, std::uint32_t window, std::uint32_t width, std::uint32_t height, const ResetArgs& args) {
|
|
if (!connection)
|
|
throw std::logic_error("attempt to use a null connection");
|
|
if (!window)
|
|
throw std::logic_error("attempt to use a null window");
|
|
BoxCore out;
|
|
out.ptr.ptr = ffi::rt4_viewport_create(connection, window, width, height, &args);
|
|
return out;
|
|
}
|
|
|
|
void BoxCore::reset() {
|
|
auto viewport = std::exchange(ptr, {});
|
|
if (viewport)
|
|
ffi::rt4_viewport_destroy(viewport.use());
|
|
}
|
|
|
|
ffi::Core* MutCore::use() const {
|
|
if (!ptr)
|
|
throw std::logic_error("attempt to use a null Core");
|
|
return ptr;
|
|
}
|
|
|
|
void MutCore::configure(std::uint32_t width, std::uint32_t height) const {
|
|
rt4_viewport_configure(use(), width, height);
|
|
}
|
|
|
|
void MutCore::redraw(const RedrawArgs& args) const {
|
|
rt4_viewport_redraw(use(), &args);
|
|
}
|