Skip to content

Commit

Permalink
input: change how joystick scrolling intertia works, textures: use wh…
Browse files Browse the repository at this point in the history
…ite instead of transparent for first pixels
  • Loading branch information
vgmoose committed Dec 1, 2023
1 parent fab8531 commit c603892
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/InputEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool InputEvents::processSDLEvents()
this->type = event.type;
this->noop = false;

// proces joystick hotplugging events
// process joystick hotplugging events
processJoystickHotplugging(&event);

this->isScrolling = false;
Expand Down
9 changes: 4 additions & 5 deletions src/ListElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ bool ListElement::process(InputEvents* event)
bool ListElement::processUpDown(InputEvents* event)
{
bool ret = false;
int SPEED = 60;
int SPEED = 1;

// handle up and down for the scroll view
if (event->isKeyDown())
{
// scroll the view
this->y += (SPEED * event->held(UP_BUTTON) - SPEED * event->held(DOWN_BUTTON));
if (this->y > minYScroll)
this->y = minYScroll;
// scroll the view by offsetting the elastic counter
event->wheelScroll += (SPEED * event->held(UP_BUTTON) - SPEED * event->held(DOWN_BUTTON));

ret |= event->held(UP_BUTTON) || event->held(DOWN_BUTTON);
}

Expand Down
7 changes: 6 additions & 1 deletion src/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool Texture::loadFromSurface(CST_Surface *surface)

// load first pixel color
auto pixelcolor = getpixel(surface, 0, 0);
SDL_GetRGB(pixelcolor, surface->format, &texFirstPixel.r, &texFirstPixel.g, &texFirstPixel.b);
SDL_GetRGBA(pixelcolor, surface->format, &texFirstPixel.r, &texFirstPixel.g, &texFirstPixel.b, &texFirstPixel.a);

// load texture size
CST_QueryTexture(texture, &texW, &texH);
Expand Down Expand Up @@ -135,6 +135,11 @@ void Texture::render(Element* parent)
// draw colored background
CST_SetDrawColor(renderer, texFirstPixel);
auto color = (CST_Color){texFirstPixel.r,texFirstPixel.g,texFirstPixel.b,0xFF};

// if the first pixel is transparent, use white
if (texFirstPixel.a == 0)
color = (CST_Color){0xFF,0xFF,0xFF,0xFF};

CST_SetDrawColor(renderer, color);
CST_FillRect(renderer, &rect);

Expand Down

0 comments on commit c603892

Please sign in to comment.