<html>
<head>

<script type="text/javascript" src="/static/js/analytics.js" ></script>
<link type="text/css" rel="stylesheet" href="/static/css/banner-styles.css"/>




<title>CH2Dto3D.cpp</title>
</head>
<!-- Generated by SynEdit HTML exporter -->
<body text="#000000" bgcolor="#FFFFFF">
<!-- BEGIN WAYBACK TOOLBAR INSERT -->
<script> if (window.archive_analytics) { window.archive_analytics.values['server_name']="wwwb-app17.us.archive.org";}; </script>

<script type="text/javascript" src="/static/js/disclaim-element.js" ></script>
<script type="text/javascript" src="/static/js/graph-calc.js" ></script>
<script type="text/javascript" src="/static/jflot/jquery.min.js" ></script>
<script type="text/javascript">
//<![CDATA[
var firstDate = 820454400000;
var lastDate = 1420070399999;
var wbPrefix = "/web/";
var wbCurrentUrl = "http:\/\/mtm2.com\/%7Emtmg\/downloads\/mtm2\/ch_2005\/CH2Dto3D.cpp";

var curYear = -1;
var curMonth = -1;
var yearCount = 18;
var firstYear = 1996;
var imgWidth = 475;
var yearImgWidth = 25;
var monthImgWidth = 2;
var trackerVal = "none";
var displayDay = "20";
var displayMonth = "Feb";
var displayYear = "2007";
var prettyMonths = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];

function showTrackers(val) {
	if(val == trackerVal) {
		return;
	}
	if(val == "inline") {
		document.getElementById("displayYearEl").style.color = "#ec008c";
		document.getElementById("displayMonthEl").style.color = "#ec008c";
		document.getElementById("displayDayEl").style.color = "#ec008c";		
	} else {
		document.getElementById("displayYearEl").innerHTML = displayYear;
		document.getElementById("displayYearEl").style.color = "#ff0";
		document.getElementById("displayMonthEl").innerHTML = displayMonth;
		document.getElementById("displayMonthEl").style.color = "#ff0";
		document.getElementById("displayDayEl").innerHTML = displayDay;
		document.getElementById("displayDayEl").style.color = "#ff0";
	}
   document.getElementById("wbMouseTrackYearImg").style.display = val;
   document.getElementById("wbMouseTrackMonthImg").style.display = val;
   trackerVal = val;
}
function getElementX2(obj) {
	var thing = jQuery(obj);
	if((thing == undefined) 
			|| (typeof thing == "undefined") 
			|| (typeof thing.offset == "undefined")) {
		return getElementX(obj);
	}
	return Math.round(thing.offset().left);
}
function trackMouseMove(event,element) {

   var eventX = getEventX(event);
   var elementX = getElementX2(element);
   var xOff = eventX - elementX;
	if(xOff < 0) {
		xOff = 0;
	} else if(xOff > imgWidth) {
		xOff = imgWidth;
	}
   var monthOff = xOff % yearImgWidth;

   var year = Math.floor(xOff / yearImgWidth);
	var yearStart = year * yearImgWidth;
   var monthOfYear = Math.floor(monthOff / monthImgWidth);
   if(monthOfYear > 11) {
       monthOfYear = 11;
   }
   // 1 extra border pixel at the left edge of the year:
   var month = (year * 12) + monthOfYear;
   var day = 1;
	if(monthOff % 2 == 1) {
		day = 15;
	}
	var dateString = 
		zeroPad(year + firstYear) + 
		zeroPad(monthOfYear+1,2) +
		zeroPad(day,2) + "000000";

	var monthString = prettyMonths[monthOfYear];
	document.getElementById("displayYearEl").innerHTML = year + 1996;
	document.getElementById("displayMonthEl").innerHTML = monthString;
	// looks too jarring when it changes..
	//document.getElementById("displayDayEl").innerHTML = zeroPad(day,2);

	var url = wbPrefix + dateString + '/' +  wbCurrentUrl;
	document.getElementById('wm-graph-anchor').href = url;

   //document.getElementById("wmtbURL").value="evX("+eventX+") elX("+elementX+") xO("+xOff+") y("+year+") m("+month+") monthOff("+monthOff+") DS("+dateString+") Moy("+monthOfYear+") ms("+monthString+")";
   if(curYear != year) {
       var yrOff = year * yearImgWidth;
       document.getElementById("wbMouseTrackYearImg").style.left = yrOff + "px";
       curYear = year;
   }
   if(curMonth != month) {
       var mtOff = year + (month * monthImgWidth) + 1;
       document.getElementById("wbMouseTrackMonthImg").style.left = mtOff + "px";
       curMonth = month;
   }
}
//]]>
</script>

<style type="text/css">body{margin-top:0!important;padding-top:0!important;min-width:800px!important;}#wm-ipp a:hover{text-decoration:underline!important;}</style>
<div id="wm-ipp" lang="en" class="__wb_banner_div" style="display:none; position:relative;padding:0 5px;min-height:70px;min-width:800px">


<div id="wm-ipp-inside" class="__wb_banner_div" style="position:fixed;padding:0!important;margin:0!important;width:97%;min-width:780px;border:5px solid #000;border-top:none;background-image:url(/static/images/toolbar/wm_tb_bk_trns.png);text-align:center;-moz-box-shadow:1px 1px 3px #333;-webkit-box-shadow:1px 1px 3px #333;box-shadow:1px 1px 3px #333;font-size:11px!important;font-family:'Lucida Grande','Arial',sans-serif!important;">
   <table style="border-collapse:collapse;margin:0;padding:0;width:100%;"><tbody><tr>
   <td style="padding:10px;vertical-align:top;min-width:110px;">
   <a href="/web/" title="Wayback Machine home page" style="background-color:transparent;border:none;"><img src="/static/images/toolbar/wayback-toolbar-logo.png" alt="Wayback Machine" width="110" height="39" border="0"/></a>
   </td>
   <td style="padding:0!important;text-align:center;vertical-align:top;width:100%;">

       <table style="border-collapse:collapse;margin:0 auto;padding:0;width:570px;"><tbody><tr>
       <td style="padding:3px 0;" colspan="2">
       <form target="_top" method="get" action="/web/form-submit.jsp" name="wmtb" id="wmtb" style="margin:0!important;padding:0!important;"><input type="text" name="url" id="wmtbURL" value="http://mtm2.com/%7Emtmg/downloads/mtm2/ch_2005/CH2Dto3D.cpp" style="width:400px;font-size:11px;font-family:'Lucida Grande','Arial',sans-serif;" onfocus="javascript:this.focus();this.select();" /><input type="hidden" name="type" value="replay" /><input type="hidden" name="date" value="20070220170051" /><input type="submit" value="Go" style="font-size:11px;font-family:'Lucida Grande','Arial',sans-serif;margin-left:5px;width: inherit !important" /><span id="wm_tb_options" style="display:block;"></span></form>
       </td>
       <td style="vertical-align:bottom;padding:5px 0 0 0!important;" rowspan="2">
           <table style="border-collapse:collapse;width:110px;color:#99a;font-family:'Helvetica','Lucida Grande','Arial',sans-serif;"><tbody>
			
           <!-- NEXT/PREV MONTH NAV AND MONTH INDICATOR -->
           <tr style="width:110px;height:16px;font-size:10px!important;">
           	<td style="padding-right:9px;font-size:11px!important;font-weight:bold;text-transform:uppercase;text-align:right;white-space:nowrap;overflow:visible;" nowrap="nowrap">
               
		                <a href="/web/20031129202614/http://mtm2.com/~mtmg/downloads/mtm2/ch_2005/CH2Dto3D.cpp" style="text-decoration:none;color:#33f;font-weight:bold;background-color:transparent;border:none;" title="29 Nov 2003"><strong>NOV</strong></a>
		                
               </td>
               <td id="displayMonthEl" style="background:#000;color:#ff0;font-size:11px!important;font-weight:bold;text-transform:uppercase;width:34px;height:15px;padding-top:1px;text-align:center;" title="You are here: 17:00:51 Feb 20, 2007">FEB</td>
				<td style="padding-left:9px;font-size:11px!important;font-weight:bold;text-transform:uppercase;white-space:nowrap;overflow:visible;" nowrap="nowrap">
               
                       Mar
                       
               </td>
           </tr>

           <!-- NEXT/PREV CAPTURE NAV AND DAY OF MONTH INDICATOR -->
           <tr>
               <td style="padding-right:9px;white-space:nowrap;overflow:visible;text-align:right!important;vertical-align:middle!important;" nowrap="nowrap">
               
		                <a href="/web/20031129202614/http://mtm2.com/~mtmg/downloads/mtm2/ch_2005/CH2Dto3D.cpp" title="20:26:14 Nov 29, 2003" style="background-color:transparent;border:none;"><img src="/static/images/toolbar/wm_tb_prv_on.png" alt="Previous capture" width="14" height="16" border="0" /></a>
		                
               </td>
               <td id="displayDayEl" style="background:#000;color:#ff0;width:34px;height:24px;padding:2px 0 0 0;text-align:center;font-size:24px;font-weight: bold;" title="You are here: 17:00:51 Feb 20, 2007">20</td>
				<td style="padding-left:9px;white-space:nowrap;overflow:visible;text-align:left!important;vertical-align:middle!important;" nowrap="nowrap">
               
                       <img src="/static/images/toolbar/wm_tb_nxt_off.png" alt="Next capture" width="14" height="16" border="0"/>
                       
			    </td>
           </tr>

           <!-- NEXT/PREV YEAR NAV AND YEAR INDICATOR -->
           <tr style="width:110px;height:13px;font-size:9px!important;">
				<td style="padding-right:9px;font-size:11px!important;font-weight: bold;text-align:right;white-space:nowrap;overflow:visible;" nowrap="nowrap">
               
		                <a href="/web/20031129202614/http://mtm2.com/~mtmg/downloads/mtm2/ch_2005/CH2Dto3D.cpp" style="text-decoration:none;color:#33f;font-weight:bold;background-color:transparent;border:none;" title="29 Nov 2003"><strong>2003</strong></a>
		                
               </td>
               <td id="displayYearEl" style="background:#000;color:#ff0;font-size:11px!important;font-weight: bold;padding-top:1px;width:34px;height:13px;text-align:center;" title="You are here: 17:00:51 Feb 20, 2007">2007</td>
				<td style="padding-left:9px;font-size:11px!important;font-weight: bold;white-space:nowrap;overflow:visible;" nowrap="nowrap">
               
                       2008
                       
				</td>
           </tr>
           </tbody></table>
       </td>

       </tr>
       <tr>
       <td style="vertical-align:middle;padding:0!important;">
           <a href="/web/20070220170051*/http://mtm2.com/%7Emtmg/downloads/mtm2/ch_2005/CH2Dto3D.cpp" style="color:#33f;font-size:11px;font-weight:bold;background-color:transparent;border:none;" title="See a list of every capture for this URL"><strong>2 captures</strong></a>
           <div class="__wb_banner_div" style="margin:0!important;padding:0!important;color:#666;font-size:9px;padding-top:2px!important;white-space:nowrap;" title="Timespan for captures of this URL">29 Nov 03 - 20 Feb 07</div>
       </td>
       <td style="padding:0!important;">
       <a style="position:relative; white-space:nowrap; width:475px;height:27px;" href="" id="wm-graph-anchor">
       <div class="__wb_banner_div" id="wm-ipp-sparkline" style="position:relative; white-space:nowrap; width:475px;height:27px;background-color:#fff;cursor:pointer;border-right:1px solid #ccc;" title="Explore captures for this URL">
			<img id="sparklineImgId" style="position:absolute; z-index:9012; top:0px; left:0px;"
				onmouseover="showTrackers('inline');" 
				onmouseout="showTrackers('none');"
				onmousemove="trackMouseMove(event,this)"
				alt="sparklines"
				width="475"
				height="27"
				border="0"
				src="/web/jsp/graph.jsp?graphdata=475_27_1996:-1:000000000000_1997:-1:000000000000_1998:-1:000000000000_1999:-1:000000000000_2000:-1:000000000000_2001:-1:000000000000_2002:-1:000000000000_2003:-1:000000000010_2004:-1:000000000000_2005:-1:000000000000_2006:-1:000000000000_2007:1:010000000000_2008:-1:000000000000_2009:-1:000000000000_2010:-1:000000000000_2011:-1:000000000000_2012:-1:000000000000_2013:-1:000000000000_2014:-1:000000000000"></img>
			<img id="wbMouseTrackYearImg" 
				style="display:none; position:absolute; z-index:9010;"
				width="25" 
				height="27"
				border="0"
				src="/static/images/toolbar/transp-yellow-pixel.png"></img>
			<img id="wbMouseTrackMonthImg"
				style="display:none; position:absolute; z-index:9011; " 
				width="2"
				height="27" 
				border="0"
				src="/static/images/toolbar/transp-red-pixel.png"></img>
       </div>
		</a>

       </td>
       </tr></tbody></table>
   </td>
   <td style="text-align:right;padding:5px;width:65px;font-size:11px!important;">
       <a href="javascript:;" onclick="document.getElementById('wm-ipp').style.display='none';" style="display:block;padding-right:18px;background:url(/static/images/toolbar/wm_tb_close.png) no-repeat 100% 0;color:#33f;font-family:'Lucida Grande','Arial',sans-serif;margin-bottom:23px;background-color:transparent;border:none;" title="Close the toolbar">Close</a>
       <a href="http://faq.web.archive.org/" style="display:block;padding-right:18px;background:url(/static/images/toolbar/wm_tb_help.png) no-repeat 100% 0;color:#33f;font-family:'Lucida Grande','Arial',sans-serif;background-color:transparent;border:none;" title="Get some help using the Wayback Machine">Help</a>
   </td>
   </tr></tbody></table>

</div>
</div>
<script type="text/javascript">
 var wmDisclaimBanner = document.getElementById("wm-ipp");
 if(wmDisclaimBanner != null) {
   disclaimElement(wmDisclaimBanner);
 }
</script>
<!-- END WAYBACK TOOLBAR INSERT -->

<pre>
<code><font  size=3 face="Courier New"><font color="#FF0000"><i>//This was written by CH_2005
//e-mail: ch_2005@programmer.net
//It requires the Carnegie Mellon Graphics Package for Dev-C++
// http://www-2.cs.cmu.edu/~cm-gfxpkg/index.html
//It was in fact written in Dev-Cpp 4.9.7.0 Which is also open source
// you can get dev-cpp from the internet
</i></font><font color="#008000">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;conio.h&gt;
#include &lt;math.h&gt;
#include &quot;CarnegieMellonGraphics.h&quot;
#include &quot;colors.h&quot;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;stdlib.h&gt;
#include &lt;math.h&gt;

</font><b>using namespace </b>std;




<font color="#FF0000"><i>//=========GLOBALS=========

