Page 1 of 1

Drawing clear solid rectangles in NXC

Posted: 04 Dec 2010, 20:40
by mattallen37
How do you draw clear solid rectangles in NXC? I know how to draw clear rectangles, OR solid rectangles, but how do you do clear solid rectangles?

Re: Drawing clear solid rectangles in NXC

Posted: 04 Dec 2010, 20:51
by mightor
Clear solid? What do you mean exactly? Can you draw it in ms paint or something similar so we know what it is supposed to look like?

- Xander

Re: Drawing clear solid rectangles in NXC

Posted: 04 Dec 2010, 20:59
by mattallen37
How about I post a program that draws in white.

Code: Select all

task main()
{
  RectOut(0, 0, 100, 64, DRAW_OPT_FILL_SHAPE); //Blacks out a solid rectangle
  
  RectOut(25, 16, 50, 32, DRAW_OPT_CLEAR);     //Whites out a normal rectangle
  RectOut(25, 24, 50, 32, DRAW_OPT_CLEAR);     //Whites out a normal rectangle
  RectOut(25, 8, 50, 32, DRAW_OPT_CLEAR);      //Whites out a normal rectangle
  RectOut(13, 16, 50, 32, DRAW_OPT_CLEAR);     //Whites out a normal rectangle
  RectOut(37, 16, 50, 32, DRAW_OPT_CLEAR);     //Whites out a normal rectangle
  
  while(true);
}
You can draw solid shapes using the DRAW_OPT_FILL_SHAPE macro. You can draw white on black using the DRAW_OPT_CLEAR macro. I want to draw solid white on a black background.

Re: Drawing clear solid rectangles in NXC

Posted: 04 Dec 2010, 21:01
by mattallen37
Never mind, I just figured it out. The two macros have the values of 32 and 4, so I just tried combining them using the value 36, and it works. Thanks anyhow.

Re: Drawing clear solid rectangles in NXC

Posted: 04 Dec 2010, 23:50
by muntoo
mattallen37 wrote:Never mind, I just figured it out. The two macros have the values of 32 and 4, so I just tried combining them using the value 36, and it works. Thanks anyhow.
That "standard" way to do it is:

Code: Select all

int There = 51, AndBackAgain = 52; // This is how little folk code
int ToTheFuture = 99; // Mad scientists code this
int AndLOTRpwnsBTTF = true; // Geniuses only

RectOut(There, AndBackAgain, ToTheFuture, AndLOTRpwnsBTTF, DRAW_OPT_CLEAR | DRAW_OPT_FILL_SHAPE);

Re: Drawing clear solid rectangles in NXC

Posted: 05 Dec 2010, 00:05
by mattallen37
Ok. I would think though that you would do something like DRAW_OPT_CLEAR + DRAW_OPT_FILL_SHAPE instead of DRAW_OPT_CLEAR | DRAW_OPT_FILL_SHAPE for the last parameter. Using the "+" obviously adds the constants (macros), thus still getting a sum of 36 (which is the value I am using). What does the single "|" do?

Re: Drawing clear solid rectangles in NXC

Posted: 05 Dec 2010, 05:30
by m-goldberg
mattallen37 wrote:Ok. I would think though that you would do something like DRAW_OPT_CLEAR + DRAW_OPT_FILL_SHAPE instead of DRAW_OPT_CLEAR | DRAW_OPT_FILL_SHAPE for the last parameter. Using the "+" obviously adds the constants (macros), thus still getting a sum of 36 (which is the value I am using). What does the single "|" do?
In Standard C and NXC, '|' is bit-wise OR. Since the drawing options are all powers of two (a common way to implement boolean options), '+' and '|' have the same effect in this case.

Re: Drawing clear solid rectangles in NXC

Posted: 05 Dec 2010, 05:38
by muntoo
mattallen37 wrote:Ok. I would think though that you would do something like DRAW_OPT_CLEAR + DRAW_OPT_FILL_SHAPE instead of DRAW_OPT_CLEAR | DRAW_OPT_FILL_SHAPE for the last parameter. Using the "+" obviously adds the constants (macros), thus still getting a sum of 36 (which is the value I am using). What does the single "|" do?
You sound like Linus ;). (I saw him using '+' to add macros.)

For flags, you use Bitwise-OR ("|") *. For other stuff (I don't know what exactly), you use adding, or whatever you use. My point is... OK, hold on, I've asked it on programmers.stackexchange.com HERE.

Someone over here is using the Bitwise-OR method.

*That looks strangely like a messed up smiley.

Re: Drawing clear solid rectangles in NXC

Posted: 05 Dec 2010, 06:26
by mattallen37
Ah yes, I see it now. The third and sixth least significant bits (0x04 and 0x20) are the ones used here. Thanks for the clarification/explanation.