Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
ISpElementView.cp
/* |
File: ISpElementView.cp |
Contains: xxx put contents here xxx |
Version: xxx put version here xxx |
Copyright: © 1998 by Apple Computer, Inc., all rights reserved. |
File Ownership: |
DRI: xxx put dri here xxx |
Other Contact: xxx put other contact here xxx |
Technology: xxx put technology here xxx |
Writers: |
(BWS) Brent Schorsch |
Change History (most recent first): |
<9> 7/17/98 BWS add header and change creator for SDK |
*/ |
/************************************************************************************* |
File: ISpElementView.cp |
Copyright © 1996, 1997, 1998 Apple Computer, Inc., All Rights Reserved |
You may incorporate this sample code into your applications without |
restriction, though the sample code has been provided "AS IS" and the |
responsibility for its operation is 100% yours. However, what you are |
not permitted to do is to redistribute the source as "DSC Sample Code" |
after having made changes. If you're going to re-distribute the source, |
we require that you make it clear in the source that the code was |
descended from Apple Sample Code, but that you've made changes. |
*************************************************************************************/ |
#include "ISpElementView.h" |
#include "ISpTestGlobals.h" |
#include <TextUtils.h> |
#include "ISpPPTestTools.h" |
ISpElementView::ISpElementView(LStream *inStream):LOffscreenView(inStream) |
{ |
StartIdling(); |
} |
ISpElementView::~ISpElementView() |
{ |
} |
ISpElementView *ISpElementView::CreateISpElementViewStream(LStream *inStream) |
{ |
return (new ISpElementView(inStream)); |
} |
void ISpElementView::SpendTime(const EventRecord &inMacEvent) |
{ |
inMacEvent; |
Refresh(); |
UpdatePort(); |
} |
void ISpElementView::DrawSelf() |
{ |
if (gElement == nil) { return; } |
Rect r; |
Str255 theString; |
CalcLocalFrameRect(r); |
r.left += 10; |
EraseRect(&r); |
OSStatus pollStatus; |
UInt32 state = 0; |
pollStatus = ISpElement_GetSimpleState(gElement, &state); |
ISpElementInfo info; |
ISpElement_GetInfo(gElement, &info); |
MoveTo(r.left, r.top + 15); |
DrawString("\pGlobal Error Code: "); |
NumToString(gStatus, theString); |
DrawString(theString); |
MoveTo(r.left, r.top + 30); |
DrawString("\pPoll Error Code: "); |
NumToString(pollStatus, theString); |
DrawString(theString); |
MoveTo(r.left, r.top + 45); |
DrawString("\pData: "); |
UInt32ToHexString(state, theString); |
DrawString(theString); |
const rectWidth = 100; |
Rect maxRect = {2,0,11,rectWidth}; |
Rect progRect = maxRect; |
float percent; |
switch(info.theKind) |
{ |
case kISpElementKind_Axis: |
{ |
percent = state; |
percent /= 0xffffffff; |
} |
break; |
case kISpElementKind_Delta: |
{ |
float inches = ((float) (Fixed) state) / (float) 0xffff; |
percent = 0.5 + (inches / 2); |
} |
} |
if (percent > 1) { percent = 1; } |
if (percent < 0) { percent = 0; } |
progRect.right = rectWidth * percent; |
OffsetRect(&maxRect, r.left, r.top + 47); |
OffsetRect(&progRect, r.left, r.top + 47); |
::FrameRect(&maxRect); |
::PaintRect(&progRect); |
MoveTo(r.left, r.top + 75); |
DrawString("\pElement Num: "); |
UInt32ToHexString((unsigned long) gElement, theString); |
DrawString(theString); |
MoveTo(r.left, r.top + 90); |
DrawString("\pElement Label: "); |
UInt32ToFourByte(info.theLabel, theString); |
DrawString(theString); |
MoveTo(r.left, r.top + 105); |
DrawString("\pElement Kind: "); |
UInt32ToFourByte(info.theKind, theString); |
DrawString(theString); |
MoveTo(r.left, r.top + 120); |
DrawString("\pElement Name: "); |
DrawString(info.theString); |
MoveTo(r.left, r.top + 135); |
ISpDeviceReference device; |
ISpElement_GetDevice(gElement, &device); |
ISpDeviceDefinition device_def; |
ISpDevice_GetDefinition(device, sizeof(ISpDeviceDefinition), &device_def); |
DrawString("\pDevice Info: "); |
DrawString(device_def.deviceName); |
DrawString("\p ("); |
UInt32ToFourByte(device_def.theDeviceClass, theString); |
DrawString(theString); |
DrawString("\p) ("); |
UInt32ToFourByte(device_def.theDeviceIdentifier, theString); |
DrawString(theString); |
DrawString("\p) ("); |
UInt32ToFourByte(device_def.permanentID, theString); |
DrawString(theString); |
DrawString("\p) ("); |
UInt32ToHexString(device_def.flags, theString); |
DrawString(theString); |
DrawString("\p)"); |
MoveTo(r.left, r.top + 150); |
OSStatus getConfigStatus = noErr; |
switch (info.theKind) |
{ |
case kISpElementKind_Button: |
ISpButtonConfigurationInfo buttonInfo; |
getConfigStatus = ISpElement_GetConfigurationInfo(gElement, sizeof (buttonInfo), &buttonInfo); |
if (getConfigStatus == noErr) |
{ |
DrawString("\pButton Ordering: "); |
NumToString (buttonInfo.id, theString); |
DrawString(theString); |
} |
break; |
case kISpElementKind_DPad: |
ISpDPadConfigurationInfo dpadInfo; |
getConfigStatus = ISpElement_GetConfigurationInfo(gElement, sizeof (dpadInfo), &dpadInfo); |
if (getConfigStatus == noErr) |
{ |
DrawString("\pDPad Ordering: "); |
NumToString (dpadInfo.id, theString); |
DrawString(theString); |
MoveTo(r.left, r.top + 165); |
DrawString("\pIs Four-Way Pad: "); |
if (dpadInfo.fourWayPad) |
DrawString("\pTrue"); |
else |
DrawString("\pFalse"); |
} |
break; |
case kISpElementKind_Axis: |
ISpAxisConfigurationInfo axisInfo; |
getConfigStatus = ISpElement_GetConfigurationInfo(gElement, sizeof (axisInfo), &axisInfo); |
if (getConfigStatus == noErr) |
{ |
DrawString("\pAxis Is Symetric: "); |
if (axisInfo.symetricAxis) |
DrawString("\pTrue"); |
else |
DrawString("\pFalse"); |
} |
break; |
case kISpElementKind_Delta: |
DrawString("\pNo Configuration for kISpElementKind_Delta kind "); |
break; |
case kISpElementKind_Movement: |
DrawString("\pNo Configuration for kISpElementKind_Movement kind "); |
break; |
case kISpElementKind_Virtual: |
DrawString("\pNo Configuration for kISpElementKind_Virtual kind "); |
break; |
} |
if (getConfigStatus != noErr) |
{ |
DrawString("\pISpElement_GetConfigurationInfo error: "); |
NumToString (getConfigStatus, theString); |
DrawString(theString); |
} |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-14