Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "iGraphics.h"
- char str[100], str2[100], key;
- int len;
- int mode;
- int x1=400,x2,r=255,g=0,b=0;
- void drawTextBox()
- {
- iSetColor(150, 150, 150);
- iRectangle(50, 250, 250, 30);
- }
- void ValueChange(void)
- {
- if(r>655&&g>255&&b>100)
- {
- r=255;
- g=0;
- b=0;
- r=r+100;
- g=g+10;
- b=b+20;
- }
- else{
- r=r+10;
- g=g+30;
- b=b+5;
- }
- if(x2<=0)
- {
- x1=420;
- x1=x1-3;
- }
- else x1=x1-3;
- }
- void iDrawCharacter(char key, int x)
- {
- int segment1,segment2,segment3,segment4,segment5,segment6,segment7,segmentNormal=30;
- segment1=segmentNormal;segment2=segmentNormal;segment3=segmentNormal;segment4=segmentNormal;segment5=segmentNormal;segment6=segmentNormal;segment7=segmentNormal;
- if(key=='1') {segment1=0;segment2=0;segment4=0;segment5=0;segment7=0;}
- else if(key=='2') {segment2=0;segment6=0;}
- else if(key=='3') {segment2=0;segment5=0;}
- else if(key=='4') {segment1=0;segment5=0;segment7=0;}
- else if(key=='5') {segment3=0;segment5=0;}
- else if(key=='6') {segment3=0;}
- else if(key=='7') {segment2=0;segment4=0;segment5=0;segment7=0;}
- else if(key=='8') {segment1=segmentNormal;segment2=segmentNormal;segment3=segmentNormal;segment4=segmentNormal;segment5=segmentNormal;segment6=segmentNormal;segment7=segmentNormal;}
- else if(key=='9') {segment5=0;}
- else if(key=='0') {segment4=0;}
- else if(key=='A') {segment7=0;}
- else if(key=='B') {segment1=0;segment3=0;}
- else if(key=='C') {segment3=0;segment4=0;segment6=0;}
- else if(key=='D') {segment1=0;segment2=0;}
- else if(key=='E') {segment3=0;segment6=0;}
- else if(key=='F') {segment3=0;segment6=0;segment7=0;}
- else {segment1=0;segment2=0;segment3=0;segment4=0;segment5=0;segment6=0;segment7=0;}
- iSetColor(r, g, b);
- iFilledRectangle(x+3+1, 50+30+30+3+2+30+1, segment1, 3);
- iFilledRectangle(x, 50+30+30+3+2, 3, segment2);
- iFilledRectangle(x+30+3+1, 50+30+30+3+2, 3, segment3);
- iFilledRectangle(x+3+1, 50+30+30+1, segment4, 3);
- iFilledRectangle(x, 50+30, 3, segment5);
- iFilledRectangle(x+30+3+1, 50+30, 3, segment6);
- iFilledRectangle(x+3+1, 50+30-3-1, segment7, 3);
- //ValueChange();
- }
- /*
- function iDraw() is called again and again by the system.
- */
- void iDraw()
- {
- //place your drawing codes here
- /*int i;
- int x1=30;
- char key;*/
- iClear();
- int i;
- x2=x1;
- //int x2=x1;
- //char key;
- drawTextBox();
- if(mode == 1)
- {
- iSetColor(255, 255, 255);
- iText(55, 260, str);
- }
- iText(10, 10, "Click to activate the box, enter to finish.");
- iSetColor(r,g,b);
- for(i=0; i<strlen(str); i++)
- {
- key = str[i];
- iDrawCharacter(key, x2);
- x2+=50;
- }
- //ValueChange();
- }
- /*
- function iMouseMove() is called when the user presses and drags the mouse.
- (mx, my) is the position where the mouse pointer is.
- */
- void iMouseMove(int mx, int my)
- {
- //place your codes here
- }
- /*
- function iMouse() is called when the user presses/releases the mouse.
- (mx, my) is the position where the mouse pointer is.
- */
- void iMouse(int button, int state, int mx, int my)
- {
- if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
- {
- //place your codes here
- if(mx >= 50 && mx <= 300 && my >= 250 && my <= 280 && mode == 0)
- {
- mode = 1;
- }
- }
- if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
- {
- //place your cods here
- }
- }
- /*
- function iKeyboard() is called whenever the user hits a key in keyboard.
- key- holds the ASCII value of the key pressed.
- */
- void iKeyboard(unsigned char key)
- {
- int i;
- if(mode == 1)
- {
- if(key == '\r')
- {
- mode = 0;
- strcpy(str2, str);
- printf("%s\n", str2);
- for(i = 0; i < len; i++)
- str[i] = 0;
- len = 0;
- }
- else
- {
- str[len] = key;
- len++;
- }
- }
- if(key == 'x')
- {
- //do something with 'x'
- exit(0);
- }
- //place your cods for other keys here
- }
- /*
- function iSpecialKeyboard() is called whenever user hits special keys like-
- function keys, home, end, pg up, pg down, arrows etc. you have to use
- appropriate constants to detect them. A list is:
- GLUT_KEY_F1, GLUT_KEY_F2, GLUT_KEY_F3, GLUT_KEY_F4, GLUT_KEY_F5, GLUT_KEY_F6,
- GLUT_KEY_F7, GLUT_KEY_F8, GLUT_KEY_F9, GLUT_KEY_F10, GLUT_KEY_F11, GLUT_KEY_F12,
- GLUT_KEY_LEFT, GLUT_KEY_UP, GLUT_KEY_RIGHT, GLUT_KEY_segmentNormalOWN, GLUT_KEY_PAGE UP,
- GLUT_KEY_PAGE segmentNormalOWN, GLUT_KEY_HOME, GLUT_KEY_ENsegmentNormal, GLUT_KEY_INSERT
- */
- void iSpecialKeyboard(unsigned char key)
- {
- if(key == GLUT_KEY_END)
- {
- exit(0);
- }
- //place your codes for other keys here
- }
- int main()
- {
- //place your own initialization codes here.
- len = 0;
- mode = 0;
- str[0]= 0;
- iSetTimer(50, ValueChange);
- iInitialize(420, 400, "TextInputDemo");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement