Example_-_ClipboardArrayToImage.c 6.5 KB

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