Skip to content

Instantly share code, notes, and snippets.

@eyelash
Created October 13, 2018 20:38
Show Gist options
  • Save eyelash/67ab9412552a76dd99c0e87d9edc578d to your computer and use it in GitHub Desktop.
Save eyelash/67ab9412552a76dd99c0e87d9edc578d to your computer and use it in GitHub Desktop.
#include <nitro.hpp>
using namespace nitro;
class DemoAnimation: public Animation {
Node* node;
public:
DemoAnimation(Node* node): node(node) {}
bool apply() override {
float t = (time % 2000) / 1000.f;
float x = std::sin(t * 3.14159f);
node->set_scale_x(.9f + x * .1f);
node->request_redraw();
return false;
}
};
class Background: public Bin {
Color color = Color(.9f, .9f, .9f);
public:
void draw(const DrawContext& draw_context) override {
CanvasElement(0, 0, get_width(), get_height(), color, Texture(), Texture(), Texture()).draw(draw_context.projection);
Bin::draw(draw_context);
}
};
class Div: public Node {
Shadow shadow {Color(0, 0, 0) * .7f, 12.f, 24.f};
RoundedRectangle rect {Color(.5f, .1f, .1f), 12.f};
RoundedBorder border {1.f, Color(0, 0, 0) * .5f, 12.f};
InsetShadow inset_shadow {Color(1, 1, 1) * .2f, 12.f, 8.f};
public:
void layout() override {
const float width = get_width();
const float height = get_height();
shadow.set_location(0.f, 0.f);
shadow.set_size(width, height);
rect.set_location(0.f, 0.f);
rect.set_size(width, height);
border.set_location(0.f, 0.f);
border.set_size(width, height);
inset_shadow.set_location(1.f, 1.f);
inset_shadow.set_size(width - 2.f, height - 2.f);
}
Node* get_child(size_t index) override {
//return index == 0 ? &shadow : nullptr;
Node* children[] = {&shadow, &rect, &border, &inset_shadow};
return index < 4 ? children[index] : nullptr;
}
};
int main() {
Window window(800, 500, "demo");
Background background;
window.set_child(&background);
Padding padding(20.f);
background.set_child(&padding);
FontSet font("Monospace", 24.f);
Text text(&font, "Eigenbezeichnung اَللُّغَةُ اَلْعَرَبِيَّة", Color(0, 0, 0) * .7f);
RoundedBorder rect(2.f, Color(0, 0, 0) * .8f, 30.f);
::Div div;
padding.set_child(&div);
DemoAnimation animation(&div);
Animation::add_animation(&animation);
window.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment