Advertisement
Ridwanul_Haque

iGraphics_SevenSegment (Offline-2) (L1,T1)

Jun 7th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.74 KB | None | 0 0
  1. #include "iGraphics.h"
  2.  
  3. char str[100], str2[100], key;
  4. int len;
  5. int mode;
  6. int x1=400,x2,r=255,g=0,b=0;
  7.  
  8. void drawTextBox()
  9. {
  10.     iSetColor(150, 150, 150);
  11.     iRectangle(50, 250, 250, 30);
  12. }
  13. void ValueChange(void)
  14. {
  15.     if(r>655&&g>255&&b>100)
  16.    {
  17.        r=255;
  18.        g=0;
  19.        b=0;
  20.        r=r+100;
  21.        g=g+10;
  22.        b=b+20;
  23.    }
  24.    else{
  25.         r=r+10;
  26.         g=g+30;
  27.         b=b+5;
  28.        }
  29.     if(x2<=0)
  30.     {
  31.         x1=420;
  32.         x1=x1-3;
  33.     }
  34.     else x1=x1-3;
  35. }
  36. void iDrawCharacter(char key, int x)
  37. {
  38.  
  39.     int segment1,segment2,segment3,segment4,segment5,segment6,segment7,segmentNormal=30;
  40.     segment1=segmentNormal;segment2=segmentNormal;segment3=segmentNormal;segment4=segmentNormal;segment5=segmentNormal;segment6=segmentNormal;segment7=segmentNormal;
  41.     if(key=='1') {segment1=0;segment2=0;segment4=0;segment5=0;segment7=0;}
  42.     else if(key=='2') {segment2=0;segment6=0;}
  43.     else if(key=='3') {segment2=0;segment5=0;}
  44.     else if(key=='4') {segment1=0;segment5=0;segment7=0;}
  45.     else if(key=='5') {segment3=0;segment5=0;}
  46.     else if(key=='6') {segment3=0;}
  47.     else if(key=='7') {segment2=0;segment4=0;segment5=0;segment7=0;}
  48.     else if(key=='8') {segment1=segmentNormal;segment2=segmentNormal;segment3=segmentNormal;segment4=segmentNormal;segment5=segmentNormal;segment6=segmentNormal;segment7=segmentNormal;}
  49.     else if(key=='9') {segment5=0;}
  50.     else if(key=='0') {segment4=0;}
  51.     else if(key=='A') {segment7=0;}
  52.     else if(key=='B') {segment1=0;segment3=0;}
  53.     else if(key=='C') {segment3=0;segment4=0;segment6=0;}
  54.     else if(key=='D') {segment1=0;segment2=0;}
  55.     else if(key=='E') {segment3=0;segment6=0;}
  56.     else if(key=='F') {segment3=0;segment6=0;segment7=0;}
  57.     else {segment1=0;segment2=0;segment3=0;segment4=0;segment5=0;segment6=0;segment7=0;}
  58.  
  59.     iSetColor(r, g, b);
  60.     iFilledRectangle(x+3+1, 50+30+30+3+2+30+1, segment1, 3);
  61.     iFilledRectangle(x, 50+30+30+3+2, 3, segment2);
  62.     iFilledRectangle(x+30+3+1, 50+30+30+3+2, 3, segment3);
  63.     iFilledRectangle(x+3+1, 50+30+30+1, segment4, 3);
  64.     iFilledRectangle(x, 50+30, 3, segment5);
  65.     iFilledRectangle(x+30+3+1, 50+30, 3, segment6);
  66.     iFilledRectangle(x+3+1, 50+30-3-1, segment7, 3);
  67.  
  68.     //ValueChange();
  69. }
  70.  
  71. /*
  72.     function iDraw() is called again and again by the system.
  73. */
  74. void iDraw()
  75. {
  76.     //place your drawing codes here
  77.     /*int i;
  78.     int x1=30;
  79.     char key;*/
  80.     iClear();
  81.     int i;
  82.     x2=x1;
  83.     //int x2=x1;
  84.     //char key;
  85.  
  86.     drawTextBox();
  87.     if(mode == 1)
  88.     {
  89.         iSetColor(255, 255, 255);
  90.         iText(55, 260, str);
  91.     }
  92.  
  93.     iText(10, 10, "Click to activate the box, enter to finish.");
  94.  
  95.     iSetColor(r,g,b);
  96.  
  97.  
  98.  
  99.     for(i=0; i<strlen(str); i++)
  100.     {
  101.  
  102.         key = str[i];
  103.  
  104.         iDrawCharacter(key, x2);
  105.         x2+=50;
  106.  
  107.     }
  108.  
  109.     //ValueChange();
  110. }
  111.  
  112. /*
  113.     function iMouseMove() is called when the user presses and drags the mouse.
  114.     (mx, my) is the position where the mouse pointer is.
  115. */
  116. void iMouseMove(int mx, int my)
  117. {
  118.     //place your codes here
  119. }
  120.  
  121. /*
  122.     function iMouse() is called when the user presses/releases the mouse.
  123.     (mx, my) is the position where the mouse pointer is.
  124. */
  125. void iMouse(int button, int state, int mx, int my)
  126. {
  127.     if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
  128.     {
  129.         //place your codes here
  130.         if(mx >= 50 && mx <= 300 && my >= 250 && my <= 280 && mode == 0)
  131.         {
  132.             mode = 1;
  133.         }
  134.     }
  135.     if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
  136.     {
  137.         //place your cods here
  138.     }
  139. }
  140.  
  141. /*
  142.     function iKeyboard() is called whenever the user hits a key in keyboard.
  143.     key- holds the ASCII value of the key pressed.
  144. */
  145. void iKeyboard(unsigned char key)
  146. {
  147.     int i;
  148.     if(mode == 1)
  149.     {
  150.         if(key == '\r')
  151.         {
  152.             mode = 0;
  153.             strcpy(str2, str);
  154.             printf("%s\n", str2);
  155.             for(i = 0; i < len; i++)
  156.                 str[i] = 0;
  157.             len = 0;
  158.         }
  159.         else
  160.         {
  161.             str[len] = key;
  162.             len++;
  163.         }
  164.     }
  165.  
  166.     if(key == 'x')
  167.     {
  168.         //do something with 'x'
  169.         exit(0);
  170.     }
  171.     //place your cods for other keys here
  172. }
  173.  
  174. /*
  175.     function iSpecialKeyboard() is called whenever user hits special keys like-
  176.     function keys, home, end, pg up, pg down, arrows etc. you have to use
  177.     appropriate constants to detect them. A list is:
  178.     GLUT_KEY_F1, GLUT_KEY_F2, GLUT_KEY_F3, GLUT_KEY_F4, GLUT_KEY_F5, GLUT_KEY_F6,
  179.     GLUT_KEY_F7, GLUT_KEY_F8, GLUT_KEY_F9, GLUT_KEY_F10, GLUT_KEY_F11, GLUT_KEY_F12,
  180.     GLUT_KEY_LEFT, GLUT_KEY_UP, GLUT_KEY_RIGHT, GLUT_KEY_segmentNormalOWN, GLUT_KEY_PAGE UP,
  181.     GLUT_KEY_PAGE segmentNormalOWN, GLUT_KEY_HOME, GLUT_KEY_ENsegmentNormal, GLUT_KEY_INSERT
  182. */
  183. void iSpecialKeyboard(unsigned char key)
  184. {
  185.  
  186.     if(key == GLUT_KEY_END)
  187.     {
  188.         exit(0);
  189.     }
  190.  
  191.     //place your codes for other keys here
  192. }
  193.  
  194. int main()
  195. {
  196.     //place your own initialization codes here.
  197.     len = 0;
  198.     mode = 0;
  199.     str[0]= 0;
  200.     iSetTimer(50, ValueChange);
  201.     iInitialize(420, 400, "TextInputDemo");
  202.     return 0;
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement