<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://wikidot.org/rss-namespace">

	<channel>
		<title>Resize a Square Using the Mouse</title>
		<link>http://gamedesign.wikicomplete.info/forum/t-1430/resize-a-square-using-the-mouse</link>
		<description>Posts in the discussion thread &quot;Resize a Square Using the Mouse&quot; - Advanced Challenge</description>
				<copyright></copyright>
		<lastBuildDate></lastBuildDate>
		
					<item>
				<guid>http://gamedesign.wikicomplete.info/forum/t-1430#post-15728</guid>
				<title>Re: Resize a Square Using the Mouse</title>
				<link>http://gamedesign.wikicomplete.info/forum/t-1430/resize-a-square-using-the-mouse#post-15728</link>
				<description></description>
				<pubDate>Sat, 12 Sep 2009 23:27:18 +0000</pubDate>
				<wikidot:authorName>kake_fisk</wikidot:authorName>				<wikidot:authorUserId>33</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>C++ with SDL version. :)</p> <div class="code"> <div class="hl-main"> <pre> <span class="hl-identifier">SDL_Event</span><span class="hl-code"> </span><span class="hl-identifier">event</span><span class="hl-code">; </span><span class="hl-identifier">SDL_Rect</span><span class="hl-code"> </span><span class="hl-identifier">square</span><span class="hl-code">; </span><span class="hl-identifier">square</span><span class="hl-code">.</span><span class="hl-identifier">x</span><span class="hl-code"> = </span><span class="hl-number">1</span><span class="hl-code">; </span><span class="hl-identifier">square</span><span class="hl-code">.</span><span class="hl-identifier">y</span><span class="hl-code"> = </span><span class="hl-number">1</span><span class="hl-code">; </span><span class="hl-identifier">square</span><span class="hl-code">.</span><span class="hl-identifier">w</span><span class="hl-code"> = </span><span class="hl-identifier">event</span><span class="hl-code">.</span><span class="hl-identifier">button</span><span class="hl-code">.</span><span class="hl-identifier">x</span><span class="hl-code"> - </span><span class="hl-identifier">square</span><span class="hl-code">.</span><span class="hl-identifier">x</span><span class="hl-code">;</span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-identifier">square</span><span class="hl-code">.</span><span class="hl-identifier">h</span><span class="hl-code"> = </span><span class="hl-identifier">event</span><span class="hl-code">.</span><span class="hl-identifier">button</span><span class="hl-code">.</span><span class="hl-identifier">y</span><span class="hl-code"> - </span><span class="hl-identifier">square</span><span class="hl-code">.</span><span class="hl-identifier">y</span><span class="hl-code">; </span><span class="hl-reserved">while</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">isRunning</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-reserved">while</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">SDL_PollEvent</span><span class="hl-brackets">(</span><span class="hl-code">&amp;</span><span class="hl-identifier">event</span><span class="hl-brackets">))</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-reserved">if</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">event</span><span class="hl-code">.</span><span class="hl-identifier">type</span><span class="hl-code"> == </span><span class="hl-identifier">SDL_MOUSEMOTION</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-identifier">square</span><span class="hl-code">.</span><span class="hl-identifier">w</span><span class="hl-code"> = </span><span class="hl-identifier">event</span><span class="hl-code">.</span><span class="hl-identifier">button</span><span class="hl-code">.</span><span class="hl-identifier">x</span><span class="hl-code"> - </span><span class="hl-identifier">square</span><span class="hl-code">.</span><span class="hl-identifier">x</span><span class="hl-code">; </span><span class="hl-identifier">square</span><span class="hl-code">.</span><span class="hl-identifier">h</span><span class="hl-code"> = </span><span class="hl-identifier">event</span><span class="hl-code">.</span><span class="hl-identifier">button</span><span class="hl-code">.</span><span class="hl-identifier">y</span><span class="hl-code"> - </span><span class="hl-identifier">square</span><span class="hl-code">.</span><span class="hl-identifier">y</span><span class="hl-code">; </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-identifier">SDL_FillRect</span><span class="hl-brackets">(</span><span class="hl-identifier">screen</span><span class="hl-code">, &amp;</span><span class="hl-identifier">square</span><span class="hl-code">, </span><span class="hl-identifier">SDL_MapRGB</span><span class="hl-brackets">(</span><span class="hl-identifier">screen</span><span class="hl-code">-&gt;</span><span class="hl-identifier">format</span><span class="hl-code">, </span><span class="hl-number">0x0</span><span class="hl-code">, </span><span class="hl-number">0x0</span><span class="hl-code">, </span><span class="hl-number">0x0</span><span class="hl-brackets">))</span><span class="hl-code">; </span><span class="hl-brackets">}</span> </pre></div> </div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://gamedesign.wikicomplete.info/forum/t-1430#post-15124</guid>
				<title>Re: Resize a Square Using the Mouse</title>
				<link>http://gamedesign.wikicomplete.info/forum/t-1430/resize-a-square-using-the-mouse#post-15124</link>
				<description></description>
				<pubDate>Fri, 21 Aug 2009 10:51:30 +0000</pubDate>
				<wikidot:authorName>Fuzzy</wikidot:authorName>				<wikidot:authorUserId>1358</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>I didn't but mine hasn't passed yet. Don't think you need to as says resize box not sprite.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://gamedesign.wikicomplete.info/forum/t-1430#post-15114</guid>
				<title>Re: Resize a Square Using the Mouse</title>
				<link>http://gamedesign.wikicomplete.info/forum/t-1430/resize-a-square-using-the-mouse#post-15114</link>
				<description></description>
				<pubDate>Thu, 20 Aug 2009 19:55:16 +0000</pubDate>
				<wikidot:authorName>commander of games</wikidot:authorName>				<wikidot:authorUserId>1289</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Do you use a sprite?</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://gamedesign.wikicomplete.info/forum/t-1430#post-15112</guid>
				<title>Re: Resize a Square Using the Mouse</title>
				<link>http://gamedesign.wikicomplete.info/forum/t-1430/resize-a-square-using-the-mouse#post-15112</link>
				<description></description>
				<pubDate>Thu, 20 Aug 2009 17:32:08 +0000</pubDate>
				<wikidot:authorName>Fuzzy</wikidot:authorName>				<wikidot:authorUserId>1358</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Here is a bit more advanced one (although still basic!).</p> <div class="code"> <pre> <code>x# = getScreenWidth() / 2 y# = getScreenHeight() / 2 Box x#, y#, rnd(getScreenWidth()), rnd(getScreenHeight()), 1 Sync Do If enterKey() = True Cls 0 Box x#, y#, MouseX(), MouseY(), 1 Sync EndIf Loop</code> </pre></div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://gamedesign.wikicomplete.info/forum/t-1430#post-15110</guid>
				<title>Re: Resize a Square Using the Mouse</title>
				<link>http://gamedesign.wikicomplete.info/forum/t-1430/resize-a-square-using-the-mouse#post-15110</link>
				<description></description>
				<pubDate>Thu, 20 Aug 2009 17:16:09 +0000</pubDate>
				<wikidot:authorName>Fuzzy</wikidot:authorName>				<wikidot:authorUserId>1358</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Does this count?? (PlayBasic)</p> <div class="code"> <pre> <code>Do Cls 0 Box 0, 0, MouseX(), MouseY(), 1 Sync Loop</code> </pre></div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://gamedesign.wikicomplete.info/forum/t-1430#post-4980</guid>
				<title>Re: Resize a Square Using the Mouse</title>
				<link>http://gamedesign.wikicomplete.info/forum/t-1430/resize-a-square-using-the-mouse#post-4980</link>
				<description></description>
				<pubDate>Thu, 28 Aug 2008 06:26:30 +0000</pubDate>
				<wikidot:authorName>hartnell</wikidot:authorName>				<wikidot:authorUserId>3</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>It works! :)</p> <p>It's strangely cool to use FBIde again.</p> <p>— hartnell</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://gamedesign.wikicomplete.info/forum/t-1430#post-4960</guid>
				<title>Re: Resize a Square Using the Mouse</title>
				<link>http://gamedesign.wikicomplete.info/forum/t-1430/resize-a-square-using-the-mouse#post-4960</link>
				<description></description>
				<pubDate>Wed, 27 Aug 2008 15:16:16 +0000</pubDate>
				<wikidot:authorName>Gosha</wikidot:authorName>				<wikidot:authorUserId>423</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>It's not a bug, It's a feature!</p> <p>anyway. I just saw the offsets doesn't get updated or something (I fixed that in the code that's above now.).<br /> But, have you tried to start with resizing it? .. It's that little box in the corner.<br /> If it doesn't work it's maybe because I'm using something new in my version of FreeBASIC.. you could try downloading the last one.</p> <p>To compile older code just add "-lang deprecated" to the compiler options.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://gamedesign.wikicomplete.info/forum/t-1430#post-4890</guid>
				<title>Re: Resize a Square Using the Mouse</title>
				<link>http://gamedesign.wikicomplete.info/forum/t-1430/resize-a-square-using-the-mouse#post-4890</link>
				<description></description>
				<pubDate>Mon, 25 Aug 2008 06:15:21 +0000</pubDate>
				<wikidot:authorName>hartnell</wikidot:authorName>				<wikidot:authorUserId>3</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>I can move it around but not resize it. Somehow it seems I'm in error, what am I missing? :)</p> <p>Stay Frosty<br /> — hartnell</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://gamedesign.wikicomplete.info/forum/t-1430#post-4852</guid>
				<title>Re: Resize a Square Using the Mouse</title>
				<link>http://gamedesign.wikicomplete.info/forum/t-1430/resize-a-square-using-the-mouse#post-4852</link>
				<description></description>
				<pubDate>Thu, 21 Aug 2008 19:15:12 +0000</pubDate>
				<wikidot:authorName>Gosha</wikidot:authorName>				<wikidot:authorUserId>423</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>So, I made a cube that can be moved and resized.</p> <p>Added up to 131 rows with comments! hehe.<br /> I wonder, is anything unessecary here? That could be removed/replaced with something alot easier:</p> <p>Updated 08/08/27</p> <div class="code"> <pre> <code>Option Explicit ' Defines the cube start position ' The offsets are required to maintain the squares size. ' offset -&gt; offset + size = size of square ' By the way, they're all shared so they can be used in subs. Dim Shared offsetx As Integer = 20 Dim Shared offsety As Integer = 10 Dim Shared sizex As Integer = 400 Dim Shared sizey As Integer = 400 ' Prepare variables for the mouse and the mouse buttons Dim Shared mousey As Integer Dim Shared mousex As Integer Dim Shared mousebtns As Integer ' This is used so not only the mouse-over-stat describes whether stuff should be ' moved/resized (The mouse moves faster than the screen draws, so it causes a ' lot of ruckus if this doesn't exist and holds the state of whether the mouse ' button is pressed or not) Dim Shared btnpressed As Byte = 0 ' This stuff is required for holding the variables of the mouse when it started, ' while the square is moving. Dim Shared mouseyoffset As Integer Dim Shared mousexoffset As Integer ' This is required so it holds the thing it's supposed to do. (Move/Resize) ' Eitherwise if you move the mouse too fast from the resizing box to the moving ' one, while holding the mouse, it starts moving it instead of resizing it. Dim Shared nocheck As Byte ' This function checks whether the mouse is over those four coordinates and ' returns either 1 for OVER and 0 for NOT OVER. Function mouseOver(x , y , tox, toy) As Byte If (mousex &gt;= x) And (mousex &lt;= tox) And (mousey &gt;= y) And (mousey &lt;= toy) Then Return 1 Else Return 0 End If End Function ' This draws the green rectangle and the filled ones inside and on the corner, ' depending on the state. ' 0 = Mose not over the resize/move cube ' 1 = Mouse over the moving cube ' 2 = Mouse over the resizing cube Sub drawCube (state) Line (offsetx, offsety)-(offsetx+sizex, offsety+sizey), 10, b Select Case state Case 1 Line (offsetx+10, offsety+10)-(offsetx+(sizex-10), offsety+(sizey-10)), 23, bf Line (offsetx+(sizex-5), offsety+(sizey-5))-(offsetx+(sizex+5), offsety+(sizey+5)), 20, bf Case 2 Line (offsetx+10, offsety+10)-(offsetx+(sizex-10), offsety+(sizey-10)), 20, bf Line (offsetx+(sizex-5), offsety+(sizey-5))-(offsetx+(sizex+5), offsety+(sizey+5)), 23, bf Case Else Line (offsetx+10, offsety+10)-(offsetx+(sizex-10), offsety+(sizey-10)), 20, bf Line (offsetx+(sizex-5), offsety+(sizey-5))-(offsetx+(sizex+5), offsety+(sizey+5)), 20, bf End Select End Sub ' This sub moves the cube according to the mouse starting position relative to ' the cube Sub moveCube() offsetx = mousex - mousexoffset offsety = mousey - mouseyoffset End Sub ' This sub resize the cube after the mouse on the bottom corner of the cube Sub resizeCube() sizex = mousex - offsetx sizey = mousey - offsety End Sub ' Lol, draws info. (Was intended for debugging, but wasn't required) Sub drawInfo() Locate 2, 2 Print "Press q to quit." End Sub Screen 18 ' 640x480 While Inkey &lt;&gt; "q" Cls Getmouse mousex, mousey,,mousebtns ' Check whether the mouse is over the the moving cube If(mouseOver(offsetx+10, offsety+10, offsetx+(sizex-10), offsety+(sizey-10))) = 1 Then drawCube(1) ' If the nocheck variable has been set, we haven't started moving If nocheck = 0 Then If mousebtns And 1 Then btnpressed = 1 ' Sets the starting offset when moving the cube (At least I think this is required) mousexoffset = mousex - offsetx mouseyoffset = mousey - offsety End If ' Set that we have checked that the mousebtn is pressed. Keep the offsets nocheck = 1 End If ' Check whether the mouse is over the little corner cube Elseif(mouseOver(offsetx+(sizex-6), offsety+(sizey-6),offsetx+(sizex+6), offsety+(sizey+6))) Then drawCube(2) ' Same as up there If this weren't here and you run the program and started ' resizing and quickly moved the button to the big moving cube it'd start ' moving instead of resizing. Annoying. If nocheck = 0 Then If mousebtns And 1 Then btnpressed = 2 End If nocheck = 1 End If Else drawCube(0) End If ' If the buttons still are pressed, keep on doing your job. If (mousebtns And 1) And (btnpressed = 2) Then resizeCube() Elseif (mousebtns And 1) And (btnpressed = 1) Then moveCube() ' Otherwise stop doing it and let it start from anew. Reset everything. Else btnpressed = 0 nocheck = 0 End If ' Draw info /debugging info drawInfo() ' Wait a little while ( This is supposed to reduce flicker ) Sleep 1 Wend End</code> </pre></div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://gamedesign.wikicomplete.info/forum/t-1430#post-4851</guid>
				<title>Re: Resize a Square Using the Mouse</title>
				<link>http://gamedesign.wikicomplete.info/forum/t-1430/resize-a-square-using-the-mouse#post-4851</link>
				<description></description>
				<pubDate>Thu, 21 Aug 2008 17:39:20 +0000</pubDate>
				<wikidot:authorName>hartnell</wikidot:authorName>				<wikidot:authorUserId>3</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Er… crap. Does anyone know where that dumbass hartnell put the challenge scoreboard?</p> <p>— hartnell</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://gamedesign.wikicomplete.info/forum/t-1430#post-4850</guid>
				<title>Re: Resize a Square Using the Mouse</title>
				<link>http://gamedesign.wikicomplete.info/forum/t-1430/resize-a-square-using-the-mouse#post-4850</link>
				<description></description>
				<pubDate>Thu, 21 Aug 2008 17:37:59 +0000</pubDate>
				<wikidot:authorName>hartnell</wikidot:authorName>				<wikidot:authorUserId>3</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>This passes the challenge. :)</p> <p>— hartnell</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://gamedesign.wikicomplete.info/forum/t-1430#post-4847</guid>
				<title>Re: Resize a Square Using the Mouse</title>
				<link>http://gamedesign.wikicomplete.info/forum/t-1430/resize-a-square-using-the-mouse#post-4847</link>
				<description></description>
				<pubDate>Thu, 21 Aug 2008 15:36:40 +0000</pubDate>
				<wikidot:authorName>Gosha</wikidot:authorName>				<wikidot:authorUserId>423</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Uhm, like so?</p> <p>FreeBASIC:</p> <div class="code"> <pre> <code>Option Explicit const SCRWIDTH as integer = 640 const SCRHEIGHT as integer = 480 dim mousey, mousex as integer screen 18 while inkey &lt;&gt; "q" cls locate 2, 2 print "Press q to quit." getmouse mousex, mousey if (mousex &gt;= 0) and (mousey &gt;= 0) then line (SCRWIDTH/2, SCRHEIGHT/2)-(mousex,mousey), 11, BF end if sleep 10 wend end</code> </pre></div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://gamedesign.wikicomplete.info/forum/t-1430#post-2436</guid>
				<title>Resize a Square Using the Mouse</title>
				<link>http://gamedesign.wikicomplete.info/forum/t-1430/resize-a-square-using-the-mouse#post-2436</link>
				<description></description>
				<pubDate>Mon, 07 Apr 2008 19:01:05 +0000</pubDate>
				<wikidot:authorName>hartnell</wikidot:authorName>				<wikidot:authorUserId>3</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>The challenge is this :</p> <ul> <li>Create a square that can be <ul> <li>Stretched along the x and y axises</li> <li>Resized simultaneously along the x and y axises.</li> </ul> </li> </ul> <p>Yeah, I know, just did it on the GMWiki, challenges will be posted here first whenever possible from now on.</p> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>