2
0

Example_-_ClipboardArrayToImage.c 6.4 KB

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