diff options
author | kdx <kikoodx@paranoici.org> | 2023-01-15 03:11:45 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-01-15 03:11:45 +0100 |
commit | 23a972f9ef5c3f926702be93d7cbb2369870c40d (patch) | |
tree | eca8043ec3b4d4bf22e383fd7fc30b36862d1cbe | |
parent | 61cb97f6d327a5c10d69e6bd79417a0543ed6cf0 (diff) | |
download | 005-23a972f9ef5c3f926702be93d7cbb2369870c40d.tar.gz |
scream
-rw-r--r-- | Cursor.cpp | 25 | ||||
-rw-r--r-- | Cursor.hpp | 5 | ||||
-rw-r--r-- | Table.cpp | 51 | ||||
-rw-r--r-- | Table.hpp | 14 | ||||
-rw-r--r-- | main.cpp | 4 |
5 files changed, 91 insertions, 8 deletions
@@ -1,14 +1,16 @@ #include "Cursor.hpp" #include "lzr.h" +#include <stdlib.h> -Cursor::Cursor() : _x(0), _y(0), _down(false) +Cursor::Cursor() : x(0), y(0), down(false), erase(false) { } void Cursor::update() { - LZR_MousePosition(&_x, &_y); - _down = LZR_BUTTON(MOUSE_L) || LZR_BUTTON(MOUSE_R); + LZR_MousePosition(&x, &y); + down = LZR_BUTTON(MOUSE_L); + erase = LZR_BUTTON(MOUSE_R); } void Cursor::draw() @@ -16,7 +18,18 @@ void Cursor::draw() LZR_ImageDrawSettings stg = { 0, 0, -1, -1, 1.0, 1.0, 0.0, true, false, false }; - LZR_DrawSetColor(1, 1, 1, 1); - LZR_DrawImageEx(_down ? LZR_IMAGE("res/cursor_down.bmp") - : LZR_IMAGE("res/cursor_up.bmp"), _x, _y, stg); + set_color(); + LZR_DrawImageEx(down || erase ? LZR_IMAGE("res/cursor_down.bmp") + : LZR_IMAGE("res/cursor_up.bmp"), + x, y, stg); +} + +void Cursor::set_color() const +{ + if (erase) + LZR_DrawSetColor(rand() & 1, 0, rand() & 1, 1); + else if (down) + LZR_DrawSetColor(rand() & 1, rand() & 1, rand() & 1, 1); + else + LZR_DrawSetColor(1, 1, 1, (rand() & 3) != 0); } @@ -1,10 +1,11 @@ #pragma once class Cursor { - int _x, _y; - bool _down; public: + int x, y; + bool down, erase; Cursor(); void update(); void draw(); + void set_color() const; }; diff --git a/Table.cpp b/Table.cpp new file mode 100644 index 0000000..25eb253 --- /dev/null +++ b/Table.cpp @@ -0,0 +1,51 @@ +#include "Table.hpp" +#include "Cursor.hpp" +#include "cfg.hpp" +#include "lzr.h" +#include <stdlib.h> + +Table::Table() : _notes(), _edited(-1) +{ + for (int i = 0; i < _width; i++) + _strength[i] = 1; +} + +void Table::update(const Cursor& cursor) +{ + _hovered = -1; + if (cursor.x < 0) + return; + const int x = cursor.x / 32; + if (x >= _width) + return; + if (cursor.down) { + if (x == _edited) + _strength[x] += 1; + else + _strength[x] = 1; + _notes[x] = cursor.y; + _edited = x; + } else if (cursor.erase) { + _strength[x] = 0; + _edited = -1; + } else + _edited = -1; + _hovered = x; +} + +void Table::draw(const Cursor& cursor) +{ + for (int i = 0; i < _width; i++) + { + const int x = i * 32; + const int y = _notes[i]; + const int s = _strength[i]; + if (i == _hovered) { + cursor.set_color(); + if (cursor.erase || (rand() & 3)) + LZR_DrawRectangle(true, x, 0, 32, CFG_DHEIGHT); + } + LZR_DrawSetColor(rand() & 1, rand() & 1, rand() & 1, 1); + LZR_DrawRectangle(true, x, y - s / 2, 32, s); + } +} diff --git a/Table.hpp b/Table.hpp new file mode 100644 index 0000000..f73ca56 --- /dev/null +++ b/Table.hpp @@ -0,0 +1,14 @@ +#pragma once +#include "Cursor.hpp" + +class Table { +private: + static const int _width = 16; + int _notes[_width]; + int _strength[_width]; + int _hovered, _edited; +public: + Table(); + void update(const Cursor& cursor); + void draw(const Cursor& cursor); +}; @@ -1,5 +1,6 @@ #include "cfg.hpp" #include "lzr.h" +#include "Table.hpp" #include "Cursor.hpp" int main(int argc, char **argv) @@ -11,12 +12,15 @@ int main(int argc, char **argv) return 1; } Cursor cursor; + Table table; while (!LZR_ShouldQuit()) { LZR_CycleEvents(); cursor.update(); + table.update(cursor); LZR_DrawBegin(); LZR_DrawSetColor(0, 0, 0, 1); LZR_DrawClear(); + table.draw(cursor); cursor.draw(); LZR_DrawEnd(); } |