Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - How do I draw into a newly created buffer?
Page 1 of 1

PostPosted: Wed Jul 10, 2002 10:22 pm
by design4use
The documentation says:
use bool create(int w, int h) to create a new buffer. However how do I then draw into the buffer and modify it before putting the buffer back on the screen. Can somebody show me an example?
I have sucessfully drawn into a gadget draw object but its not clear to me how to obtain a buffer draw object to draw into.

PostPosted: Thu Jul 11, 2002 5:37 pm
by design4use
OK after some nightly experimentation I had a little bit of success. Here is what I did:
In the UIGadget code
declared 2 Draw objects, one attached the gadget and the other for use as a buffer.
Then I added this function and called it from the gadget's ondraw() handler:
void gaListMgr.testDraw() {
bool success;
int prev;

success = dBuffer.create(100,100);
if (success) {
prev = dBuffer.fg(255);
dBuffer.line(clrFG, 10, 10, 50, 50);
dBuffer.frame(clrFG,1,1,98, 98, 2, 2);
dBuffer.draw(dBuffer, 30, 60);

draw.begin();
draw.draw(dBuffer, 10,10);
draw.end();
}
dBuffer.release();
}

The outcome that was unexpected is that it drew the buffer (yay!!!) but not relative to the coordinates of the gadget, but instead using absolute screen coordinates. This is a bug, right? All other drawing operations on a gadget usually are relative to the gadget's origin, so this confused me.<b></b>

PostPosted: Fri Jul 12, 2002 4:08 am
by dewey
Yes, Draw.draw will draw a given buffer into another Draw object (in this case, the gadget). The reason that it drew screen relative is likely that you forgot to first attach the Draw to the gadget using Draw.attachGadget().

Tip: If you want to draw the entire contents of the gadget to an offscreen buffer, then copy it to the gadget - use two draw objects. Attach the first to the gadget, and create the second one using Draw.copyGadget(), rather than Draw.create()

PostPosted: Fri Jul 12, 2002 5:54 pm
by design4use
I really do think it's a bug.
If I understand you correctly you say that I need to to attach the draw object I draw into to the gadget, not the buffer Draw object. If you look at the full source below, I already do that in the code. The gadget I have is positioned on the form at about 50,50, yet I still see the drawing from the buffer appear at 0,0 on the form. So if I am not mistaken this is a bug in OrbForms drawing code.


// gadget declaration

object myGadget {
// A UIGadget must always be the first member of a gadget
UIGadget gadget;
Draw draw, dBuffer;
// default event handlers
void onopen();
void ondraw();

void testDraw();
};


void myGadget.onopen() {
// todo: provide customized code for initialization
draw.attachGadget(gadget);
dBuffer.copyGadget(gadget);
}

void myGadget.ondraw() {
// todo: provide customized drawing code
testDraw();
}

void myGadget.testDraw() {
int prev;

prev = dBuffer.fg(255);
dBuffer.line(clrFG, 10, 10, 50, 50);
dBuffer.frame(clrFG,1,1,98, 98, 2, 2);
dBuffer.draw(dBuffer, 30, 60);

draw.begin();
draw.draw(dBuffer, 10,10);
draw.end();
dBuffer.release();
}

PostPosted: Fri Jul 12, 2002 6:15 pm
by design4use
The second bug I see is that when I remove the 3 lines near the end where dBuffer is drawn to the gadget's draw object, the buffer still visibly draws on the form.
Shouldn't a drawing operation to a buffer be invisible until the program tells the buffer to draw its contents to the screen?

PostPosted: Fri Jul 12, 2002 10:02 pm
by dewey
Please send me the complete project, and I will take a look at it. I will look at the second bug as well.

You should not be doing this:
dBuffer.draw(dBuffer, 30, 60);

That will only redraw the buffer on top of itself.

PostPosted: Sat Jul 13, 2002 3:40 pm
by dewey
1) you must call dBuffer.begin() and dBuffer.end() to set the draw window correctly - otherwise the line/frame functions will draw to the current window, which is the form.

2) You cannot call Draw.copyGadget() in the onopen handler, because the gadget is not visible and cannot be copied. It would be best to have dBuffer as a local to the draw function, creating and releasing it there.

3) Draw.fg(255) will fail cause a warning on non-color devices with a debug ROM because 255 is not in the valid color range in < 256 color mode. The warning causes the draw window to be reset, so drawing will occur on the form window in debug ROMs.

PostPosted: Sat Jul 13, 2002 7:03 pm
by design4use
Thank you very much, your answer was very helpful. The aspects I feel could be better documented are that the gadget cannot be copied into Draw on opening it, as well as the color restrictions you mentioned. The docs only mention the 256 colors available, so I assumed if it didn't find the color on a <8-bit device it would just pick the nearest available.

In the interested of sharing the working result, here it is what worked for me:
// gadget declaration

object myGadget {
// A UIGadget must always be the first member of a gadget
UIGadget gadget;
Draw draw;
// default event handlers
void onopen();
void ondraw();

void testDraw();
};


void myGadget.onopen() {
// attach Draw to gadget
draw.attachGadget(gadget);
}

void myGadget.ondraw() {
// call test function
testDraw();
}

void myGadget.testDraw() {
int prev, i;
Draw dBuffer;//buffer is now local
//create a buffer the size of gadget
dBuffer.copyGadget(gadget);

//draw things into the buffer
dBuffer.begin();
prev = dBuffer.fg(10);
dBuffer.line(clrFG, 10, 10, 50, 50);
dBuffer.frame(clrFG,1,1,gadget.w, gadget.h, 2, 2);
dBuffer.end();

//blast the buffer contents to the screen
draw.begin();
draw.draw(dBuffer, 0,0);
draw.end();
dBuffer.release();
}

PostPosted: Mon Jul 15, 2002 7:03 pm
by damien
Ive found that the best performance can be had by allocating the offscreen buffer once in the onopen() handler, and then always drawing to the offscreen buffer and then blasting that onto the screen. This save creating, copying and releasing the offscreen buffer with every ondraw() event.


object myGadget {
// A UIGadget must always be the first member of a gadget
UIGadget gadget;
Draw draw, dBuffer;
// default event handlers
void onopen();
void ondraw();

void myGadget.onopen() {
// attach Draw to gadget
draw.attachGadget(gadget);
// create offscreen buffer
dBuffer.create(gadget.w, gadget.h);
}

void myGadget.ondraw() {
// call test function
testDraw();
}

void myGadget.testDraw() {
int prev, i;

//draw things into the buffer
dBuffer.begin();
prev = dBuffer.fg(10);
dBuffer.line(clrFG, 10, 10, 50, 50);
dBuffer.frame(clrFG,1,1,gadget.w, gadget.h, 2, 2);
dBuffer.end();

//blast the buffer contents to the screen
draw.begin();
draw.draw(dBuffer, 0,0);
draw.end();
}