nobody at rubyforge.org
2006-Dec-03 15:39 UTC
[Wxruby-development] [776] trunk/wxruby2: Added Bitmap#draw method, updated sample
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!-- #msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; } #msg dt { float: left; width: 6em; font-weight: bold; } #msg dt:after { content:'':'';} #msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; } #msg dl a { font-weight: bold} #msg dl a:link { color:#fc3; } #msg dl a:active { color:#ff0; } #msg dl a:visited { color:#cc6; } h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; } #msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; } #msg ul, pre { overflow: auto; } #header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; } #patch { width: 100%; } #patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;} #patch .propset h4, #patch .binary h4 {margin:0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;} #patch .propset .diff, #patch .binary .diff {padding:10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, .info {color:#888;background:#fff;} --></style> <title>[776] trunk/wxruby2: Added Bitmap#draw method, updated sample</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>776</dd> <dt>Author</dt> <dd>brokentoy</dd> <dt>Date</dt> <dd>2006-12-03 10:39:37 -0500 (Sun, 03 Dec 2006)</dd> </dl> <h3>Log Message</h3> <pre>Added Bitmap#draw method, updated sample</pre> <h3>Modified Paths</h3> <ul> <li><a href="#trunkwxruby2doctextilebitmaptxtl">trunk/wxruby2/doc/textile/bitmap.txtl</a></li> <li><a href="#trunkwxruby2doctextilememorydctxtl">trunk/wxruby2/doc/textile/memorydc.txtl</a></li> <li><a href="#trunkwxruby2samplescontrolscontrolsrb">trunk/wxruby2/samples/controls/controls.rb</a></li> </ul> <h3>Added Paths</h3> <ul> <li><a href="#trunkwxruby2libwxclassesbitmaprb">trunk/wxruby2/lib/wx/classes/bitmap.rb</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="trunkwxruby2doctextilebitmaptxtl"></a> <div class="modfile"><h4>Modified: trunk/wxruby2/doc/textile/bitmap.txtl (775 => 776)</h4> <pre class="diff"><span> <span class="info">--- trunk/wxruby2/doc/textile/bitmap.txtl        2006-12-03 12:19:45 UTC (rev 775) +++ trunk/wxruby2/doc/textile/bitmap.txtl        2006-12-03 15:39:37 UTC (rev 776) </span><span class="lines">@@ -213,7 +213,8 @@ </span><span class="cx"> If the application omits to delete the bitmap explicitly, the bitmap will be </span><span class="cx"> destroyed automatically by Widgets when the application exits. </span><span class="cx"> </span><del>-Do not delete a bitmap that is selected into a memory device context. </del><ins>+Do not delete a bitmap that is selected into a memory device context, +for example during a call to "draw":#Bitmap_draw . </ins><span class="cx"> </span><span class="cx"> h3(#Bitmap_addhandler). Bitmap#add_handler </span><span class="cx"> </span><span class="lines">@@ -286,6 +287,20 @@ </span><span class="cx"> </span><span class="cx"> "Bitmap.new":bitmap.html#Bitmap_new </span><span class="cx"> </span><ins>+h3(#Bitmap_draw). Bitmap#draw + + *draw*() { | device_context | ... } + +Allows drawing directly onto a Bitmap. Accepts a block which will be +passed a "MemoryDC":memorydc.html device context, which can be used to +draw lines, shapes and text upon a bitmap. See "DC":dc.html for the full +range of drawing methods that are available. + +Using this call ensures that the device context is properly set up for +use before drawing starts, and disposed of when drawing is +finished. It''s recommended you use this draw method rather than +instantiating MemoryDC directly. + </ins><span class="cx"> h3(#Bitmap_findhandler). Bitmap#find_handler </span><span class="cx"> </span><span class="cx"> "BitmapHandler":bitmaphandler.html *find_handler*(%(arg-type)String% name) </span></span></pre></div> <a id="trunkwxruby2doctextilememorydctxtl"></a> <div class="modfile"><h4>Modified: trunk/wxruby2/doc/textile/memorydc.txtl (775 => 776)</h4> <pre class="diff"><span> <span class="info">--- trunk/wxruby2/doc/textile/memorydc.txtl        2006-12-03 12:19:45 UTC (rev 775) +++ trunk/wxruby2/doc/textile/memorydc.txtl        2006-12-03 15:39:37 UTC (rev 776) </span><span class="lines">@@ -1,10 +1,9 @@ </span><span class="cx"> h1(#wxmemorydc). Wx::MemoryDC </span><span class="cx"> </span><del>-A memory device context provides a means to draw graphics onto a bitmap. When -drawing in to a mono-bitmap, using @WHITE@, @WHITE_PEN@ and -@WHITE_BRUSH@ -will draw the background colour (i.e. 0) whereas all other colours will draw the -foreground colour (i.e. 1). </del><ins>+A memory device context provides a means to draw graphics onto a +bitmap. When drawing in to a mono-bitmap, using @WHITE@, @WHITE_PEN@ and +@WHITE_BRUSH@ will draw the background colour (i.e. 0) whereas all other +colours will draw the foreground colour (i.e. 1). </ins><span class="cx"> </span><span class="cx"> h2. Derived from </span><span class="cx"> </span><span class="lines">@@ -15,21 +14,11 @@ </span><span class="cx"> h2. Remarks </span><span class="cx"> </span><span class="cx"> A bitmap must be selected into the new memory DC before it may be used </span><del>-for anything. Typical usage is as follows: </del><ins>+for anything. Using the "Bitmap#draw":Bitmap.html#Bitmap_draw method +with a block ensures that the DC is properly set up and disposed of, and +it''s recommended you use that method to create a MemoryDC rather than +instantiating it directly. </ins><span class="cx"> </span><del>- - // Create a memory DC - MemoryDC temp_dc; - temp_dc.SelectObject(test_bitmap); - - // We can now draw into the memory DC... - // Copy from this DC to another DC. - old_dc.Blit(250, 50, BITMAP_WIDTH, BITMAP_HEIGHT, temp_dc, 0, 0); - - -Note that the memory DC _must_ be deleted (or the bitmap selected out of it) before a bitmap -can be reselected into another memory DC. - </del><span class="cx"> h2. See also </span><span class="cx"> </span><span class="cx"> "Bitmap":bitmap.html, "DC":dc.html </span><span class="lines">@@ -52,10 +41,13 @@ </span><span class="cx"> </span><span class="cx"> Selects the given bitmap into the device context, to use as the memory </span><span class="cx"> bitmap. Selecting the bitmap into a memory DC allows you to draw into </span><del>-the DC (and therefore the bitmap) and also to use *Blit* to copy -the bitmap to a window. For this purpose, you may find "DC#draw_icon":dc.html#DC_drawicon easier to use instead. </del><ins>+the DC (and therefore the bitmap). and also to use *Blit* to copy the +bitmap to a window. For simple drawing of Bitmaps onto a window''s DC, +you may find "DC#draw_icon":dc.html#DC_drawicon easier to use instead. </ins><span class="cx"> </span><del>-If the argument is NullBitmap (or some other uninitialised Bitmap) the current bitmap is selected out of the device -context, and the original bitmap restored, allowing the current bitmap to -be destroyed safely. </del><ins>+If the argument is Wx::NULL_BITMAP (or some other uninitialised Bitmap) the +current bitmap is selected out of the device context, and the original +bitmap restored, allowing the current bitmap to be destroyed safely. </ins><span class="cx"> </span><ins>+It is recommended that you use "Bitmap#draw":Bitmap.html#Bitmap_draw +rather than creating a MemoryDC and calling select_object yourself. </ins></span></pre></div> <a id="trunkwxruby2libwxclassesbitmaprb"></a> <div class="addfile"><h4>Added: trunk/wxruby2/lib/wx/classes/bitmap.rb (0 => 776)</h4> <pre class="diff"><span> <span class="info">--- trunk/wxruby2/lib/wx/classes/bitmap.rb         (rev 0) +++ trunk/wxruby2/lib/wx/classes/bitmap.rb        2006-12-03 15:39:37 UTC (rev 776) </span><span class="lines">@@ -0,0 +1,10 @@ </span><ins>+class Wx::Bitmap + # Accepts a block, which will be passed a device context which can be + # used to draw upon the Bitmap + def draw + dc = MemoryDC.new + dc.select_object(self) + yield dc + dc.select_object( NULL_BITMAP ) + end +end </ins></span></pre></div> <a id="trunkwxruby2samplescontrolscontrolsrb"></a> <div class="modfile"><h4>Modified: trunk/wxruby2/samples/controls/controls.rb (775 => 776)</h4> <pre class="diff"><span> <span class="info">--- trunk/wxruby2/samples/controls/controls.rb        2006-12-03 12:19:45 UTC (rev 775) +++ trunk/wxruby2/samples/controls/controls.rb        2006-12-03 15:39:37 UTC (rev 776) </span><span class="lines">@@ -385,13 +385,12 @@ </span><span class="cx"> StaticBitmap.new( panel, -1, icon, Point.new(10, 10) ) </span><span class="cx"> </span><span class="cx"> bitmap = Bitmap.new( 100, 100 ) </span><del>- dc = MemoryDC.new - dc.select_object( bitmap ) - dc.set_pen(GREEN_PEN) - dc.clear() - dc.draw_ellipse(5, 5, 90, 90) - dc.draw_text("Bitmap", 30, 40) - dc.select_object( NULL_BITMAP ) </del><ins>+ bitmap.draw do | dc | + dc.clear() + dc.set_pen(GREEN_PEN) + dc.draw_ellipse(5, 5, 90, 90) + dc.draw_text("Bitmap", 30, 40) + end </ins><span class="cx"> </span><span class="cx"> BitmapButton.new(panel, ID_BITMAP_BTN, bitmap, Point.new(100, 20)) </span><span class="cx"> </span></span></pre> </div> </div> </body> </html>