/******************************************************************************************* * * raylib [textures] example - Draw part of the texture tiled * * This example has been created using raylib 3.0 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2020 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5) * ********************************************************************************************/ #include "raylib.h" #define SIZEOF(A) (sizeof(A)/sizeof(A[0])) #define OPT_WIDTH 220 // max width for the options container #define MARGIN_SIZE 8 // size for the margins #define COLOR_SIZE 16 // size of the color select buttons int main(int argc, char **argv) { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; SetConfigFlags(FLAG_WINDOW_RESIZABLE); // Make the window resizable InitWindow(screenWidth, screenHeight, "raylib [textures] example - Draw part of a texture tiled"); // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) Texture ptex = LoadTexture("resources/pat.png"); SetTextureFilter(ptex, FILTER_TRILINEAR); // Makes the texture smoother when upscaled // Coordinates for all patterns inside the texture const Rectangle patRec[] = { (Rectangle){3,3,66,66}, (Rectangle){75,3,100,100}, (Rectangle){3,75,66,66}, (Rectangle){7,156,50,50}, (Rectangle){85,106,90,45}, (Rectangle){75,154,100,60} }; // Setup colors const Color colors[] = { BLACK, MAROON, ORANGE, BLUE, PURPLE, BEIGE, LIME, RED, DARKGRAY, SKYBLUE}; enum {MAX_COLORS = SIZEOF(colors)}; Rectangle colorRec[MAX_COLORS] = { 0 }; // Calculate rectangle for each color for(int i=0, x=0, y=0; i 10.0f) scale = 10.0f; else if( scale <= 0.0f) scale = 0.25f; // Change rotation if(IsKeyPressed(KEY_LEFT)) rotation -= 25.0f; if(IsKeyPressed(KEY_RIGHT)) rotation += 25.0f; // Reset if(IsKeyPressed(KEY_SPACE)) { rotation = 0.0f; scale = 1.0f; } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); // Draw the tiled area DrawTextureTiled(ptex, patRec[activePat], (Rectangle){OPT_WIDTH+MARGIN_SIZE, MARGIN_SIZE, screenWidth - OPT_WIDTH - 2*MARGIN_SIZE, screenHeight - 2*MARGIN_SIZE}, (Vector2){0.0f, 0.0f}, rotation, scale, colors[activeCol]); // Draw options DrawRectangle(MARGIN_SIZE, MARGIN_SIZE, OPT_WIDTH - MARGIN_SIZE, screenHeight-2*MARGIN_SIZE, ColorAlpha(LIGHTGRAY, 0.5f)); DrawText("Select Pattern", 2+MARGIN_SIZE, 30+MARGIN_SIZE, 10, BLACK); DrawTexture(ptex, 2+MARGIN_SIZE, 40+MARGIN_SIZE, BLACK); DrawRectangle(2+MARGIN_SIZE + patRec[activePat].x, 40+MARGIN_SIZE+patRec[activePat].y,patRec[activePat].width, patRec[activePat].height, ColorAlpha(DARKBLUE, 0.3f)); DrawText("Select Color", 2+MARGIN_SIZE, 10+256+MARGIN_SIZE, 10, BLACK); for(int i=0; i