Example_-_ClipboardArrayToImage.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //
  2. //
  3. //
  4. //
  5. #include "raylib.h"
  6. #include <string.h>
  7. static Color c64color[16]; //' our colors
  8. static int countcommas(char *in);
  9. static int countnumbers(char *in);
  10. static bool importspriteis8x8(int in);
  11. static bool importspriteis16x16(int in);
  12. static bool importspriteis32x32(int in);
  13. static void readtempsprite(int w,int h,char *in);
  14. static void create8x8sprite();
  15. static void inic64colors();
  16. static RenderTexture2D target;
  17. static int tempsprite[8][8] = {0};
  18. int main(void)
  19. {
  20. // Initialization
  21. //--------------------------------------------------------------------------------------
  22. const int screenWidth = 800;
  23. const int screenHeight = 450;
  24. InitWindow(screenWidth, screenHeight, "raylib example.");
  25. inic64colors();
  26. target = LoadRenderTexture(32,32);
  27. BeginTextureMode(target);
  28. ClearBackground(BLACK); // Make the entire Sprite Transparent.
  29. EndTextureMode();
  30. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  31. //--------------------------------------------------------------------------------------
  32. // Create a char to read the clipboard with.
  33. char clipBoardTxt[1024];
  34. // Create a pointer to the clipboardtxt char
  35. const char *clipPointer = clipBoardTxt;
  36. // Read the contents of the clipboard into the clipboardtxt pointer
  37. clipPointer = GetClipboardText();
  38. // create a char
  39. char work[1024];
  40. // copy the contents of the char that has a pointer containing the clipboard txt into this work char
  41. strcpy(work,clipPointer);
  42. // count the comma's and the numbers.
  43. int numCommas = countcommas(work);
  44. int numNumbers = countnumbers(work);
  45. static bool banana=false;
  46. if(importspriteis8x8(numNumbers)){
  47. readtempsprite(8,8,work);
  48. create8x8sprite();
  49. banana=true;
  50. }
  51. // Main game loop
  52. while (!WindowShouldClose()) // Detect window close button or ESC key
  53. {
  54. // Update
  55. //----------------------------------------------------------------------------------
  56. //----------------------------------------------------------------------------------
  57. // Draw
  58. //----------------------------------------------------------------------------------
  59. BeginDrawing();
  60. ClearBackground(RAYWHITE);
  61. if(banana){
  62. DrawText("~!!!!!!!!!!!!!",0,0,20,BLACK);
  63. }
  64. DrawText(work,100,100,20,BLACK);
  65. DrawText(FormatText("Comma Count : %i",numCommas),100,80,20,BLACK);
  66. DrawText(FormatText("Number Count : %i",numNumbers),100,60,20,BLACK);
  67. if(importspriteis8x8(numNumbers)){
  68. DrawText("Sprite is 8x8",100,40,20,BLACK);
  69. }
  70. for(int y=0;y<8;y++){
  71. for(int x=0;x<8;x++){
  72. DrawText(FormatText("%i",tempsprite[y][x]),x*30,y*30,20,BLACK);
  73. }
  74. }
  75. DrawTexture(target.texture,100,100, WHITE);
  76. EndDrawing();
  77. //----------------------------------------------------------------------------------
  78. }
  79. // De-Initialization
  80. //--------------------------------------------------------------------------------------
  81. UnloadRenderTexture(target); // Unload render texture
  82. CloseWindow(); // Close window and OpenGL context
  83. //--------------------------------------------------------------------------------------
  84. return 0;
  85. }
  86. void create8x8sprite(){
  87. BeginTextureMode(target);
  88. ClearBackground(BLUE); // Make the entire Sprite Transparent.
  89. EndTextureMode();
  90. // Draw something on it.
  91. for (int y=0;y<8;y++)
  92. {
  93. for (int x=0;x<8; x++)
  94. {
  95. BeginTextureMode(target);
  96. DrawRectangle(x*4,y*4,4,4,c64color[tempsprite[y][x]]);
  97. EndTextureMode();
  98. }
  99. }
  100. }
  101. void readtempsprite(int w,int h,char *in){
  102. int cnt=0;
  103. int x=0;
  104. int y=0;
  105. for(int i=0;in[i];i++){
  106. if(in[i] >= '0' && in[i] <='9'){
  107. cnt++;
  108. if(cnt>1){
  109. x++;
  110. if(x>=w){
  111. x=0;
  112. y++;
  113. }
  114. }
  115. tempsprite[x][y] = in[i]-'0';
  116. }
  117. }
  118. }
  119. int countcommas(char *in){
  120. int out=0;
  121. for(int i=0;in[i];i++){
  122. if(in[i] == ',')out++;
  123. }
  124. return out;
  125. }
  126. int countnumbers(char *in){
  127. int out=0;
  128. for(int i=0;in[i];i++){
  129. if(in[i] >= '0' && in[i] <= '9')out++;
  130. }
  131. return out;
  132. }
  133. bool importspriteis8x8(int in){
  134. if(in-2 == 8*8)return true;
  135. return false;
  136. }
  137. bool importspriteis16x16(int in){
  138. if(in-2 == 16*16)return true;
  139. return false;
  140. }
  141. bool importspriteis32x32(int in){
  142. if(in-2 == 32*32)return true;
  143. return false;
  144. }
  145. void inic64colors(void){
  146. c64color[0 ] = (Color){0 , 0 , 0 , 255 };//Black
  147. c64color[1 ] = (Color){255,255,255, 255 };//White
  148. c64color[2 ] = (Color){136,0 ,0 , 255 };//Red
  149. c64color[3 ] = (Color){170,255,238, 255 };//Cyan
  150. c64color[4 ] = (Color){204,68 ,204, 255 };//Violet / Purple
  151. c64color[5 ] = (Color){0 ,204,85 , 255 };//Green
  152. c64color[6 ] = (Color){0 ,0 ,170, 255 };//Blue
  153. c64color[7 ] = (Color){238,238,119, 255 };//Yellow
  154. c64color[8 ] = (Color){221,136,85 , 255 };//Orange
  155. c64color[9 ] = (Color){102,68 ,0 , 255 };//Brown
  156. c64color[10] = (Color){255,119,119, 255 };//Light red
  157. c64color[11] = (Color){51 ,51 ,51 , 255 };//Dark grey / Grey 1
  158. c64color[12] = (Color){119,119,119, 255 };//Grey 2
  159. c64color[13] = (Color){170,255,102, 255 };//Light green
  160. c64color[14] = (Color){0 ,136,255, 255 };//Light blue
  161. c64color[15] = (Color){187,187,187, 255 };//Light grey / grey 3
  162. }