Skip to content

Commit

Permalink
drawing: add cursor states on PC, set texture width/height on cache load
Browse files Browse the repository at this point in the history
  • Loading branch information
vgmoose committed Jul 28, 2024
1 parent b2e2f0d commit 2fdf675
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ SOURCES += $(CHESTO_DIR)/libs/SDL_FontCache
VPATH += $(CHESTO_DIR)/libs/SDL_FontCache

CFLAGS += $(INCLUDE) -DAPP_VERSION=\"$(APP_VERSION)\" -frandom-seed=84248
CXXFLAGS += $(CFLAGS) -fno-exceptions -std=gnu++20
CXXFLAGS += $(CFLAGS) -fexceptions -std=gnu++20
ASFLAGS += -g $(ARCH)

export TOPDIR := $(CURDIR)
Expand Down
20 changes: 20 additions & 0 deletions src/DrawUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,26 @@ void CST_LowRumble(InputEvents* event, int ms)
}
}

void CST_SetCursor(int cursor)
{
if (cursor == CST_CURSOR_NONE) {
SDL_ShowCursor(SDL_DISABLE);
return;
}

SDL_ShowCursor(SDL_ENABLE);
auto sdlCursor = SDL_SYSTEM_CURSOR_ARROW;
if (cursor == CST_CURSOR_HAND) {
sdlCursor = SDL_SYSTEM_CURSOR_HAND;
} else if (cursor == CST_CURSOR_TEXT) {
sdlCursor = SDL_SYSTEM_CURSOR_IBEAM;
} else if (cursor == CST_CURSOR_SPINNER) {
sdlCursor = SDL_SYSTEM_CURSOR_WAIT;
}

SDL_SetCursor(SDL_CreateSystemCursor(sdlCursor));
}

bool CST_isRectOffscreen(CST_Rect* rect)
{
// if this element will be offscreen, don't try to render it
Expand Down
7 changes: 7 additions & 0 deletions src/DrawUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ typedef SDL_Rect CST_Rect;
class RootDisplay;
class InputEvents;

#define CST_CURSOR_NONE -1
#define CST_CURSOR_ARROW 0
#define CST_CURSOR_HAND 1
#define CST_CURSOR_TEXT 2
#define CST_CURSOR_SPINNER 3

// init / rendering analogues
bool CST_DrawInit(RootDisplay* root);
void CST_MixerInit(RootDisplay* root);
Expand Down Expand Up @@ -79,6 +85,7 @@ void CST_GetRGBA(Uint32 pixel, SDL_PixelFormat* format, CST_Color* cstColor);
bool CST_SavePNG(CST_Texture* texture, const char* filename);
void CST_SetWindowTitle(const char* title);

void CST_SetCursor(int cursor);
void CST_LowRumble(InputEvents* event, int ms);

#ifdef MUSIC
Expand Down
12 changes: 12 additions & 0 deletions src/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,21 @@ bool Element::onTouchDrag(InputEvents* event)

// play a hover sound and vibrate
CST_LowRumble(event, 200);

// change the cursor to a hand
CST_SetCursor(CST_CURSOR_HAND);
} else {
auto initialElasticCounter = this->elasticCounter;

// we're in a drag event, but not for this element
this->elasticCounter = NO_HIGHLIGHT;

if (initialElasticCounter != NO_HIGHLIGHT) {
// change the cursor back to the arrow
CST_SetCursor(CST_CURSOR_ARROW);
ret |= true;
}

}
}

Expand Down
5 changes: 5 additions & 0 deletions src/NetImageElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ NetImageElement::NetImageElement(const char *url, std::function<Texture *(void)>
// printf("Key: %s\n", key.c_str());
if (loadFromCache(key)) {
loaded = true;

// if we're using the cache, we can update the size now
// printf("The size of the image is %d x %d\n", texW, texH);
width = texW;
height = texH;
}
else {
// setup a temporary image fallback
Expand Down

0 comments on commit 2fdf675

Please sign in to comment.