ROBOTC.net forums
http://www.robotc.net/forums/

cursor.c
http://www.robotc.net/forums/viewtopic.php?f=15&t=2388
Page 1 of 1

Author:  DIEvAl [ Tue May 18, 2010 1:23 pm ]
Post subject:  cursor.c

Current version: 1.1

This is the library, that creates a cursor on NXT screen. You can controll it using 2 motor joystick with touch sensor (like this. It has 2 touch sensors, but only 1 can be used by this program).
You can also create up to 32 buttons. Each button has different ID (number 0..31) and can be rectangular or circular. You can get the ID of the pressed button using the nButtonPressed variable.
Buttons 0..3 have hotkeys:
RobotC help - Buttons wrote:
*NOTE* 0 = Gray Rectangle button. 1 = Right Arrow button. 2 = Left Arrow button. 3 = Orange Square button


Varables and functions:
Code:
VARABLES:
[Name]              [Description]                                 [Note]                                          [Example]
nButtonPressed      -1: none, 0..31: ID of pressed button         Is set only when you press or release button    nxtDisplayStringAt(80, 32, "%d", nButtonPressed);
nButtonOver         -1: none, 0..31: ID of button under cursor    Is set every 40 msec                            nxtDisplayStringAt(80, 32, "%d", nButtonOver);


FUNCTIONS:
[Name]                                                                        [Description]                          [Example]
init(int t=S1, int mX=motorB, int mY=motorC, int sX=50, int sY=-50)           Initialisation                         init(S1, motorB, motorC, 50, -50);
                                                                              t:     port of Touch sensor            init()
                                                                              mX/mY: port of Motor X/Y
                                                                              sX/sY: Speed of cursor

createButton(int ID, int left, int top, int right, int bottom, string text,   Creates rectangular button             createButton(5,  85, 45, 95, 35, "/");
TAlign align=alignCenter, TValign valign=valignCenter)                        ID: ID of button                       createButton(3, 3, 61, 50, 43, "3", alignLeft, valignTop);
                                                                              left, top, right, bottom: position
                                                                              text: text. If too long, is truncated
                                                                              align: alignLeft, alignCenter
                                                                                     or alignRight
                                                                              valign: valignTop, valignCenter
                                                                                      or valignBottom
 
createButtonCircle(int ID, int x, int y, int radius, string text)             Creates circular button                createButton(5,  85, 45, 95, 35, "/");
                                                                              ID: ID of button                       createButton(3, 3, 61, 50, 43, "3", alignLeft, valignTop);
                                                                              x, y, radius: position
                                                                              text: text. If too long, is truncated

void deleteButton(int ID);                                                    Deletes button                         deleteButton(i);
                                                                              ID: ID of button

void deleteAllButtons();                                                      Deletes all buttons                    deleteAllButtons();


There are 2 sample programs:
  • cursor_sample.c (V1.1): This program creates three rectangular buttons and two circular buttons, shows ID of pressed button on the screen, and stops when you press "X" button.
  • cursor_calc.c (V1.0): This program is a simple calculator:
    Code:
    ---------------------
    |                 - |
    | 12345678       |X||
    |                 - |
    | -  -  -  -   -  - |
    ||7||8||9||C| |*||/||
    | -  -  -  -   -  - |
    | -  -  -      -  - |
    ||4||5||6|    | ||-||
    | -  -  -     |+| - |
    | -  -  -  -  | | - |
    ||1||2||3||0| | ||=||
    | -  -  -  -   -  - |
    ---------------------


Attachments:
cursor.c [5.72 KiB]
Downloaded 415 times
cursor_sample.c [1.89 KiB]
Downloaded 436 times
cursor_calc.c [4.88 KiB]
Downloaded 425 times

Author:  DIEvAl [ Tue May 18, 2010 1:43 pm ]
Post subject:  Re: cursor.c

Images:

Attachments:
File comment: cursor_calc.c
IMGP0245.JPG
IMGP0245.JPG [ 42.23 KiB | Viewed 4849 times ]

Author:  DIEvAl [ Fri May 21, 2010 5:26 am ]
Post subject:  Re: cursor.c

Version 1.1 released!
New features:
  • Circular buttons.
  • Aligned text in rectangular buttons.
  • Variable nButtonOver.

Main post updated.

Attachments:
cursor.c [5.66 KiB]
Downloaded 433 times

Author:  mightor [ Fri May 21, 2010 1:51 pm ]
Post subject:  Re: cursor.c

This is a very nice library you made. Thank you for sharing!

Regards,
Xander

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/