Advertisement
Wistaro

WIND3_test

Feb 13th, 2017
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.53 KB | None | 0 0
  1. ////////////////////////////////////////
  2. // v0.0.01
  3. // Author: William "Wistaro" Romiguieres
  4. // License: OpenSource
  5. // Description: A Windows-like in C just for fun :)
  6. ////////////////////////////////////////
  7.  
  8. /* Keep these headers */
  9. #include <stdbool.h>
  10. #include <stddef.h>
  11. #include <stdint.h>
  12. #include <tice.h>
  13.  
  14. #include <math.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <lib/ce/graphx.h>
  19. #include <lib/ce/keypadc.h>
  20. #include <decompress.h>
  21. #include "gfx_wind.h"
  22. //#include "gfx_fond.h"
  23.  
  24. #define CURSOR_MOVE_AMT 1
  25. #define CURSOR_MIN_X    0
  26. #define CURSOR_MIN_Y    0
  27. #define CURSOR_MAX_X    (LCD_WIDTH-1)
  28. #define CURSOR_MAX_Y    (LCD_HEIGHT-1)
  29.  
  30. /* Put function prototypes here */
  31. void printText(const char *text, uint8_t x, uint8_t y);
  32. void printTextSmall(const char *text, uint8_t xpos, uint8_t ypos);
  33. void printHomeScreen();
  34. void pause(int time);
  35. void printBoxMessage(uint8_t posx, uint8_t posy, char* text, uint8_t mode, gfx_image_t* windBh);
  36.  
  37. /* Put all your code here */
  38. void main(void) {
  39.     int cursor_x = 50;
  40.     int cursor_y = 50;
  41.     uint8_t demOpen = 0;
  42.     kb_key_t keyg1, keyg7, keyg2;
  43.     kb_key_t keyg6;
  44.    
  45.     gfx_image_t *behind_cursor = gfx_MallocSprite(16, 16);
  46.  
  47.     // begin graphics
  48.     gfx_Begin(gfx_8bpp);
  49.  
  50.     // draw main screen
  51.     printHomeScreen();
  52.  
  53.     // set initial state
  54.     gfx_GetSprite(behind_cursor, cursor_x, cursor_y);
  55.     gfx_TransparentSprite(cursor, cursor_x, cursor_y);
  56.  
  57.     // wait for a keypress
  58.     do {
  59.         kb_Scan();
  60.         keyg1 = kb_Data[kb_group_1];
  61.         keyg7 = kb_Data[kb_group_7];
  62.        
  63.         keyg6 = kb_Data[kb_group_6];
  64.  
  65.         if (!keyg7) continue; // if no arrows pressed, skip
  66.  
  67.         gfx_Sprite(behind_cursor, cursor_x, cursor_y);
  68.  
  69.         if(keyg7 & kb_Up) {
  70.              gfx_GetSprite(behind_cursor, cursor_x, cursor_y);
  71.             if ((cursor_y -= CURSOR_MOVE_AMT) < CURSOR_MIN_X) cursor_y = CURSOR_MIN_X;
  72.         }
  73.         if(keyg7 & kb_Down) {
  74.              gfx_GetSprite(behind_cursor, cursor_x, cursor_y);
  75.             if ((cursor_y += CURSOR_MOVE_AMT) > CURSOR_MAX_Y) cursor_y = CURSOR_MAX_Y;
  76.         }
  77.         if(keyg7 & kb_Left) {
  78.              gfx_GetSprite(behind_cursor, cursor_x, cursor_y);
  79.             if ((cursor_x -= CURSOR_MOVE_AMT) < CURSOR_MIN_Y) cursor_x = CURSOR_MIN_Y;
  80.         }
  81.         if(keyg7 & kb_Right) {
  82.            
  83.            
  84.              gfx_GetSprite(behind_cursor, cursor_x, cursor_y);
  85.             if ((cursor_x += CURSOR_MOVE_AMT) > CURSOR_MAX_X) cursor_x = CURSOR_MAX_X;
  86.         }
  87.        
  88.         if(keyg6 & kb_Enter) {
  89.            
  90.            //draw something just for debug x)
  91.            gfx_SetColor(gfx_blue);
  92.            gfx_FillRectangle(0,0,100,50);                    
  93.         }
  94.        
  95.         gfx_GetSprite(behind_cursor, cursor_x, cursor_y);
  96.         gfx_TransparentSprite(cursor, cursor_x, cursor_y);
  97.        
  98.     } while (keyg1 != kb_2nd);
  99.  
  100.     gfx_End();
  101.     free(behind_cursor);
  102.  
  103.     /* Retour à l'OS */
  104.     pgrm_CleanUp();
  105.     malloc(0);
  106. }
  107.  
  108. /* Draw text on the homescreen at the given X/Y location */
  109. void printText(const char *text, uint8_t xpos, uint8_t ypos) {
  110.     os_SetCursorPos(ypos, xpos);
  111.     os_PutStrFull(text);
  112. }
  113.  
  114. /* Draw small text at the given X/Y location */
  115. void printTextSmall(const char *text, uint8_t xpos, uint8_t ypos) {
  116.     os_FontDrawText(text, xpos, ypos);
  117. }
  118.  
  119. void printHomeScreen() {
  120.        
  121.         uint8_t a,b;
  122.  
  123.       //  gfx_image_t *fontleft_uncompress = (gfx_image_t*)0xD031F6;
  124.        // gfx_image_t *fontright_uncompress = (gfx_image_t*)0xD031F6;
  125.    
  126.         //gfx_image_t *behind_cursor = gfx_MallocSprite( 319, 239 ); //allocate space
  127.        // dzx7_Standard(fondleft, fontleft_uncompress);
  128.         //gfx_ScaledSprite_NoClip(fontleft_uncompress,0,0,1,1);
  129.        
  130.         //dzx7_Standard(fondleft, fontright_uncompress);
  131.         //gfx_ScaledSprite_NoClip(fontright_uncompress,0,0,1,1);
  132.        
  133.        
  134.         //gfx_image_t *fondleft_uncomp;
  135.         //gfx_image_t *fondright_uncomp;
  136.    
  137.         //fondleft_uncomp = gfx_MallocSprite( 154, 240 ); //allocate space
  138.         /*fondright_uncomp = gfx_MallocSprite( 167, 241 ); //allocate space
  139.    
  140.        dzx7_Standard( fondleft, fondleft_uncomp ); //uncompress sprite
  141.        dzx7_Standard( fondright, fondright_uncomp ); //uncompress sprite
  142.    
  143.          */
  144.    
  145.          //gfx_SetDrawBuffer();
  146.          gfx_FillScreen(gfx_blue);
  147.          gfx_ScaledSprite_NoClip(fond,0,0,3,3);
  148.          gfx_SetColor( 0xFF15 );
  149.          gfx_FillRectangle(0,215,319,50);
  150.          
  151.    
  152.        // gfx_ScaledSprite_NoClip(fontleft_uncompress,0,0,1,1);
  153.        // gfx_ScaledSprite_NoClip(fontright_uncompress,150,0,1,1);
  154.    
  155.          gfx_TransparentSprite(start2,0,215);
  156.          
  157.    
  158.             for(a = 0;a<=220;a = a+40){
  159.                 for(b = 0;b<=100;b = b+40){
  160.                     gfx_TransparentSprite_NoClip(folder,a,b);
  161.                 }
  162.             }
  163.    
  164.     //gfx_Sprite(xpdem,0,62);
  165.        // gfx_SwapDraw();
  166.          /*gfx_GetSprite(behind_cursor,50,100);
  167.          gfx_RotateSpriteHalf(behind_cursor,behind_cursor);
  168.          gfx_TransparentSprite_NoClip(behind_cursor,30,60);*/
  169.    
  170.          
  171.    
  172.    
  173.      //free(fondleft_uncomp); //free the memory
  174.      //free(fondright_uncomp); //free the memory
  175. }
  176.  
  177. void pause(int time){
  178.         int i;
  179.         time = 1000*time;
  180.         for(i=0; i<time; i++);
  181. }
  182.  
  183. void printBoxMessage(uint8_t posx, uint8_t posy, char* text, uint8_t mode, gfx_image_t* windBh){
  184.     gfx_SetColor( gfx_RGBTo1555(23,101,125)  );
  185.     gfx_FillRectangle(posx,posy,100,50);
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement