Skip to content

Commit

Permalink
Cleanup, display lightbar color
Browse files Browse the repository at this point in the history
  • Loading branch information
igor725 committed Mar 17, 2024
1 parent 6d2f7a0 commit 43e037e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 33 deletions.
17 changes: 0 additions & 17 deletions .vscode/launch.json

This file was deleted.

18 changes: 10 additions & 8 deletions input/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

Controller::Controller() {
this->currPadColor = 0;
this->padColors[0] = {0x00, 0xff, 0x00};
this->padColors[1] = {0xff, 0x00, 0x00};
this->padColors[2] = {0x00, 0x00, 0xff};
this->padColors[3] = {0xff, 0xff, 0x00};
this->padColors[4] = {0xff, 0x00, 0xff};
this->padColors[5] = {0x00, 0xff, 0xff};
this->padColors[6] = {0xff, 0xff, 0xff};
this->padColors[0] = {0xff, 0xff, 0xff};
this->padColors[1] = {0x00, 0xff, 0x00};
this->padColors[2] = {0xff, 0x00, 0x00};
this->padColors[3] = {0x00, 0x00, 0xff};
this->padColors[4] = {0xff, 0xff, 0x00};
this->padColors[5] = {0xff, 0x00, 0xff};
this->padColors[6] = {0x00, 0xff, 0xff};
this->padColors[7] = {0xff, 0xff, 0xff};
}

Controller::~Controller() {}
Expand Down Expand Up @@ -160,8 +161,9 @@ bool Controller::TouchpadPressed() {
return CheckButtonsPressed(ORBIS_PAD_BUTTON_TOUCH_PAD);
}

void Controller::NextColor() {
OrbisPadColor Controller::NextColor() {
scePadSetLightBar(this->pad, &this->padColors[this->currPadColor = (this->currPadColor + 1) % 7]);
return this->padColors[this->currPadColor];
}

void Controller::ReadSticks(float *leftx, float *lefty, float *rightx, float *righty) {
Expand Down
4 changes: 2 additions & 2 deletions input/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Controller
int buttonState;
int currPadColor;
OrbisPadData padData;
OrbisPadColor padColors[7];
OrbisPadColor padColors[8];

void setButtonState(int state);
public:
Expand Down Expand Up @@ -41,7 +41,7 @@ class Controller
bool TouchpadPressed();
int ReadFingers(OrbisPadTouch **fingers);
void ReadSticks(float *leftx, float *lefty, float *rightx, float *righty);
void NextColor();
OrbisPadColor NextColor();
};

#endif
Expand Down
26 changes: 20 additions & 6 deletions input/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,27 @@
std::stringstream debugLogStream;

int frameID = 0;
Color bgColor;

int main(void) {
int rc;
int video;
int curFrame = 0;
static void repaintBar(PNG *png, OrbisPadColor newColor) {
static uint32_t prevColor = 0xFFFFFFFF;
uint32_t newColorU32 =
((uint32_t)newColor.r << 00) |
((uint32_t)newColor.g << 8) |
((uint32_t)newColor.b << 16);
if (prevColor == newColorU32) return;
static int32_t iWidth = 0, iHeight = 0;
auto idata = png->GetImgData(&iWidth, &iHeight);
for (int x = 840; x < 1079; x++) {
for (int y = 323; y < 474; y++) {
ptrdiff_t off = (y * iWidth) + x;
if (prevColor == idata[off])
idata[off] = newColorU32;
}
}
prevColor = newColorU32;
}

int main(void) {
// No buffering
setvbuf(stdout, NULL, _IONBF, 0);
// Create a 2D scene
Expand Down Expand Up @@ -66,7 +80,7 @@ int main(void) {
triangleBtn->Draw(scene, 1187, 359);
released = false;
} else if (released == false) {
controller->NextColor();
repaintBar(controllerBackground, controller->NextColor());
released = true;
}

Expand Down
6 changes: 6 additions & 0 deletions input/png.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ PNG::~PNG()
stbi_image_free(this->img);
}

uint32_t *PNG::GetImgData(int *width, int *height) {
if (width != NULL) *width = this->width;
if (height != NULL) *height = this->height;
return this->img;
}

void PNG::Draw(Scene2D *scene, int startX, int startY)
{
// Don't draw non-existant images
Expand Down
1 change: 1 addition & 0 deletions input/png.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class PNG {
PNG(const char *imagePath);
~PNG();

uint32_t *GetImgData(int *width = NULL, int *height = NULL);
void Draw(Scene2D *scene, int startX, int startY);
};

Expand Down

0 comments on commit 43e037e

Please sign in to comment.