<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Allegro + Tablet PC with Touch Screen</title>
		<link>http://www.allegro.cc/forums/view/600432</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 01 Jun 2009 20:43:20 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve recently bought myself a Windows Tablet PC with a touchscreen thinking my Allegro project would just  work with it. Turns out I was wrong <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> Since I invested a lot of money in the tablet, I was determined to get Allegro working with it. The good news is that I managed to finally get everything working (stylus/mouse/touch.) The bad news is I&#39;m not sure the best way to implement this directly into Allegro.</p><p>Some specs:<br />Toshiba Portege M750 with touchscreen<br />Windows Vista Business<br />Allegro 4.2.2</p><p>First I searched these forums and found no solutions. A search for &quot;tablet&quot; brings up a bunch of posts on Wacom tablets. And searching for &quot;touch screen&quot; brings up a few posts which describe my problem, but their solutions seem to work for Wacom tablets, not touch screens or styluses (styli?) I tried commenting out the handlers for DIMOFS_X and DIMOFS_Y in wmmouse.c, function mouse_dinput_handle_event. No luck, just broke everything.</p><p>The behavior I see is the cursor is always at one corner of the screen. But I found  if I point the stylus at the center and move just a little, then it will bounce around dramatically, but still be somewhere on the screen.</p><p>I checked out what data is being returned from Direct Input. It looks like data being passed to mouse_dinput_handle_event are in range (-2560, -1600) - (2560, 1600) Absolute coordinates. But if you use the mouse then relative coordinates are passed. Touch screen is also absolute, but I did not check to see the range. Since the behavior is similar to the stylus input, my guess is that it&#39;s the same. </p><p>PROBLEM 1: How does someone tell if the data being passed is relative or absolute?<br />PROBLEM 2: How do I know what device is sending me the data?<br />PROBLEM 3: How do I know the range of that absolute device?</p><p>Since I could not answer these questions, I decided I needed a different approach. I tried to edit wwnd.c and handle WM_MOUSEMOVE, WM_LBUTTONDOWN, and WM_LBUTTONDOWN messages in directx_wnd_proc.</p><p>I found that I wasn&#39;t getting WM_MOUSEMOVE messages in full screen mode.</p><p>I managed to find a work around for this. GetCursorPos will work, but only if you don&#39;t initialize Allegro&#39;s mouse routines and you account for the window location in windowed mode.</p><p>So I export wnd_x and wnd_y in allegro.def, and include aintwin.h in my project. Then I can get the mouse position with this code...</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number"> 1</span>  POINT p<span class="k2">;</span>
<span class="number"> 2</span>  GetCursorPos<span class="k2">(</span><span class="k3">&amp;</span>p<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 3</span>  <span class="k1">int</span> mx <span class="k3">=</span> p.x <span class="k3">-</span> wnd_x<span class="k2">;</span>
<span class="number"> 4</span>  <span class="k1">int</span> my <span class="k3">=</span> p.y <span class="k3">-</span> wnd_y<span class="k2">;</span>
</div></div><p>

Now I need to handle mouse clicks. I am getting button down/up messages so I&#39;ll use those. I add a variable to winalleg.h</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number"> 1</span>AL_VAR<span class="k2">(</span><span class="k1">volatile</span> <span class="k1">int</span>, windows_mouse_b1<span class="k2">)</span><span class="k2">;</span>
</div></div><p>

And define it in wwnd.c</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number"> 1</span><span class="k1">volatile</span> <span class="k1">int</span> windows_mouse_b1 <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
</div></div><p>

And add this to the switch in wwnd.c, function directx_wnd_proc.</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number"> 1</span><span class="k1">case</span> WM_LBUTTONDOWN:
<span class="number"> 2</span>  windows_mouse_b1 <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span>
<span class="number"> 3</span>  <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 4</span><span class="k1">case</span> WM_LBUTTONUP:
<span class="number"> 5</span>  windows_mouse_b1 <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 6</span>  <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
</div></div><p>

Then export windows_mouse_b1 in allegro.def. It sort of works. Mouse is fine, you have to press really hard on the stylus to acknowledge a click, and the touchscreen does not move the cursor before you get the click message. <img src="http://www.allegro.cc/forums/smileys/angry.gif" alt="&gt;:(" /></p><p>Dig through WinUser.h, find messages WM_TABLET_FIRST and WM_TABLET_LAST with nothing in between them. I start capturing the messages in this range. I only find one, when I click with the stylus or touch the screen, it&#39;s undocumented message 716 (0x2CC) I figure out this is a message saying click and set the cursor at the same time. I add this code to directx_wnd_proc</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number"> 1</span><span class="k1">case</span> <span class="n">716</span><span class="k2">:</span>
<span class="number"> 2</span>  windows_mouse_b1 <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span>
<span class="number"> 3</span>  SetCursorPos<span class="k2">(</span>LOWORD<span class="k2">(</span>lparam<span class="k2">)</span>, HIWORD<span class="k2">(</span>lparam<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 4</span>  <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
</div></div><p>

The mouse up message is received as normal and everything works! I can switch between mouse and stylus and touch screen and the input is always interpreted correctly whether in full screen or windowed. Since message #716 is not documented, I&#39;m afraid it will change in Windows 7. I haven&#39;t figured out right clicking yet either. I have not tested it in Allegro 4.4 but I checked the code and didn&#39;t see anything that would indicate a fix for this. I haven&#39;t tested or checked Allegro 5.</p><p>So that&#39;s what I&#39;ve figured out. Maybe that will help with tablet/touch screen support in the future. It&#39;s at least a workaround for people who want tablet support now. Although really we should be using the tablet SDK to write a windows mouse driver. I&#39;m just glad I finally got this working. </p><p>-Mark
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (mseiden)</author>
		<pubDate>Mon, 01 Jun 2009 04:15:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>uhumm...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Alianix)</author>
		<pubDate>Mon, 01 Jun 2009 09:13:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>In 4.9, we don&#39;t use DirectInput at all for the mouse code - if you want you can try if 4.9 works wit your tablet. And if it does, maybe someone will back-port the changes.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Mon, 01 Jun 2009 17:52:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/600432/814316#target">Elias</a> said:</div><div class="quote"><p>
In 4.9, we don&#39;t use DirectInput at all for the mouse code
</p></div></div><p>

Hey, look at that. It was fixed in 4.9 sometime in the last month. From your responses, I feel like I should have known that somehow <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (mseiden)</author>
		<pubDate>Mon, 01 Jun 2009 20:43:20 +0000</pubDate>
	</item>
</rss>
