View unanswered posts | View active topics It is currently Thu Apr 24, 2014 11:03 pm






Reply to topic  [ 4 posts ] 
cursor.c 
Author Message
Rookie

Joined: Sun May 16, 2010 3:31 pm
Posts: 10
Post 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 265 times
cursor_sample.c [1.89 KiB]
Downloaded 284 times
cursor_calc.c [4.88 KiB]
Downloaded 274 times


Last edited by DIEvAl on Mon May 24, 2010 2:56 pm, edited 2 times in total.

Tue May 18, 2010 1:23 pm
Profile
Rookie

Joined: Sun May 16, 2010 3:31 pm
Posts: 10
Post Re: cursor.c
Images:


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


Last edited by DIEvAl on Fri May 21, 2010 5:58 am, edited 1 time in total.

Tue May 18, 2010 1:43 pm
Profile
Rookie

Joined: Sun May 16, 2010 3:31 pm
Posts: 10
Post 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 285 times
Fri May 21, 2010 5:26 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3116
Location: Rotterdam, The Netherlands
Post Re: cursor.c
This is a very nice library you made. Thank you for sharing!

Regards,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri May 21, 2010 1:51 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.