//====Create a new window 700 by 500 in size at 1034,310
</i></font>Window window(<font color="#800080">20</font>,<font color="#800080">20</font>,<font color="#800080">700</font>,<font color="#800080">500</font>, <font color="#993366">&quot;CH's VCpp 2D to 3D Wavefront OBJ Creator&quot;</font>);    

<font color="#FF0000"><i>//==THIS=TELLS=WHAT=THE=PROGRAM=IS=DOING==
</i></font><b>typedef enum </b>{NONE,
              <font color="#FF0000"><i>/*FILE*/
              </i></font>LOAD_2D,          <font color="#FF0000"><i>//Loads an image to use as a guide in modling
              </i></font>WIDTH,            <font color="#FF0000"><i>//Changes default width at vert
              </i></font>SAVE,             <font color="#FF0000"><i>//Saves the OBJ model file
              </i></font>EXIT,             <font color="#FF0000"><i>//Makes the program quit
              /*ADD*/
              </i></font>ADD_VERTS,        <font color="#FF0000"><i>//Adds points to the vertex array
              </i></font>ADD_FACES,        <font color="#FF0000"><i>//Adds faces to the face array by clicking verts
              </i></font>ADD_EDGES,        <font color="#FF0000"><i>//Adds edges to the edges arry by clicking verts
              /*MOD*/
              </i></font>MOVE_VERTS,       <font color="#FF0000"><i>//Changes the x/y of a vert by click and drag              
              </i></font>VERT_WIDTH,       <font color="#FF0000"><i>//Changes the width at a vert (z)
              /*DEL*/
              </i></font>DEL_VERTS,        <font color="#FF0000"><i>//Deletes a vert from the model!(if edges|faces)
              </i></font>DEL_FACES,        <font color="#FF0000"><i>//Deletes a face by clicking 3 verts of a face
              </i></font>DEL_EDGES,        <font color="#FF0000"><i>//Deletes an edge by clicking 2 verts of an edge
              /*COLORS*/
              </i></font>COLORS_VERTS,     <font color="#FF0000"><i>//Changes the draw color for verts
              </i></font>COLORS_FACES,     <font color="#FF0000"><i>//Changes the draw color for faces
              </i></font>COLORS_EDGES,     <font color="#FF0000"><i>//Changes the draw color for edges
             </i></font>}mode;
mode PROG_MODE;

<font color="#FF0000"><i>//==MODEL=DATA!
</i></font><b>struct </b>vert{ <font color="#FF0000"><i>//a vert holds and x,y,z set
    </i></font><b>int </b>x;
    <b>int </b>y;
    <b>int </b>z;
    <font color="#FF0000"><i>//a pretty constructor for the struct
    </i></font>vert(<b>int </b>x, <b>int </b>y, <b>int </b>z):x(x),y(y),z(z){};
};
<b>struct </b>face{ <font color="#FF0000"><i>//in a face the points are define a triange clockwise
    </i></font><b>int </b>vert1;
    <b>int </b>vert2;
    <b>int </b>vert3;
    face(<b>int </b>vert1, <b>int </b>vert2, <b>int </b>vert3):
    vert1(vert1),vert2(vert2),vert3(vert3){};
};
<b>struct </b>model{ <font color="#FF0000"><i>//these simpe models have just verts and faces ...
    </i></font>vector&lt;vert&gt; verts;
    <font color="#FF0000"><i>//int num_verts;
    </i></font>vector&lt;face&gt; faces;
    <font color="#FF0000"><i>//int_num_faces;
    </i></font><b>int </b>width; <font color="#FF0000"><i>//...and a default width to just be used in the editor
    //the constructor only inits the width cuz the verts and faces are not known
    </i></font>model(<b>int </b>width): width(width) {};
};
model OBJ(<font color="#800080">50</font>);

<font color="#FF0000"><i>//==FONT 
//Set Font and Style    
//Char sizes
</i></font><b>const int </b>CHAR_WIDTH = <font color="#800080">9</font>;
<b>const int </b>CHAR_HEIGHT = <font color="#800080">12</font>;

<font color="#FF0000"><i>//Foreground and Background font styles
</i></font><b>const </b>Style FORE_FONT_STYLE = Style(Color::BLACK,<font color="#800080">2</font>);
<b>const </b>Style BACK_FONT_STYLE = Style(Color::WHITE,<font color="#800080">2</font>);

<font color="#FF0000"><i>//Font ttf file for font face
</i></font><b>const </b>string FONT_FACE = <font color="#993366">&quot;C:\\WINDOWS\\FONTS\\OCRAEXT.TTF&quot;</font>;
<b>const </b>Font FONT = Font(FONT_FACE,CHAR_HEIGHT);


<font color="#FF0000"><i>//==CURSOR
</i></font><b>const </b>Style FORE_CURSOR_STYLE = Style(Color::BLACK,<font color="#800080">3</font>);
<b>const </b>Style BACK_CURSOR_STYLE = Style(Color::WHITE,<font color="#800080">3</font>);

<font color="#FF0000"><i>//==RECTANGLES
</i></font><b>struct </b>rect{
    <b>int </b>x1;
    <b>int </b>y1;
    <b>int </b>x2;
    <b>int </b>y2;
    <font color="#FF0000"><i>//yay a struct constructor!
    </i></font>rect(<b>int </b>x1, <b>int </b>y1, <b>int </b>x2, <b>int </b>y2):
    x1(x1), x2(x2), y1(y1), y2(y2) {}
};
<font color="#FF0000"><i>//screen areas
//           Area           x1    y1    x2        y2
//           ~~~~           ~~    ~~    ~~        ~~
</i></font><b>const </b>rect   CANVAS      (  <font color="#800080">25</font>,   <font color="#800080">87</font>,   <font color="#800080">25</font>+<font color="#800080">651</font>,   <font color="#800080">87</font>+<font color="#800080">276 </font>); <font color="#FF0000"><i>//651x276
</i></font><b>const </b>rect   IO_WINDOW   (  <font color="#800080">25</font>,   <font color="#800080">399</font>,  <font color="#800080">25</font>+<font color="#800080">651</font>,   <font color="#800080">76</font>+<font color="#800080">399 </font>); <font color="#FF0000"><i>//651x76
</i></font><b>const </b>rect   MENU_RECT   (  <font color="#800080">376</font>,  <font color="#800080">27</font>,   <font color="#800080">376</font>+<font color="#800080">314</font>,  <font color="#800080">27</font>+<font color="#800080">34  </font>);

<font color="#FF0000"><i>//Menu button rects
//           Area           x1    y1    x2     y2
//           ~~~~           ~~    ~~    ~~     ~~
</i></font><b>const </b>rect   FILE_RECT   (  <font color="#800080">380</font>,  <font color="#800080">4</font>,  <font color="#800080">380</font>+<font color="#800080">48</font>,  <font color="#800080">25</font>);
<b>const </b>rect   ADD_RECT    (  <font color="#800080">436</font>,  <font color="#800080">4</font>,  <font color="#800080">436</font>+<font color="#800080">47</font>,  <font color="#800080">25</font>);
<b>const </b>rect   MOD_RECT    (  <font color="#800080">490</font>,  <font color="#800080">4</font>,  <font color="#800080">490</font>+<font color="#800080">51</font>,  <font color="#800080">25</font>);
<b>const </b>rect   DEL_RECT    (  <font color="#800080">547</font>,  <font color="#800080">4</font>,  <font color="#800080">547</font>+<font color="#800080">44</font>,  <font color="#800080">25</font>);
<b>const </b>rect   COLORS_RECT (  <font color="#800080">596</font>,  <font color="#800080">4</font>,  <font color="#800080">596</font>+<font color="#800080">90</font>,  <font color="#800080">25</font>);

<font color="#FF0000"><i>//SubMenu Button Rects
//           Area               x1    y1     x2      y2
//           ~~~~               ~~    ~~     ~~      ~~
//FILE:
</i></font><b>const </b>rect   LOAD_2D_RECT    (  <font color="#800080">383</font>,  <font color="#800080">33</font>,  <font color="#800080">383</font>+<font color="#800080">86</font>,   <font color="#800080">54</font>);
<b>const </b>rect   WIDTH_RECT      (  <font color="#800080">475</font>,  <font color="#800080">33</font>,  <font color="#800080">475</font>+<font color="#800080">98</font>,   <font color="#800080">54</font>);
<b>const </b>rect   SAVE_RECT       (  <font color="#800080">579</font>,  <font color="#800080">33</font>,  <font color="#800080">579</font>+<font color="#800080">52</font>,   <font color="#800080">54</font>);
<b>const </b>rect   EXIT_RECT       (  <font color="#800080">639</font>,  <font color="#800080">33</font>,  <font color="#800080">639</font>+<font color="#800080">42</font>,   <font color="#800080">54</font>);
<font color="#FF0000"><i>//ADD_DEL_COLORS:
</i></font><b>const </b>rect   VERTS_RECT      (  <font color="#800080">391</font>,  <font color="#800080">33</font>,  <font color="#800080">391</font>+<font color="#800080">58</font>,   <font color="#800080">54</font>);
<b>const </b>rect   FACES_RECT      (  <font color="#800080">498</font>,  <font color="#800080">33</font>,  <font color="#800080">498</font>+<font color="#800080">62</font>,   <font color="#800080">54</font>);
<b>const </b>rect   EDGES_RECT      (  <font color="#800080">605</font>,  <font color="#800080">33</font>,  <font color="#800080">605</font>+<font color="#800080">65</font>,   <font color="#800080">54</font>);
<font color="#FF0000"><i>//MOD:
</i></font><b>const </b>rect   MOVE_VERTS_RECT (  <font color="#800080">383</font>,  <font color="#800080">33</font>,  <font color="#800080">383</font>+<font color="#800080">113</font>,  <font color="#800080">54</font>);
<b>const </b>rect   VERT_WIDTH_RECT (  <font color="#800080">574</font>,  <font color="#800080">33</font>,  <font color="#800080">574</font>+<font color="#800080">110</font>,  <font color="#800080">54</font>);


<font color="#FF0000"><i>//==BUTTONS
</i></font><b>struct </b>menu_button{
    rect my_rect;
    <b>bool </b>enabled;
    <b>bool </b>active;
    <font color="#FF0000"><i>//yay a constructor!
    </i></font>menu_button(rect my_rect, <b>bool </b>enabled, <b>bool </b>active):
    my_rect(my_rect),enabled(enabled),active(active){}
};

<font color="#FF0000"><i>//==MENU BUTTONS
//           Button           Rect       Enabled   Active
//           ~~~~~~           ~~~~       ~~~~~~~   ~~~~~~
</i></font>menu_button  FILE_BTN   (   FILE_RECT   ,   <font color="#800080">1    </font>,   <font color="#800080">0    </font>);
menu_button  ADD_BTN    (   ADD_RECT    ,   <font color="#800080">1    </font>,   <font color="#800080">0    </font>);
menu_button  MOD_BTN    (   MOD_RECT    ,   <font color="#800080">0    </font>,   <font color="#800080">0    </font>);
menu_button  DEL_BTN    (   DEL_RECT    ,   <font color="#800080">0    </font>,   <font color="#800080">0    </font>);
menu_button  COLORS_BTN (   COLORS_RECT ,   <font color="#800080">0    </font>,   <font color="#800080">0    </font>);


<b>struct </b>button{
    rect my_rect;
    <b>bool </b>enabled;
    <b>bool </b>visable;
    <font color="#FF0000"><i>//yay a constructor!
    </i></font>button(rect my_rect, <b>bool </b>enabled, <b>bool </b>visable):
    my_rect(my_rect),enabled(enabled),visable(visable){}
};
<font color="#FF0000"><i>//==SUBMENU BUTTONS
//           Button                Rect               Enabled   Visable
//           ~~~~~~                ~~~~               ~~~~~~~   ~~~~~~~
//FILE:
</i></font>button  LOAD_2D_BTN            (   LOAD_2D_RECT      ,   <font color="#800080">0    </font>,    <font color="#800080">0    </font>);
button  WIDTH_BTN              (   WIDTH_RECT        ,   <font color="#800080">0    </font>,    <font color="#800080">0    </font>);
button  SAVE_BTN               (   SAVE_RECT         ,   <font color="#800080">0    </font>,    <font color="#800080">0    </font>);
button  EXIT_BTN               (   EXIT_RECT         ,   <font color="#800080">0    </font>,    <font color="#800080">0    </font>);
<font color="#FF0000"><i>//ADD:
</i></font>button  ADD_VERTS_BTN          (   VERTS_RECT        ,   <font color="#800080">0    </font>,    <font color="#800080">0    </font>);
button  ADD_FACES_BTN          (   FACES_RECT        ,   <font color="#800080">0    </font>,    <font color="#800080">0    </font>);
button  ADD_EDGES_BTN          (   EDGES_RECT        ,   <font color="#800080">0    </font>,    <font color="#800080">0    </font>);
<font color="#FF0000"><i>//MOD:
</i></font>button  MOVE_VERTS_BTN         (   MOVE_VERTS_RECT   ,   <font color="#800080">0    </font>,    <font color="#800080">0    </font>);
button  VERT_WIDTH_BTN         (   VERT_WIDTH_RECT   ,   <font color="#800080">0    </font>,    <font color="#800080">0    </font>);
<font color="#FF0000"><i>//DEL:
</i></font>button  DEL_VERTS_BTN          (   VERTS_RECT        ,   <font color="#800080">0    </font>,    <font color="#800080">0    </font>);
button  DEL_FACES_BTN          (   FACES_RECT        ,   <font color="#800080">0    </font>,    <font color="#800080">0    </font>);
button  DEL_EDGES_BTN          (   EDGES_RECT        ,   <font color="#800080">0    </font>,    <font color="#800080">0    </font>);
<font color="#FF0000"><i>//COLORS:
</i></font>button  COLORS_VERTS_BTN       (   VERTS_RECT        ,   <font color="#800080">0    </font>,    <font color="#800080">0    </font>);
button  COLORS_FACES_BTN       (   FACES_RECT        ,   <font color="#800080">0    </font>,    <font color="#800080">0    </font>);
button  COLORS_EDGES_BTN       (   EDGES_RECT        ,   <font color="#800080">0    </font>,    <font color="#800080">0    </font>);



<font color="#FF0000"><i>//==COLOR SCHEME
//     State                         Color         Width
//     ~~~~~                         ~~~~~         ~~~~~
</i></font>Style ENABLED    = Style(Color::     BLUE        ,   <font color="#800080">2   </font>);
Style ACTIVE     = Style(Color::     GREEN       ,   <font color="#800080">2   </font>);
Style HOVER      = Style(Color::     RED         ,   <font color="#800080">2   </font>);
Style DISABLED   = Style(Color    (<font color="#800080">128</font>,<font color="#800080">0</font>,<font color="#800080">128</font>)    ,   <font color="#800080">2   </font>);
<font color="#FF0000"><i>//     ~~~~~                         ~~~~~         ~~~~~
</i></font>Style VERT_STYLE = Style(Color::     RED         ,   <font color="#800080">1   </font>);
Style FACE_STYLE = Style(Color::     GREEN       ,   <font color="#800080">1   </font>);
Style EDGE_STYLE = Style(Color::     BLUE        ,   <font color="#800080">3   </font>);

<font color="#FF0000"><i>//==IMAGES
//          Name                    Path                                 Type
//          ~~~~                    ~~~~                                 ~~~~
</i></font><b>const </b>Image BACKGROUND_IMAGE       (<font color="#993366">&quot;ch_back.png&quot;             </font>,Image::   PNG    );
<b>const </b>Image FILE_IMAGE             (<font color="#993366">&quot;ch_file.png&quot;             </font>,Image::   PNG    );
<b>const </b>Image ADD_DEL_COLORS_IMAGE   (<font color="#993366">&quot;ch_add_del_colors.png&quot;   </font>,Image::   PNG    );
<b>const </b>Image MOD_IMAGE              (<font color="#993366">&quot;ch_mod.png&quot;              </font>,Image::   PNG    );
      Image TEMPLATE_IMAGE;
<font color="#FF0000"><i>//=========END===GLOBALS=========




//=========FUNCTIONS=========

//==BUTTON FUNCTIONS
//This should handle the border colors for a given button as well as return
//if it was clicked
</i></font><b>bool </b>clicked(button &amp;to_check,<b>const </b>MouseEvent &amp;m_event);
<b>bool </b>clicked(menu_button &amp;to_check,<b>const </b>MouseEvent &amp;m_event);
<b>bool </b>clicked(<b>const </b>rect &amp;to_check,<b>const </b>MouseEvent &amp;m_event);
<b>void </b>handle_buttons(<b>const </b>MouseEvent &amp;m_event);

<font color="#FF0000"><i>//==MENU=FUNCTIONS
//This takes care of the menus
</i></font><b>void </b>handle_menus(<b>const </b>MouseEvent &amp;m_event);
<font color="#FF0000"><i>//this activates a menu and deactivates all the others
</i></font><b>void </b>activate(menu_button &amp;to_check);

<font color="#FF0000"><i>//==DRAW==FUNCTIONS
</i></font><b>void </b>draw_model(<b>const </b>model &amp;OBJ);
<b>void </b>draw_vert(<b>const </b>vert &amp;to_draw, <b>const </b>Style &amp;the_style);
<b>void </b>draw_vert(<b>const </b>vector&lt;vert&gt; &amp;verts);
<b>void </b>draw_face(<b>const </b>face &amp;to_draw, <b>const </b>Style &amp;the_style);
<b>void </b>draw_face(<b>const </b>vector&lt;face&gt; &amp;faces);

<font color="#FF0000"><i>//==FILE=FUNCTIONS
</i></font><b>void </b>save_model(<b>const </b>model &amp;to_save,<b>const </b>string &amp;file_path);

<font color="#FF0000"><i>//==MODEL=FUNCTIONS
</i></font><b>int </b>get_close_vert(<b>int </b>m_x, <b>int </b>m_y);

<font color="#FF0000"><i>//==CLEARING FUNCTIONS
// Function to wait for a mouse click and clear the screen
</i></font><b>void </b>WaitNClear();
<font color="#FF0000"><i>//clear the window
</i></font><b>void </b>clear();
<font color="#FF0000"><i>//clear an area
</i></font><b>void </b>clear(<b>const </b>rect &amp;to_clear);

<font color="#FF0000"><i>//==STRING FUNCTIONS
</i></font>string input_string(<b>int </b>line_nuber, string prompt);
string mid(string mid_of,<b>int </b>pos,<b>int </b>num_char);
<font color="#FF0000"><i>//Output a strng to a given line in the io window:
</i></font><b>void </b>output(string message,<b>int </b>line_number);

<font color="#FF0000"><i>//=========END====FUNCTIONS=========




//========================MAIN!==========================
</i></font><b>int </b>main()
{
    <font color="#FF0000"><i>//background:
    </i></font>window.drawImage(BACKGROUND_IMAGE,<font color="#800080">0</font>,<font color="#800080">0</font>);
    
    <font color="#FF0000"><i>//init the state of the program
    </i></font>PROG_MODE = NONE;
    
    <font color="#FF0000"><i>//to hold the events in the event loop
    </i></font>MouseEvent m_event;
    KeyboardEvent k_event;
    
    <font color="#FF0000"><i>//other vars:
    </i></font><b>int </b>m_x, m_y, i;
    string prompt;
    string answer;
    <font color="#FF0000"><i>//for finding close est vert
    </i></font><b>int </b>dist,small_dist = <font color="#800080">1000 </font>,vert1,vert2,vert3;
        
    <font color="#FF0000"><i>//event loop
    //while((!window.isKeyboardQueueEmpty() &amp;&amp; (k_event = window.getKeyboardEvent()) == KeyboardEvent() &amp;&amp; !(k_event == KeyboardEvent(NamedKey::ESCAPE))) ^ window.isKeyboardQueueEmpty()){
    </i></font><b>while </b>(<b>true</b>) {
        <font color="#FF0000"><i>//get mouse event now in loop
        </i></font>m_event = window.waitForMouseEvent();
        m_x = window.getMouseX();
        m_y = window.getMouseY();
               
        <font color="#FF0000"><i>//Take care of menus
        </i></font>handle_menus(m_event);
        
        <font color="#FF0000"><i>//Take care of buttons
        </i></font>handle_buttons(m_event);
        
        <b>switch</b>(PROG_MODE) {
        <b>case </b>NONE:
            <b>break</b>;
        <b>case </b>LOAD_2D:
            <font color="#FF0000"><i>//Clear the IO window
            </i></font>clear(IO_WINDOW);
            <font color="#FF0000"><i>//print the action title
            </i></font>output(<font color="#993366">&quot;Load 2D Template Image 651x276&quot;</font>,<font color="#800080">1</font>);
            <font color="#FF0000"><i>//set the prompt + prompt the user
            </i></font>prompt = <font color="#993366">&quot;Enter PNG:&quot;</font>;            
            answer = input_string(<font color="#800080">2</font>,prompt);
            <font color="#FF0000"><i>//set the teplate image file name and type and display the template
            </i></font>TEMPLATE_IMAGE = Image(answer,Image::PNG);
            window.drawImage(TEMPLATE_IMAGE,CANVAS.x1,CANVAS.y1);
            <font color="#FF0000"><i>//Set the prog mode back to nothing
            </i></font>PROG_MODE = NONE;
            <font color="#FF0000"><i>//clear the io window again.
            </i></font>clear(IO_WINDOW);
            <b>break</b>;
        <b>case </b>WIDTH:
            <font color="#FF0000"><i>//Clear the IO window
            </i></font>clear(IO_WINDOW);
            <font color="#FF0000"><i>//print the action title
            </i></font>output(<font color="#993366">&quot;Set Default Model Width (+/- z at each vert)&quot;</font>,<font color="#800080">1</font>);
            <font color="#FF0000"><i>//set the prompt + prompt the user
            </i></font>prompt = <font color="#993366">&quot;Enter Width:&quot;</font>;            
            answer = input_string(<font color="#800080">2</font>,prompt);
            <font color="#FF0000"><i>//set the width
            </i></font>OBJ.width = atoi(answer.c_str());
            <font color="#FF0000"><i>//This is to make the width number updated
            </i></font>window.drawImage(FILE_IMAGE,MENU_RECT.x1,MENU_RECT.y1);
            <b>char </b>width_str[<font color="#800080">20</font>];
            _ultoa(OBJ.width,width_str,<font color="#800080">10</font>);
            window.drawText(FORE_FONT_STYLE,FONT,WIDTH_BTN.my_rect.x1+<font color="#800080">70</font>,WIDTH_BTN.my_rect.y1+<font color="#800080">15</font>,width_str);
            <font color="#FF0000"><i>//Set the prog mode back to nothing
            </i></font>PROG_MODE = NONE;
            <font color="#FF0000"><i>//clear the io window again.
            </i></font>clear(IO_WINDOW);
            <b>break</b>;
        <b>case </b>SAVE:
            <font color="#FF0000"><i>//Clear the IO window
            </i></font>clear(IO_WINDOW);
            <font color="#FF0000"><i>//print the action title
            </i></font>output(<font color="#993366">&quot;Save 3D Wavefront Model OBJ File&quot;</font>,<font color="#800080">1</font>);
            <font color="#FF0000"><i>//set the prompt + prompt the user
            </i></font>prompt = <font color="#993366">&quot;Enter OBJ:&quot;</font>;            
            answer = input_string(<font color="#800080">2</font>,prompt);
            <font color="#FF0000"><i>//save the model
            </i></font>save_model(OBJ,answer);
            <font color="#FF0000"><i>//Set the prog mode back to nothing
            </i></font>PROG_MODE = NONE;
            <font color="#FF0000"><i>//clear the io window again.
            </i></font>clear(IO_WINDOW);
            <b>break</b>;
        <b>case </b>ADD_VERTS:
            <b>if</b>(clicked(CANVAS,m_event)) {
                OBJ.verts.push_back(vert(m_x-CANVAS.x1, m_y-CANVAS.y1, OBJ.width));
                OBJ.verts.push_back(vert(m_x-CANVAS.x1, m_y-CANVAS.y1, (-<font color="#800080">1</font>)*OBJ.width));
                draw_model(OBJ);
            }
            <b>break</b>;
        <b>case </b>ADD_FACES:
            <b>if</b>(clicked(CANVAS,m_event)) {
                <font color="#FF0000"><i>//get vert1 and draw it
                </i></font>vert1 = get_close_vert(m_x,m_y);
                draw_vert(OBJ.verts[vert1],FACE_STYLE);
                
                <font color="#FF0000"><i>//get vert 2...
                </i></font>m_event = window.waitForMouseEvent();
                m_x = window.getMouseX();
                m_y = window.getMouseY();
                <b>while </b>(!clicked(CANVAS,m_event)) {
                    m_event = window.waitForMouseEvent();
                    m_x = window.getMouseX();
                    m_y = window.getMouseY();
                }
                vert2 = get_close_vert(m_x,m_y);
                <font color="#FF0000"><i>//...and draw it
                </i></font>draw_vert(OBJ.verts[vert2],FACE_STYLE);

                <font color="#FF0000"><i>//get vert 3...
                </i></font>m_event = window.waitForMouseEvent();
                m_x = window.getMouseX();
                m_y = window.getMouseY();
                <b>while </b>(!clicked(CANVAS,m_event)) {
                    m_event = window.waitForMouseEvent();
                    m_x = window.getMouseX();
                    m_y = window.getMouseY();
                }
                vert3 = get_close_vert(m_x,m_y);
                <font color="#FF0000"><i>//...and draw it
                </i></font>draw_vert(OBJ.verts[vert3],FACE_STYLE);
                
                OBJ.faces.push_back(face(vert1,vert2,vert3));
                OBJ.faces.push_back(face(vert3+<font color="#800080">1</font>,vert2+<font color="#800080">1</font>,vert1+<font color="#800080">1</font>));
                
                draw_model(OBJ);
            }
            <b>break</b>;
        <b>case </b>ADD_EDGES:
            <b>if</b>(clicked(CANVAS,m_event)) {
                <font color="#FF0000"><i>//get vert1 and draw it
                </i></font>vert1 = get_close_vert(m_x,m_y);
                draw_vert(OBJ.verts[vert1],EDGE_STYLE);
                
                <font color="#FF0000"><i>//get vert 2...
                </i></font>m_event = window.waitForMouseEvent();
                m_x = window.getMouseX();
                m_y = window.getMouseY();
                <b>while </b>(!clicked(CANVAS,m_event)) {
                    m_event = window.waitForMouseEvent();
                    m_x = window.getMouseX();
                    m_y = window.getMouseY();
                }
                vert2 = get_close_vert(m_x,m_y);
                <font color="#FF0000"><i>//...and draw it
                </i></font>draw_vert(OBJ.verts[vert2],EDGE_STYLE);
                
                OBJ.faces.push_back(face(vert2,vert1,vert2+<font color="#800080">1</font>));
                OBJ.faces.push_back(face(vert1+<font color="#800080">1</font>,vert2+<font color="#800080">1</font>,vert1));
                draw_face(OBJ.faces[OBJ.faces.size()-<font color="#800080">1</font>],EDGE_STYLE);
                draw_model(OBJ);
            }
            <b>break</b>;
        <b>case </b>EXIT:
            <font color="#FF0000"><i>//destruct some stuff
            </i></font>window.~Window();
            
            FONT.~Font();
            
            BACKGROUND_IMAGE.~Image();
            FILE_IMAGE.~Image();
            ADD_DEL_COLORS_IMAGE.~Image();
            MOD_IMAGE.~Image();
            TEMPLATE_IMAGE.~Image();
                        
            <b>return </b><font color="#800080">0</font>;
            <b>break</b>;
        }
    }
	<b>return </b><font color="#800080">0</font>;
}
<font color="#FF0000"><i>//========================END===MAIN!==========================

</i></font><b>int </b>get_close_vert(<b>int </b>m_x, <b>int </b>m_y) {
    <b>int </b>close_vert, small_dist = <font color="#800080">10000</font>, dist;
    <b>for</b>(<b>int </b>i = <font color="#800080">0</font>; i &lt; OBJ.verts.size();i+=<font color="#800080">2</font>) {
        dist = sqrt(<b>double</b>((OBJ.verts[i].x - (m_x-CANVAS.x1)))*(OBJ.verts[i].x - (m_x-CANVAS.x1)) + (OBJ.verts[i].y - (m_y-CANVAS.y1))*(OBJ.verts[i].y - (m_y-CANVAS.y1)));
        <font color="#FF0000"><i>//massive debug output :-)
        /*cout &lt;&lt; OBJ.verts[i].x &lt;&lt; '\t' &lt;&lt; (OBJ.verts[i].x - m_x) &lt;&lt; '\t' &lt;&lt; (OBJ.verts[i].x - m_x)*(OBJ.verts[i].x - m_x)
             &lt;&lt; '\t' &lt;&lt; OBJ.verts[i].y &lt;&lt; '\t' &lt;&lt; (OBJ.verts[i].y - m_y) &lt;&lt; '\t' &lt;&lt; (OBJ.verts[i].y - m_y)*(OBJ.verts[i].y - m_y)
             &lt;&lt; endl &lt;&lt; (OBJ.verts[i].x - m_x)*(OBJ.verts[i].x - m_x) + (OBJ.verts[i].y - m_y)*(OBJ.verts[i].y - m_y)
             &lt;&lt; '\t' &lt;&lt; double((OBJ.verts[i].x - m_x))*(OBJ.verts[i].x - m_x) + (OBJ.verts[i].y - m_y)*(OBJ.verts[i].y - m_y)
             &lt;&lt; '\t' &lt;&lt; sqrt(double((OBJ.verts[i].x - m_x))*(OBJ.verts[i].x - m_x) + (OBJ.verts[i].y - m_y)*(OBJ.verts[i].y - m_y))
             &lt;&lt; endl &lt;&lt; endl;*/
        </i></font><b>if </b>(dist &lt; small_dist) {
            small_dist = dist;
            close_vert = i;
        }
    }
    <b>return </b>close_vert;
}

<b>void </b>save_model(<b>const </b>model &amp;to_save,<b>const </b>string &amp;file_path) {
    
    ofstream ofile;
    ofile.open(file_path.c_str());
        <b>for</b>(<b>int </b>i = <font color="#800080">0</font>; i &lt; to_save.verts.size(); i++)
             ofile &lt;&lt; <font color="#993366">&quot;v &quot; 
                   </font>&lt;&lt; to_save.verts[i].x &lt;&lt; ' '
                   &lt;&lt; to_save.verts[i].y &lt;&lt; ' '
                   &lt;&lt; to_save.verts[i].z &lt;&lt; '\n';
        <b>for</b>(<b>int </b>i = <font color="#800080">0</font>; i &lt; to_save.faces.size(); i++)
             ofile &lt;&lt; <font color="#993366">&quot;f &quot; 
                   </font>&lt;&lt; to_save.faces[i].vert1+<font color="#800080">1 </font>&lt;&lt; ' '
                   &lt;&lt; to_save.faces[i].vert2+<font color="#800080">1 </font>&lt;&lt; ' '
                   &lt;&lt; to_save.faces[i].vert3+<font color="#800080">1 </font>&lt;&lt; '\n';
    ofile.close();

}

<b>void </b>draw_model(<b>const </b>model &amp;obj){
    draw_face(obj.faces);
    draw_vert(obj.verts);
}

<b>void </b>draw_face(<b>const </b>vector&lt;face&gt; &amp;faces){
    <b>for</b>(<b>int </b>i = <font color="#800080">0</font>; i &lt; faces.size();i++) {
        draw_face(faces[i],FACE_STYLE);
    }
}

<b>void </b>draw_face(<b>const </b>face &amp;to_draw, <b>const </b>Style &amp;the_style) {

    window.drawLine(the_style,OBJ.verts[to_draw.vert1].x+CANVAS.x1,OBJ.verts[to_draw.vert1].y+CANVAS.y1,OBJ.verts[to_draw.vert2].x+CANVAS.x1,OBJ.verts[to_draw.vert2].y+CANVAS.y1);
    window.drawLine(the_style,OBJ.verts[to_draw.vert2].x+CANVAS.x1,OBJ.verts[to_draw.vert2].y+CANVAS.y1,OBJ.verts[to_draw.vert3].x+CANVAS.x1,OBJ.verts[to_draw.vert3].y+CANVAS.y1);
    window.drawLine(the_style,OBJ.verts[to_draw.vert3].x+CANVAS.x1,OBJ.verts[to_draw.vert3].y+CANVAS.y1,OBJ.verts[to_draw.vert1].x+CANVAS.x1,OBJ.verts[to_draw.vert1].y+CANVAS.y1);

}

<b>void </b>draw_vert(<b>const </b>vector&lt;vert&gt; &amp;verts){
    <b>for</b>(<b>int </b>i = <font color="#800080">0</font>; i &lt; verts.size();i++) {
        draw_vert(verts[i],VERT_STYLE);
    }
}

<b>void </b>draw_vert(<b>const </b>vert &amp;to_draw, <b>const </b>Style &amp;the_style) {
    window.drawCircleFilled(the_style,to_draw.x+CANVAS.x1,to_draw.y+CANVAS.y1,<font color="#800080">4</font>);
}

<b>void </b>handle_buttons(<b>const </b>MouseEvent &amp;m_event){
    
    <b>if</b>(LOAD_2D_BTN.visable) <b>if</b>(clicked(LOAD_2D_BTN,m_event)) PROG_MODE = LOAD_2D;
    <b>if</b>(WIDTH_BTN.visable) <b>if</b>(clicked(WIDTH_BTN,m_event)) PROG_MODE = WIDTH;
    <b>if</b>(SAVE_BTN.visable) <b>if</b>(clicked(SAVE_BTN,m_event)) PROG_MODE = SAVE;
    <b>if</b>(EXIT_BTN.visable) <b>if</b>(clicked(EXIT_BTN,m_event)) PROG_MODE = EXIT;
    <b>if</b>(ADD_VERTS_BTN.visable) <b>if</b>(clicked(ADD_VERTS_BTN,m_event)) {
            <font color="#FF0000"><i>//Clear the IO window
            </i></font>clear(IO_WINDOW);
            <font color="#FF0000"><i>//print the action title
            </i></font>output(<font color="#993366">&quot;Add Verticies.&quot;</font>,<font color="#800080">1</font>);            
        PROG_MODE = ADD_VERTS;
    }
    <b>if</b>(ADD_FACES_BTN.visable) <b>if</b>(clicked(ADD_FACES_BTN,m_event)) {
            <font color="#FF0000"><i>//Clear the IO window
            </i></font>clear(IO_WINDOW);
            <font color="#FF0000"><i>//print the action title
            </i></font>output(<font color="#993366">&quot;Add Faces.&quot;</font>,<font color="#800080">1</font>);            
        PROG_MODE = ADD_FACES;
    }
    <b>if</b>(ADD_EDGES_BTN.visable) <b>if</b>(clicked(ADD_EDGES_BTN,m_event)) {
            <font color="#FF0000"><i>//Clear the IO window
            </i></font>clear(IO_WINDOW);
            <font color="#FF0000"><i>//print the action title
            </i></font>output(<font color="#993366">&quot;Add Edges.&quot;</font>,<font color="#800080">1</font>);            
        PROG_MODE = ADD_EDGES;
    }

}

<b>void </b>activate(menu_button &amp;to_activate) {
    <font color="#FF0000"><i>//deactivate
    </i></font>FILE_BTN.active = <b>false</b>; <b>if</b>(FILE_BTN.enabled) window.drawRectangleOutline(ENABLED,FILE_BTN.my_rect.x1,FILE_BTN.my_rect.y1,FILE_BTN.my_rect.x2,FILE_BTN.my_rect.y2); <b>else </b>window.drawRectangleOutline(DISABLED,FILE_BTN.my_rect.x1,FILE_BTN.my_rect.y1,FILE_BTN.my_rect.x2,FILE_BTN.my_rect.y2);
    ADD_BTN.active = <b>false</b>; <b>if</b>(ADD_BTN.enabled) window.drawRectangleOutline(ENABLED,ADD_BTN.my_rect.x1,ADD_BTN.my_rect.y1,ADD_BTN.my_rect.x2,ADD_BTN.my_rect.y2); <b>else </b>window.drawRectangleOutline(DISABLED,ADD_BTN.my_rect.x1,ADD_BTN.my_rect.y1,ADD_BTN.my_rect.x2,ADD_BTN.my_rect.y2);
    MOD_BTN.active = <b>false</b>; <b>if</b>(MOD_BTN.enabled) window.drawRectangleOutline(ENABLED,MOD_BTN.my_rect.x1,MOD_BTN.my_rect.y1,MOD_BTN.my_rect.x2,MOD_BTN.my_rect.y2); <b>else </b>window.drawRectangleOutline(DISABLED,MOD_BTN.my_rect.x1,MOD_BTN.my_rect.y1,MOD_BTN.my_rect.x2,MOD_BTN.my_rect.y2);
    DEL_BTN.active = <b>false</b>; <b>if</b>(DEL_BTN.enabled) window.drawRectangleOutline(ENABLED,DEL_BTN.my_rect.x1,DEL_BTN.my_rect.y1,DEL_BTN.my_rect.x2,DEL_BTN.my_rect.y2); <b>else </b>window.drawRectangleOutline(DISABLED,DEL_BTN.my_rect.x1,DEL_BTN.my_rect.y1,DEL_BTN.my_rect.x2,DEL_BTN.my_rect.y2);
    COLORS_BTN.active = <b>false</b>; <b>if</b>(COLORS_BTN.enabled) window.drawRectangleOutline(ENABLED,COLORS_BTN.my_rect.x1,COLORS_BTN.my_rect.y1,COLORS_BTN.my_rect.x2,COLORS_BTN.my_rect.y2); <b>else </b>window.drawRectangleOutline(DISABLED,COLORS_BTN.my_rect.x1,COLORS_BTN.my_rect.y1,COLORS_BTN.my_rect.x2,COLORS_BTN.my_rect.y2);
    <font color="#FF0000"><i>//activate
    </i></font>to_activate.active = <b>true</b>; window.drawRectangleOutline(ACTIVE,to_activate.my_rect.x1,to_activate.my_rect.y1,to_activate.my_rect.x2,to_activate.my_rect.y2);
    <b>if</b>(FILE_BTN.active) {
        LOAD_2D_BTN.visable = <b>true</b>; WIDTH_BTN.visable = <b>true</b>; SAVE_BTN.visable = <b>true</b>; EXIT_BTN.visable = <b>true</b>;
        LOAD_2D_BTN.enabled = <b>true</b>; WIDTH_BTN.enabled = <b>true</b>; SAVE_BTN.enabled = <b>true</b>; EXIT_BTN.enabled = <b>true</b>;
    }
    <b>else </b>{
        LOAD_2D_BTN.visable = <b>false</b>; WIDTH_BTN.visable = <b>false</b>; SAVE_BTN.visable = <b>false</b>; EXIT_BTN.visable = <b>false</b>;
        LOAD_2D_BTN.enabled = <b>false</b>; WIDTH_BTN.enabled = <b>false</b>; SAVE_BTN.enabled = <b>false</b>; EXIT_BTN.enabled = <b>false</b>;    
    }        
    <b>if</b>(ADD_BTN.active) {
        ADD_VERTS_BTN.visable = <b>true</b>; ADD_FACES_BTN.visable = <b>true</b>; ADD_EDGES_BTN.visable = <b>true</b>;
        ADD_VERTS_BTN.enabled = <b>true</b>; ADD_FACES_BTN.enabled = <b>true</b>; ADD_EDGES_BTN.enabled = <b>true</b>;
    }
    <b>else </b>{
        ADD_VERTS_BTN.visable = <b>false</b>; ADD_FACES_BTN.visable = <b>false</b>; ADD_EDGES_BTN.visable = <b>false</b>;
        ADD_VERTS_BTN.enabled = <b>false</b>; ADD_FACES_BTN.enabled = <b>false</b>; ADD_EDGES_BTN.enabled = <b>false</b>;
    }        
}

<b>void </b>handle_menus(<b>const </b>MouseEvent &amp;m_event) {

        <b>if</b>(clicked(FILE_BTN,m_event)) {
            <font color="#FF0000"><i>//cout &lt;&lt; &quot;You Clicked FILE!&quot; &lt;&lt; endl;
            </i></font>window.drawImage(FILE_IMAGE,MENU_RECT.x1,MENU_RECT.y1);
            activate(FILE_BTN);
            <b>char </b>width_str[<font color="#800080">20</font>];
            _ultoa(OBJ.width,width_str,<font color="#800080">10</font>);
            window.drawText(FORE_FONT_STYLE,FONT,WIDTH_BTN.my_rect.x1+<font color="#800080">70</font>,WIDTH_BTN.my_rect.y1+<font color="#800080">15</font>,width_str);
        }
        <b>if</b>(clicked(ADD_BTN,m_event)) {
            <font color="#FF0000"><i>//cout &lt;&lt; &quot;You Clicked ADD!&quot; &lt;&lt; endl;
            </i></font>window.drawImage(ADD_DEL_COLORS_IMAGE,MENU_RECT.x1,MENU_RECT.y1);
            activate(ADD_BTN);
        }
        <b>if</b>(clicked(MOD_BTN,m_event)) {
            <font color="#FF0000"><i>//cout &lt;&lt; &quot;You Clicked MOD!&quot; &lt;&lt; endl;
            </i></font>window.drawImage(MOD_IMAGE,MENU_RECT.x1,MENU_RECT.y1);
            activate(MOD_BTN);
        }
        <b>if</b>(clicked(DEL_BTN,m_event)) {
            <font color="#FF0000"><i>//cout &lt;&lt; &quot;You Clicked DEL!&quot; &lt;&lt; endl;
            </i></font>window.drawImage(ADD_DEL_COLORS_IMAGE,MENU_RECT.x1,MENU_RECT.y1);
            activate(DEL_BTN);
        }
        <b>if</b>(clicked(COLORS_BTN,m_event)) {
            <font color="#FF0000"><i>//cout &lt;&lt; &quot;You Clicked COLORS!&quot; &lt;&lt; endl;
            </i></font>window.drawImage(ADD_DEL_COLORS_IMAGE,MENU_RECT.x1,MENU_RECT.y1);
            activate(COLORS_BTN);
        }
}

<b>bool </b>clicked(<b>const </b>rect &amp;to_check,<b>const </b>MouseEvent &amp;m_event){

    <font color="#FF0000"><i>//m_event = window.waitForMouseEvent();
    </i></font><b>int </b>m_x, m_y;
    <b>bool </b>click;
    m_x = window.getMouseX();
    m_y = window.getMouseY();
    click = m_event == MouseEvent(MouseEvent::BUTTON_DOWN_EVENT,MouseEvent::LEFT_BUTTON);
    
    <font color="#FF0000"><i>//cout &lt;&lt; m_event &lt;&lt; '\t' &lt;&lt; click &lt;&lt; endl;
    
    </i></font><b>return </b>(click &amp;&amp; m_x &gt;= to_check.x1 &amp;&amp; m_x &lt;= to_check.x2 &amp;&amp; m_y &gt;= to_check.y1 &amp;&amp; m_y &lt;= to_check.y2);
}

<b>bool </b>clicked(menu_button &amp;to_check,<b>const </b>MouseEvent &amp;m_event){

    <b>int </b>m_x, m_y;
    <b>bool </b>click;
    m_x = window.getMouseX();
    m_y = window.getMouseY();
    click = m_event == MouseEvent(MouseEvent::BUTTON_DOWN_EVENT,MouseEvent::LEFT_BUTTON);
    
    <font color="#FF0000"><i>//debug output
    //cout &lt;&lt; m_event &lt;&lt; '\t' &lt;&lt; click &lt;&lt; endl;
    
    </i></font><b>if</b>(to_check.enabled &amp;&amp; m_x &gt;= to_check.my_rect.x1 &amp;&amp; m_x &lt;= to_check.my_rect.x2 &amp;&amp; m_y &gt;= to_check.my_rect.y1 &amp;&amp; m_y &lt;= to_check.my_rect.y2){
        <font color="#FF0000"><i>//Draw &quot;hover&quot; rectangle around Load2dButton
        </i></font><b>if</b>(!to_check.active) window.drawRectangleOutline(HOVER,to_check.my_rect.x1,to_check.my_rect.y1,to_check.my_rect.x2,to_check.my_rect.y2);
        <b>if</b>(click) <b>return true</b>;
    }
    <b>else </b>{
        <b>if</b>(to_check.enabled) {
           <font color="#FF0000"><i>//Draw &quot;enabled&quot; rectangle around Load2dButton
           </i></font><b>if</b>(!to_check.active) window.drawRectangleOutline(ENABLED,to_check.my_rect.x1,to_check.my_rect.y1,to_check.my_rect.x2,to_check.my_rect.y2);                        
        }
        <b>else </b>{
           <font color="#FF0000"><i>//Draw &quot;disabled&quot; rectangle around Load2dButton
           </i></font>window.drawRectangleOutline(DISABLED,to_check.my_rect.x1,to_check.my_rect.y1,to_check.my_rect.x2,to_check.my_rect.y2);                        
        }
    }
    <b>return false</b>;
}

<b>bool </b>clicked(button &amp;to_check,<b>const </b>MouseEvent &amp;m_event){

    <font color="#FF0000"><i>//m_event = window.waitForMouseEvent();
    </i></font><b>int </b>m_x, m_y;
    <b>bool </b>click;
    m_x = window.getMouseX();
    m_y = window.getMouseY();
    click = m_event == MouseEvent(MouseEvent::BUTTON_DOWN_EVENT,MouseEvent::LEFT_BUTTON);
    
    <font color="#FF0000"><i>//cout &lt;&lt; m_event &lt;&lt; '\t' &lt;&lt; click &lt;&lt; endl;
    
    </i></font><b>if</b>(to_check.enabled &amp;&amp; m_x &gt;= to_check.my_rect.x1 &amp;&amp; m_x &lt;= to_check.my_rect.x2 &amp;&amp; m_y &gt;= to_check.my_rect.y1 &amp;&amp; m_y &lt;= to_check.my_rect.y2){
        <font color="#FF0000"><i>//Draw &quot;hover&quot; rectangle around Load2dButton
        </i></font>window.drawRectangleOutline(HOVER,to_check.my_rect.x1,to_check.my_rect.y1,to_check.my_rect.x2,to_check.my_rect.y2);            
        <b>if</b>(click) <b>return true</b>;
    }
    <b>else </b>{
        <b>if</b>(to_check.enabled) {
           <font color="#FF0000"><i>//Draw &quot;enabled&quot; rectangle around Load2dButton
           </i></font>window.drawRectangleOutline(ENABLED,to_check.my_rect.x1,to_check.my_rect.y1,to_check.my_rect.x2,to_check.my_rect.y2);                        
        }
        <b>else </b>{
           <font color="#FF0000"><i>//Draw &quot;disabled&quot; rectangle around Load2dButton
           </i></font>window.drawRectangleOutline(DISABLED,to_check.my_rect.x1,to_check.my_rect.y1,to_check.my_rect.x2,to_check.my_rect.y2);                        
        }
    }
    <b>return false</b>;
}

string input_string(<b>int </b>line_number, string prompt){
    <font color="#FF0000"><i>//Define String to return
    </i></font>string to_return;
    
    <b>int </b>x = IO_WINDOW.x1 + CHAR_WIDTH;
    <b>int </b>y = IO_WINDOW.y1 + line_number * (CHAR_HEIGHT+<font color="#800080">3</font>) + <font color="#800080">3</font>;
    
    <font color="#FF0000"><i>//Output the Prompt
    </i></font>window.drawText(FORE_FONT_STYLE,FONT,x,y,prompt.c_str());
    
    <font color="#FF0000"><i>//get the chars and output them one at a time
    </i></font>window.flushKeyboardQueue();
    KeyboardEvent key;
    
    <font color="#FF0000"><i>//Draw cursor:
    </i></font>window.drawLine(FORE_CURSOR_STYLE,x + CHAR_WIDTH*prompt.length() + CHAR_WIDTH*to_return.length()+CHAR_WIDTH,y,x + CHAR_WIDTH*prompt.length() + CHAR_WIDTH*to_return.length() + <font color="#800080">2</font>*CHAR_WIDTH,y);
    <font color="#FF0000"><i>//wait for char
    </i></font>key = window.waitForKeyboardEvent();            
    <font color="#FF0000"><i>//Erase cursor:
    </i></font>window.drawLine(BACK_CURSOR_STYLE,x + CHAR_WIDTH*prompt.length() + CHAR_WIDTH*to_return.length()+CHAR_WIDTH,y,x + CHAR_WIDTH*prompt.length() + CHAR_WIDTH*to_return.length() + <font color="#800080">2</font>*CHAR_WIDTH,y);

    <font color="#FF0000"><i>//cout &lt;&lt; x &lt;&lt; endl;
    </i></font><b>for </b>(<b>int </b>char_num = <font color="#800080">0</font>; KeyboardEvent(NamedKey::ENTER) != key; char_num++){
        <font color="#FF0000"><i>//debug output
        //cout &lt;&lt; key &lt;&lt; endl;
        
        </i></font>{
            <b>int </b>i;
            <b>for</b>(i=<font color="#800080">0</font>;i &lt; <font color="#800080">128 </font>&amp;&amp; key != KeyboardEvent(<b>char</b>(i)); i++);
            <font color="#FF0000"><i>//cout &lt;&lt; i &lt;&lt; endl;
    
            </i></font><b>switch </b>(i) {
            <b>case </b><font color="#800080">0x80</font>: <font color="#FF0000"><i>//overflow - that is a special - left,right,etc.
            </i></font><b>case </b><font color="#800080">0x08</font>: <font color="#FF0000"><i>//backspace //disabled
                
                </i></font>char_num--;
                <font color="#FF0000"><i>//Draw cursor:
                </i></font>window.drawLine(FORE_CURSOR_STYLE,x + CHAR_WIDTH*prompt.length() + CHAR_WIDTH*to_return.length() + CHAR_WIDTH,y,x + CHAR_WIDTH*prompt.length() + CHAR_WIDTH*to_return.length() + <font color="#800080">2</font>*CHAR_WIDTH,y);
                <font color="#FF0000"><i>//Get the next keypress
                </i></font>window.flushKeyboardQueue();
                <font color="#FF0000"><i>//wait for char
                </i></font>key = window.waitForKeyboardEvent();            
                <font color="#FF0000"><i>//Erase cursor:
                </i></font>window.drawLine(BACK_CURSOR_STYLE,x + CHAR_WIDTH*prompt.length() + CHAR_WIDTH*to_return.length() + CHAR_WIDTH,y,x + CHAR_WIDTH*prompt.length() + CHAR_WIDTH*to_return.length() + <font color="#800080">2</font>*CHAR_WIDTH,y);

                <font color="#FF0000"><i>/*
                char_num--;

                window.drawText(back_font_style,MyFont,x + CHAR_WIDTH*prompt.length() + CHAR_WIDTH*to_return.length(),y,&amp;to_return[char_num]);
                
                to_return = mid(to_return,0,to_return.length()-1);
                
                //Draw cursor:
                window.drawLine(fore_cursor_style,x + CHAR_WIDTH*prompt.length() + CHAR_WIDTH*to_return.length()+CHAR_WIDTH,y,x + CHAR_WIDTH*prompt.length() + CHAR_WIDTH*to_return.length() + 2*CHAR_WIDTH,y);
                //Get the next keypress
                window.flushKeyboardQueue();
                //wait for char
                key = window.waitForKeyboardEvent();            
                //Erase cursor:
                window.drawLine(back_cursor_style,x + CHAR_WIDTH*prompt.length() + CHAR_WIDTH*to_return.length()+CHAR_WIDTH,y,x + CHAR_WIDTH*prompt.length() + CHAR_WIDTH*to_return.length() + 2*CHAR_WIDTH,y);
                */
                
                </i></font><b>break</b>;
            <b>default</b>:
                <font color="#FF0000"><i>//concatenation
                </i></font>to_return += <b>char</b>(i);        
                <font color="#FF0000"><i>//debug outut
                //cout &lt;&lt; char(i) &lt;&lt; &quot;\t&quot; &lt;&lt; i &lt;&lt; &quot;\t&quot; &lt;&lt; char_num &lt;&lt; &quot;\t&quot; &lt;&lt; to_return &lt;&lt; endl;
                //char output
                </i></font>window.drawText(FORE_FONT_STYLE,FONT,x + CHAR_WIDTH*prompt.length() + CHAR_WIDTH*to_return.length(),y,&amp;to_return[char_num]);
                <font color="#FF0000"><i>//debug output
                //cout &lt;&lt; i &lt;&lt; endl;    
        
                //Draw cursor:
                </i></font>window.drawLine(FORE_CURSOR_STYLE,x + CHAR_WIDTH*prompt.length() + CHAR_WIDTH*to_return.length() + CHAR_WIDTH,y,x + CHAR_WIDTH*prompt.length() + CHAR_WIDTH*to_return.length() + <font color="#800080">2</font>*CHAR_WIDTH,y);
                <font color="#FF0000"><i>//Get the next keypress
                </i></font>window.flushKeyboardQueue();
                <font color="#FF0000"><i>//wait for char
                </i></font>key = window.waitForKeyboardEvent();            
                <font color="#FF0000"><i>//Erase cursor:
                </i></font>window.drawLine(BACK_CURSOR_STYLE,x + CHAR_WIDTH*prompt.length() + CHAR_WIDTH*to_return.length() + CHAR_WIDTH,y,x + CHAR_WIDTH*prompt.length() + CHAR_WIDTH*to_return.length() + <font color="#800080">2</font>*CHAR_WIDTH,y);
        
                <b>break</b>;
            };
        }

    };

    <font color="#FF0000"><i>//debug return
    //to_return = &quot;Test abcdef.&quot;;    
    </i></font><b>return </b>to_return;
}

string mid(string mid_of,<b>int </b>pos,<b>int </b>num_char){

    string to_return;
    
    <b>for </b>(<b>int </b>i = pos; i &lt; pos + num_char; i++)
        to_return += mid_of[i];
    
    <b>return </b>to_return;

}

<b>void </b>WaitNClear()
{ 
    <font color="#FF0000"><i>/*//Set position
    int x = IO_WINDOW.x1 + CHAR_WIDTH;
    int y = IO_WINDOW.y1 + 4 * (CHAR_HEIGHT+3) + 10;*/

    //Display Message
</i></font>	string message;
	message = <font color="#993366">&quot;Press any key to continue...&quot;</font>;
    <font color="#FF0000"><i>//window.drawText(FORE_FONT_STYLE,FONT,x,y,message);    
    </i></font>output(message,<font color="#800080">1</font>);
    output(message,<font color="#800080">2</font>);
    output(message,<font color="#800080">3</font>);
    output(message,<font color="#800080">4</font>);
    output(message,<font color="#800080">5</font>);

    <font color="#FF0000"><i>//Get keypress
    </i></font>window.flushKeyboardQueue();
    window.waitForKeyboardEvent();
    
    <font color="#FF0000"><i>//Clear screen
    </i></font>clear();
}

<b>void </b>output(string message,<b>int </b>line_number) {

   <font color="#FF0000"><i>//Set position
    </i></font><b>int </b>x = IO_WINDOW.x1 + CHAR_WIDTH;
    <b>int </b>y = IO_WINDOW.y1 + line_number * (CHAR_HEIGHT+<font color="#800080">3</font>) + <font color="#800080">3</font>;

    <font color="#FF0000"><i>//Display Message
    </i></font>window.drawText(FORE_FONT_STYLE,FONT,x,y,message);
    
}

<b>void </b>clear() {
    <font color="#FF0000"><i>// Draw a rectangle that covers the entire window
    </i></font>window.drawRectangleFilled(Style::WHITE,<font color="#800080">0</font>, <font color="#800080">0</font>, window.getWidth(), window.getHeight());
}

<b>void </b>clear(<b>const </b>rect &amp;to_clear) {
    window.drawRectangleFilled(BACK_FONT_STYLE,to_clear.x1,to_clear.y1,to_clear.x2,to_clear.y2);
}
</font>
</code></pre>
</body>
</html>




<!--
     FILE ARCHIVED ON 17:00:51 Feb 20, 2007 AND RETRIEVED FROM THE
     INTERNET ARCHIVE ON 3:18:19 Jul 21, 2014.
     JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE.

     ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C.
     SECTION 108(a)(3)).
-->
