menu
This commit is contained in:
+13
-24
@@ -6,6 +6,7 @@
|
||||
|
||||
typedef enum {
|
||||
NOT_CLICKED,
|
||||
HOVER,
|
||||
CLICKED
|
||||
} ButtonState;
|
||||
|
||||
@@ -13,8 +14,10 @@ typedef struct
|
||||
{
|
||||
Sprite sprite;
|
||||
Vector2 notClicked;
|
||||
Vector2 hover;
|
||||
Vector2 clicked;
|
||||
bool isHovered;
|
||||
bool isClicked;
|
||||
} ImageButton;
|
||||
|
||||
typedef struct
|
||||
@@ -22,7 +25,7 @@ typedef struct
|
||||
Sprite sprite;
|
||||
} ImageElement;
|
||||
|
||||
ImageButton CreateImageButton(ButtonState state, Texture2D *texture, const TextureAsset *asset, Vector2 *source, Vector2 *clicked, Rectangle *destRec){
|
||||
ImageButton CreateImageButton(ButtonState state, Texture2D *texture, const TextureAsset *asset, Vector2 *source, Vector2 *clicked, Vector2 *hover, Rectangle *destRec){
|
||||
return (ImageButton){
|
||||
.sprite = {
|
||||
.texture = *texture,
|
||||
@@ -34,6 +37,7 @@ ImageButton CreateImageButton(ButtonState state, Texture2D *texture, const Textu
|
||||
.color = WHITE
|
||||
},
|
||||
.notClicked = (Vector2){source->x, source->y},
|
||||
.hover = *hover,
|
||||
.clicked = *clicked
|
||||
};
|
||||
}
|
||||
@@ -52,47 +56,32 @@ ImageElement CreateImageElement(Texture2D *texture, const TextureAsset *asset, V
|
||||
};
|
||||
}
|
||||
|
||||
void PrintImageButton(const ImageButton btn) {
|
||||
printf("ImageButton:\n");
|
||||
printf(" Sprite.texture: id = %d\n", btn.sprite.texture.id);
|
||||
printf(" Sprite.sourceRec: x = %f, y = %f, width = %f, height = %f\n",
|
||||
btn.sprite.sourceRec.x, btn.sprite.sourceRec.y,
|
||||
btn.sprite.sourceRec.width, btn.sprite.sourceRec.height);
|
||||
printf(" Sprite.destRec: x = %f, y = %f, width = %f, height = %f\n",
|
||||
btn.sprite.destRec.x, btn.sprite.destRec.y,
|
||||
btn.sprite.destRec.width, btn.sprite.destRec.height);
|
||||
printf(" Sprite.frameSize: x = %f, y = %f\n",
|
||||
btn.sprite.frameSize.x, btn.sprite.frameSize.y);
|
||||
printf(" Sprite.origin: x = %f, y = %f\n",
|
||||
btn.sprite.origin.x, btn.sprite.origin.y);
|
||||
printf(" Sprite.rotation: %f\n", btn.sprite.rotation);
|
||||
printf(" Sprite.color: r = %d, g = %d, b = %d, a = %d\n",
|
||||
btn.sprite.color.r, btn.sprite.color.g,
|
||||
btn.sprite.color.b, btn.sprite.color.a);
|
||||
printf(" notClicked: x = %f, y = %f\n", btn.notClicked.x, btn.notClicked.y);
|
||||
printf(" clicked: x = %f, y = %f\n", btn.clicked.x, btn.clicked.y);
|
||||
}
|
||||
|
||||
int isImageButtonClicked(ImageButton *b, Sound soundHover, Sound soundClick){
|
||||
if (CheckCollisionPointRec(GetMousePosition(), b->sprite.destRec)) {
|
||||
|
||||
if (!b->isHovered) {
|
||||
PlaySound(soundHover);
|
||||
b->isHovered = true;
|
||||
UpdateSpriteSourceRec(&b->sprite, &b->hover);
|
||||
}
|
||||
|
||||
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)){
|
||||
UpdateSpriteSourceRec(&b->sprite, &b->clicked);
|
||||
if (!b->isClicked) {
|
||||
PlaySound(soundClick);
|
||||
b->isClicked = true;
|
||||
UpdateSpriteSourceRec(&b->sprite, &b->clicked);
|
||||
}
|
||||
}
|
||||
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
|
||||
{
|
||||
PlaySound(soundClick);
|
||||
b->isClicked = false;
|
||||
b->isHovered = false;
|
||||
UpdateSpriteSourceRec(&b->sprite, &b->notClicked);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
UpdateSpriteSourceRec(&b->sprite, &b->notClicked);
|
||||
b->isClicked = false;
|
||||
b->isHovered = false;
|
||||
}
|
||||
return false;
|
||||
|
||||
+13
-2
@@ -2,6 +2,7 @@
|
||||
#define INPUT_H
|
||||
|
||||
typedef struct {
|
||||
Vector2 screenPosition;
|
||||
Vector2 worldPosition;
|
||||
float zoomSpeed;
|
||||
float minZoom;
|
||||
@@ -10,17 +11,27 @@ typedef struct {
|
||||
float wheelMove;
|
||||
bool leftButton;
|
||||
bool rightButton;
|
||||
Texture2D cursorTexture;
|
||||
} Mouse;
|
||||
|
||||
Mouse CreateMouse(float zoomSpeed, float minZoom, float maxZoom){
|
||||
Mouse CreateMouse(float zoomSpeed, float minZoom, float maxZoom, Texture2D *texture){
|
||||
HideCursor();
|
||||
return (Mouse){
|
||||
.zoomSpeed = zoomSpeed,
|
||||
.minZoom = minZoom,
|
||||
.maxZoom = maxZoom
|
||||
.maxZoom = maxZoom,
|
||||
.cursorTexture = *texture
|
||||
};
|
||||
}
|
||||
|
||||
void UpdateMouseScreen(Mouse *mouse){
|
||||
mouse->screenPosition = GetMousePosition();
|
||||
|
||||
}
|
||||
|
||||
void UpdateMouse(Mouse *mouse, Camera2D *camera) {
|
||||
|
||||
mouse->screenPosition = GetMousePosition();
|
||||
mouse->worldPosition = GetScreenToWorld2D(GetMousePosition(), *camera);
|
||||
mouse->leftButton = IsMouseButtonDown(MOUSE_LEFT_BUTTON);
|
||||
mouse->rightButton = IsMouseButtonDown(MOUSE_RIGHT_BUTTON);
|
||||
|
||||
@@ -40,4 +40,15 @@ void RenderSprite(const Sprite *sprite){
|
||||
);
|
||||
}
|
||||
|
||||
void PrintSprite(const Sprite *sprite) {
|
||||
printf("Sprite:\n");
|
||||
printf(" Sprite.texture: id = %d\n", sprite->texture.id);
|
||||
printf(" Sprite.sourceRec: x = %f, y = %f, width = %f, height = %f\n", sprite->sourceRec.x, sprite->sourceRec.y, sprite->sourceRec.width, sprite->sourceRec.height);
|
||||
printf(" Sprite.destRec: x = %f, y = %f, width = %f, height = %f\n", sprite->destRec.x, sprite->destRec.y, sprite->destRec.width, sprite->destRec.height);
|
||||
printf(" Sprite.frameSize: x = %f, y = %f\n", sprite->frameSize.x, sprite->frameSize.y);
|
||||
printf(" Sprite.origin: x = %f, y = %f\n", sprite->origin.x, sprite->origin.y);
|
||||
printf(" Sprite.rotation: %f\n", sprite->rotation);
|
||||
printf(" Sprite.color: r = %d, g = %d, b = %d, a = %d\n", sprite->color.r, sprite->color.g, sprite->color.b, sprite->color.a);
|
||||
}
|
||||
|
||||
#endif // SPRITE_H
|
||||
|
||||
Reference in New Issue
Block a user