Skip to content

Commit baf83df

Browse files
committed
Single/Draw Mode
1 parent 91024fd commit baf83df

File tree

5 files changed

+65
-18
lines changed

5 files changed

+65
-18
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@ LedED is an LED matrix editor designed to generate header files that can be embe
1616

1717
![LedED Editor](https://github.com/Byte-White/MAX7219-Dev/assets/51212450/e206b911-b73d-4fc0-8bca-feab067aa0e8)
1818

19-
### Example Animations
19+
### Examples
20+
21+
![Example 1](https://github.com/Byte-White/MAX7219-Dev/assets/51212450/4629b9c5-dec6-4e06-8f1a-fcd6a0cf7433)
22+
23+
![Example 2](https://github.com/Byte-White/WS2812-Dev/assets/51212450/5996d8b4-5e5e-4b3e-a7aa-5759b8fdda84)
24+
25+
![Example 3](https://github.com/Byte-White/LedED/assets/51212450/4d2286f2-5aef-4255-a8b7-2dac581fe1ac)
26+
2027

21-
![Example Animation 1](https://github.com/Byte-White/MAX7219-Dev/assets/51212450/4629b9c5-dec6-4e06-8f1a-fcd6a0cf7433)
2228

23-
![Example Animation 2](https://github.com/Byte-White/WS2812-Dev/assets/51212450/5996d8b4-5e5e-4b3e-a7aa-5759b8fdda84)
2429

2530
### Exported Header File
2631

src/editor.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void Editor::ResetAll()
5555
// led buttons
5656
void Editor::DrawButtons(const int& x_items, const int& y_items)
5757
{
58-
snprintf(hoverdatatext,50,"");
58+
snprintf(hoverdatatext,60,"");
5959
Vector2 pos = GetMousePosition();
6060
int starting_x = GetScreenWidth() / 4 + camera_x;
6161
int starting_y = 0 + camera_y; // or GetScreenHeight() / 4 if you want menu at the top
@@ -107,20 +107,27 @@ void Editor::DrawButtons(const int& x_items, const int& y_items)
107107
SetMouseCursor(MOUSE_CURSOR_CROSSHAIR);
108108
cursorishovering = true;
109109

110-
snprintf(hoverdatatext,50,"hovering over:\nx: %d\ny: %d\n%s",j,i,data[curframe][i*w+j].to_string(rgb_or_bw).c_str());//j - x i - y
111-
112-
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) // if led color is the same as preview color clear the led
113-
{
114-
if(data[curframe][i*w+j] == col)
110+
snprintf(hoverdatatext,60,"hovering over:\nx: %d\ny: %d\n%s",j,i,data[curframe][i*w+j].to_string(rgb_or_bw).c_str());//j - x i - y
111+
if(singledrawmode)
112+
{ // click to draw
113+
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) // if led color is the same as preview color clear the led
115114
{
116-
leddata blank;
117-
blank.r = 0;
118-
blank.g = 0;
119-
blank.b = 0;
120-
blank.a = 255;
121-
data[curframe][i*w+j] = blank;
115+
if(data[curframe][i*w+j] == col)
116+
{
117+
leddata blank;
118+
blank.r = 0;
119+
blank.g = 0;
120+
blank.b = 0;
121+
blank.a = 255;
122+
data[curframe][i*w+j] = blank;
123+
}
124+
else data[curframe][i*w+j]=col;
122125
}
123-
else data[curframe][i*w+j]=col;
126+
}
127+
else
128+
{ // hold to draw
129+
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
130+
data[curframe][i*w+j]=col;
124131
}
125132
}
126133

src/editor.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class Editor
5858
double leftdowntime = 0.0;
5959
unsigned int curframe = 0;// index of the frame
6060
double camera_x = 0.0 ,camera_y = 0.0,camera_scale = 1.0;
61-
62-
char hoverdatatext[50];
61+
bool singledrawmode = true;
62+
char hoverdatatext[60];
6363
private:
6464
void RGBAMenu();
6565
void WBMenu();
@@ -78,5 +78,6 @@ class Editor
7878
void Render();
7979
void Export(const std::string& path,std::string& error);
8080
void DrawTextInput(std::string& txt,int x,int y,int n,int font,int& cursorlocation,Color bg = GRAY, Color tc = WHITE);
81+
bool DrawCheckbox(int x,int y,bool& ticked,Color ctoff = DARKBLUE,Color cton = LIME, Color bgoff = BLUE,Color bgon = DARKGREEN,std::string txt = "");
8182
};
8283

src/gui.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,34 @@ void Editor::DrawTextInput(std::string& txt,int x,int y,int n, int font, int& cu
143143
lastblink = GetTime()+0.5; // so it doesnt blink while typing
144144
}
145145
}
146+
147+
148+
bool Editor::DrawCheckbox(int x,int y,bool& ticked,Color ctoff,Color cton, Color bgoff,Color bgon,std::string txt)
149+
{
150+
Vector2 pos = GetMousePosition();
151+
152+
// Draw color button
153+
if(ticked)
154+
{
155+
DrawRectangle(x, y, 25, 25, bgon);
156+
DrawText("x", x + 5, y, 25, cton);
157+
}
158+
else
159+
{
160+
DrawRectangle(x, y, 25, 25, bgoff);
161+
DrawText("o", x + 5, y, 25, ctoff);
162+
}
163+
DrawText(txt.c_str(),x+30,y,25,ticked?cton:ctoff);
164+
// Check if the button is pressed
165+
if((pos.x >= x && pos.x <= x + 25) && (pos.y >= y && pos.y <= y + 25))
166+
{
167+
SetMouseCursor(MOUSE_CURSOR_POINTING_HAND);
168+
cursorishovering = true;
169+
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
170+
{
171+
ticked = !ticked;
172+
}
173+
}
174+
175+
return false;
176+
}

src/menu.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ void Editor::DrawMenu()
110110
tab = 2; // Export Menu
111111
}
112112
}
113+
// Drawing Mode
114+
DrawCheckbox(10,GetScreenHeight()/2 - 35,singledrawmode,DARKBLUE,LIME,BLUE,DARKGREEN,singledrawmode?"Single":"Draw");
113115
//------ Hovering Led -----
114116
DrawText(hoverdatatext,10,GetScreenHeight()/2,15,WHITE);
115117

@@ -162,6 +164,7 @@ void Editor::DrawMenu()
162164
}
163165
}
164166
}
167+
165168
}
166169

167170
void Editor::DrawExportMenu()

0 commit comments

Comments
 (0)