/// <summary> /// Return the extension mask for the given tag. /// </summary> /// <param name="tag_I">type of extension being searched for</param> /// <returns>0xFFFFFFFF on error</returns> public static UInt32 GetWTExtensionMask(EWTXExtensionTag tag_I) { UInt32 extMask = 0; IntPtr buf = CMemUtils.AllocUnmanagedBuf(extMask); try { UInt32 extIndex = FindWTExtensionIndex(tag_I); // Supported if extIndex != -1 if (extIndex != 0xFFFFFFFF) { int size = (int)CWintabFuncs.WTInfo( (uint)EWTICategoryIndex.WTI_EXTENSIONS + (uint)extIndex, (uint)EWTIExtensionIndex.EXT_MASK, buf); extMask = (UInt32)CMemUtils.MarshalUnmanagedBuf <UInt32>(buf, size); } } catch (Exception ex) { MessageBox.Show("FAILED GetWTExtensionMask: " + ex.ToString()); } CMemUtils.FreeUnmanagedBuf(buf); return(extMask); }
/// <summary> /// Write out an image to a tablet's OLED (Organic Light Emitting Diode) /// if supported by the tablet (eg: Intuos4). /// </summary> /// <param name="context_I">wintab context</param> /// <param name="extTagIndex_I">which extension tag we're setting</param> /// <param name="tabletIndex_I">index of the tablet being set</param> /// <param name="controlIndex_I">the index of the control being set</param> /// <param name="functionIndex_I">the index of the control function being set</param> /// <param name="imageFilePath_I">path to PNG image file</param> private static bool SetIcon( CWintabContext context_I, EWTXExtensionTag extTagIndex_I, UInt32 tabletIndex_I, UInt32 controlIndex_I, UInt32 functionIndex_I, String imageFilePath_I) { try { if (!CWintabExtensions.ControlPropertySetImage( context_I.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, (byte)controlIndex_I, (byte)functionIndex_I, (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_OVERRIDE_ICON, imageFilePath_I)) { throw new Exception("Oops - FAILED ControlPropertySet for TABLET_PROPERTY_OVERRIDE"); } } catch (Exception ex) { throw ex; } return(true); }
/// <summary> /// Returns extension index tag for given tag, if possible. /// </summary> /// <param name="tag_I">type of extension being searched for</param> /// <returns>0xFFFFFFFF on error</returns> public static UInt32 FindWTExtensionIndex(EWTXExtensionTag tag_I) { UInt32 thisTag = 0; UInt32 extIndex = 0xFFFFFFFF; IntPtr buf = CMemUtils.AllocUnmanagedBuf(thisTag); for (Int32 loopIdx = 0, size = -1; size != 0; loopIdx++) { size = (int)CWintabFuncs.WTInfo( (uint)EWTICategoryIndex.WTI_EXTENSIONS + (UInt32)loopIdx, (uint)EWTIExtensionIndex.EXT_TAG, buf); if (size > 0) { thisTag = CMemUtils.MarshalUnmanagedBuf <UInt32>(buf, size); if ((EWTXExtensionTag)thisTag == tag_I) { extIndex = (UInt32)loopIdx; break; } } } CMemUtils.FreeUnmanagedBuf(buf); return(extIndex); }
/// <summary> /// Return the extension mask for the given tag. /// </summary> /// <param name="tag_I">type of extension being searched for</param> /// <returns>0xFFFFFFFF on error</returns> public static UInt32 GetWTExtensionMask(EWTXExtensionTag tag_I) { UInt32 extMask = 0; IntPtr buf = CMemUtils.AllocUnmanagedBuf(extMask); try { UInt32 extIndex = FindWTExtensionIndex(tag_I); // Supported if extIndex != -1 if (extIndex != 0xFFFFFFFF) { int size = (int)CWintabFuncs.WTInfo( (uint)EWTICategoryIndex.WTI_EXTENSIONS + (uint)extIndex, (uint)EWTIExtensionIndex.EXT_MASK, buf); extMask = (UInt32)CMemUtils.MarshalUnmanagedBuf <UInt32>(buf, size); } } finally { CMemUtils.FreeUnmanagedBuf(buf); } return(extMask); }
/// <summary> /// Iterate through and setup all controls on this extension. /// </summary> /// <param name="tabletIndex_I">tablet index</param> /// <param name="extTagIndex_I">extension index tag</param> /// <param name="setupFunc_I">function called to setup extension control layout</param> public void SetupControlsForExtension( UInt32 tabletIndex_I, EWTXExtensionTag extTagIndex_I, DrawControlsSetupFunction setupFunc_I) { UInt32 numCtrls = 0; try { // Get number of controls of this type. if (!CWintabExtensions.ControlPropertyGet( mLogContext.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, 0, // ignored 0, // ignored (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_CONTROLCOUNT, ref numCtrls)) { throw new Exception("Oops - Failed ControlPropertyGet for TABLET_PROPERTY_CONTROLCOUNT"); } // All tablets should have ExpressKeys (we assume). if (numCtrls == 0 && EWTXExtensionTag.WTX_EXPKEYS2 == extTagIndex_I) { throw new Exception("Oops - SetupControlsForExtension didn't find any ExpressKeys!"); } for (UInt32 idx = 0; idx < numCtrls; idx++) { SetupFunctionsForControl(tabletIndex_I, extTagIndex_I, idx, numCtrls, setupFunc_I); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Iterate through and setup all functions on this control. /// </summary> /// </summary> /// <param name="tabletIndex_I">tablet index</param> /// <param name="extTagIndex_I">extension index tag</param> /// <param name="controlIndex_I">control index</param> /// <param name="setupFunc_I">function called to setup extension control layout</param> public void SetupFunctionsForControl( UInt32 tabletIndex_I, EWTXExtensionTag extTagIndex_I, UInt32 controlIndex_I, UInt32 numControls_I, DrawControlsSetupFunction setupFunc_I) { UInt32 numFuncs = 0; try { // Get the number of functions for this control. if (!CWintabExtensions.ControlPropertyGet( mLogContext.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, (byte)controlIndex_I, 0, // ignored (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_FUNCCOUNT, ref numFuncs)) { throw new Exception("Oops - Failed ControlPropertyGet for TABLET_PROPERTY_FUNCCOUNT"); } Debug.Assert(numFuncs > 0); for (UInt32 funcIdx = 0; funcIdx < numFuncs; funcIdx++) { SetupPropertiesForFunctions(tabletIndex_I, extTagIndex_I, controlIndex_I, funcIdx, numControls_I, setupFunc_I); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Sets properties for the specified control. /// </summary> /// <param name="tabletIndex_I"></param> /// <param name="extTagIndex_I"></param> /// <param name="controlIndex_I"></param> /// <param name="functionIndex_I"></param> /// <param name="ctrlName_I"></param> private void SetControlProperties(UInt32 tabletIndex_I, EWTXExtensionTag extTagIndex_I, UInt32 controlIndex_I, UInt32 functionIndex_I, UInt32 numControls_I, String ctrlName_I) { try { switch (extTagIndex_I) { case EWTXExtensionTag.WTX_EXPKEYS2: { bool visible = mExtensionControlState.Tablets[tabletIndex_I].expKeys[controlIndex_I].available; // Prepend indication of left or right side to control name. // NOTE - don't forget that any string modifications will eventually be // encoded to UTF8 before being sent to the driver. int location = mExtensionControlState.Tablets[tabletIndex_I].expKeys[controlIndex_I].location; String ctrlName = (location == 0 ? "L_" : "R_") + ctrlName_I; int uiIndex = location == 0 ? (int)controlIndex_I : // left-side indicator (int)(controlIndex_I + Math.Abs((Int32)(numControls_I / 2 - 8))); // right-side indicator switch (uiIndex) { // map controlIndex_I to a left-side express key indicator. case 0: Tab0_L_EK1Panel.Visible = visible; Tab0_L_EK1NameLabel.Visible = visible; Tab0_L_EK1NameLabel.Text = ctrlName; break; case 1: Tab0_L_EK2Panel.Visible = visible; Tab0_L_EK2NameLabel.Visible = visible; Tab0_L_EK2NameLabel.Text = ctrlName; break; case 2: Tab0_L_EK3Panel.Visible = visible; Tab0_L_EK3NameLabel.Visible = visible; Tab0_L_EK3NameLabel.Text = ctrlName; break; case 3: Tab0_L_EK4Panel.Visible = visible; Tab0_L_EK4NameLabel.Visible = visible; Tab0_L_EK4NameLabel.Text = ctrlName; break; case 4: Tab0_L_EK5Panel.Visible = visible; Tab0_L_EK5NameLabel.Visible = visible; Tab0_L_EK5NameLabel.Text = ctrlName; break; case 5: Tab0_L_EK6Panel.Visible = visible; Tab0_L_EK6NameLabel.Visible = visible; Tab0_L_EK6NameLabel.Text = ctrlName; break; case 6: Tab0_L_EK7Panel.Visible = visible; Tab0_L_EK7NameLabel.Visible = visible; Tab0_L_EK7NameLabel.Text = ctrlName; break; case 7: Tab0_L_EK8Panel.Visible = visible; Tab0_L_EK8NameLabel.Visible = visible; Tab0_L_EK8NameLabel.Text = ctrlName; break; // map controlIndex_I to a right-side express key indicator. case 8: Tab0_R_EK1Panel.Visible = visible; Tab0_R_EK1NameLabel.Visible = visible; Tab0_R_EK1NameLabel.Text = ctrlName; break; case 9: Tab0_R_EK2Panel.Visible = visible; Tab0_R_EK2NameLabel.Visible = visible; Tab0_R_EK2NameLabel.Text = ctrlName; break; case 10: Tab0_R_EK3Panel.Visible = visible; Tab0_R_EK3NameLabel.Visible = visible; Tab0_R_EK3NameLabel.Text = ctrlName; break; case 11: Tab0_R_EK4Panel.Visible = visible; Tab0_R_EK4NameLabel.Visible = visible; Tab0_R_EK4NameLabel.Text = ctrlName; break; case 12: Tab0_R_EK5Panel.Visible = visible; Tab0_R_EK5NameLabel.Visible = visible; Tab0_R_EK5NameLabel.Text = ctrlName; break; case 13: Tab0_R_EK6Panel.Visible = visible; Tab0_R_EK6NameLabel.Visible = visible; Tab0_R_EK6NameLabel.Text = ctrlName; break; case 14: Tab0_R_EK7Panel.Visible = visible; Tab0_R_EK7NameLabel.Visible = visible; Tab0_R_EK7NameLabel.Text = ctrlName; break; case 15: Tab0_R_EK8Panel.Visible = visible; Tab0_R_EK8NameLabel.Visible = visible; Tab0_R_EK8NameLabel.Text = ctrlName; break; default: throw new Exception("Oops - unknown ExpressKey uiIndex: " + uiIndex.ToString()); } } break; case EWTXExtensionTag.WTX_TOUCHRING: { bool visible = mExtensionControlState.Tablets[tabletIndex_I].touchRings[controlIndex_I].available; int location = mExtensionControlState.Tablets[tabletIndex_I].touchRings[controlIndex_I].location; String TRname = location == 0 ? "Left" : "Right"; String ctrlName = (location == 0 ? "L_" : "R_") + ctrlName_I; switch (controlIndex_I) { case 0: Tab0_TR1NameLabel.Visible = visible; Tab0_TR1NameLabel.Text = TRname; // Set mode button state. switch (functionIndex_I) { case 0: Tab0_TR1Mode1Panel.Visible = visible; Tab0_TR1Mode1NameLabel.Visible = visible; Tab0_TR1Mode1NameLabel.Text = ctrlName; break; case 1: Tab0_TR1Mode2Panel.Visible = visible; Tab0_TR1Mode2NameLabel.Visible = visible; Tab0_TR1Mode2NameLabel.Text = ctrlName; break; case 2: Tab0_TR1Mode3Panel.Visible = visible; Tab0_TR1Mode3NameLabel.Visible = visible; Tab0_TR1Mode3NameLabel.Text = ctrlName; break; case 3: Tab0_TR1Mode4Panel.Visible = visible; Tab0_TR1Mode4NameLabel.Visible = visible; Tab0_TR1Mode4NameLabel.Text = ctrlName; break; default: throw new Exception("Oops - unknown mode index"); } break; case 1: Tab0_TR2NameLabel.Visible = visible; Tab0_TR2NameLabel.Text = TRname; // Set mode button state. switch (functionIndex_I) { case 0: Tab0_TR2Mode1Panel.Visible = visible; Tab0_TR2Mode1NameLabel.Visible = visible; Tab0_TR2Mode1NameLabel.Text = ctrlName; break; case 1: Tab0_TR2Mode2Panel.Visible = visible; Tab0_TR2Mode2NameLabel.Visible = visible; Tab0_TR2Mode2NameLabel.Text = ctrlName; break; case 2: Tab0_TR2Mode3Panel.Visible = visible; Tab0_TR2Mode3NameLabel.Visible = visible; Tab0_TR2Mode3NameLabel.Text = ctrlName; break; case 3: Tab0_TR2Mode4Panel.Visible = visible; Tab0_TR2Mode4NameLabel.Visible = visible; Tab0_TR2Mode4NameLabel.Text = ctrlName; break; default: throw new Exception("Oops - unknown mode index"); } break; default: throw new Exception("Oops - unknown TouchRing controlIndex_I: " + controlIndex_I.ToString()); } } break; case EWTXExtensionTag.WTX_TOUCHSTRIP: { bool visible = mExtensionControlState.Tablets[tabletIndex_I].touchStrips[controlIndex_I].available; int location = mExtensionControlState.Tablets[tabletIndex_I].touchStrips[controlIndex_I].location; String TRname = location == 0 ? "Left" : "Right"; String ctrlName = (location == 0 ? "L_" : "R_") + ctrlName_I; switch (controlIndex_I) { case 0: Tab0_TS1NameLabel.Visible = visible; Tab0_TS1NameLabel.Text = TRname; // Set mode button state. switch (functionIndex_I) { case 0: Tab0_TS1Mode1Panel.Visible = visible; Tab0_TS1Mode1NameLabel.Visible = visible; Tab0_TS1Mode1NameLabel.Text = ctrlName; break; case 1: Tab0_TS1Mode2Panel.Visible = visible; Tab0_TS1Mode2NameLabel.Visible = visible; Tab0_TS1Mode2NameLabel.Text = ctrlName; break; case 2: Tab0_TS1Mode3Panel.Visible = visible; Tab0_TS1Mode3NameLabel.Visible = visible; Tab0_TS1Mode3NameLabel.Text = ctrlName; break; case 3: Tab0_TS1Mode4Panel.Visible = visible; Tab0_TS1Mode4NameLabel.Visible = visible; Tab0_TS1Mode4NameLabel.Text = ctrlName; break; default: throw new Exception("Oops - unknown mode index"); } break; case 1: Tab0_TS2NameLabel.Visible = visible; Tab0_TS2NameLabel.Text = TRname; // Set mode button state. switch (functionIndex_I) { case 0: Tab0_TS2Mode1Panel.Visible = visible; Tab0_TS2Mode1NameLabel.Visible = visible; Tab0_TS2Mode1NameLabel.Text = ctrlName; break; case 1: Tab0_TS2Mode2Panel.Visible = visible; Tab0_TS2Mode2NameLabel.Visible = visible; Tab0_TS2Mode2NameLabel.Text = ctrlName; break; case 2: Tab0_TS2Mode3Panel.Visible = visible; Tab0_TS2Mode3NameLabel.Visible = visible; Tab0_TS2Mode3NameLabel.Text = ctrlName; break; case 3: Tab0_TS2Mode4Panel.Visible = visible; Tab0_TS2Mode4NameLabel.Visible = visible; Tab0_TS2Mode4NameLabel.Text = ctrlName; break; default: throw new Exception("Oops - unknown mode index"); } break; default: throw new Exception("Oops - unknown TouchRing controlIndex_I: " + controlIndex_I.ToString()); } } break; default: throw new Exception("Oops - unknown tagIndex: " + extTagIndex_I.ToString()); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Iterate through all functions on this control. /// </summary> /// </summary> /// <param name="tabletIndex_I">tablet index</param> /// <param name="extTagIndex_I">extension index tag</param> /// <param name="controlIndex_I">control index</param> /// <param name="functionIndex_I">control function index</param> /// <param name="setupFunc_I">function called to setup extension control layout</param> public void SetupPropertiesForFunctions( UInt32 tabletIndex_I, EWTXExtensionTag extTagIndex_I, UInt32 controlIndex_I, UInt32 functionIndex_I, UInt32 numControls_I, DrawControlsSetupFunction setupFunc_I) { bool bIsAvailable = false; try { WTPKT propOverride = 1; // true UInt32 ctrlAvailable = 0; UInt32 ctrlLocation = 0; UInt32 ctrlMinRange = 0; UInt32 ctrlMaxRange = 0; String indexStr = extTagIndex_I == EWTXExtensionTag.WTX_EXPKEYS2 ? Convert.ToString(controlIndex_I) : Convert.ToString(functionIndex_I); // NOTE - you can use strings in any language here. // The strings will be encoded to UTF8 before sent to the driver. // For example, you could use the string: "付録A" to indicate "EK" in Japanese. String ctrlname = extTagIndex_I == EWTXExtensionTag.WTX_EXPKEYS2 ? "EK: " + indexStr : extTagIndex_I == EWTXExtensionTag.WTX_TOUCHRING ? "TR: " + indexStr : extTagIndex_I == EWTXExtensionTag.WTX_TOUCHSTRIP ? "TS: " + indexStr : /* unknown control */ "UK: " + indexStr; do { // Ask if control is available for override. if (!CWintabExtensions.ControlPropertyGet( mLogContext.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, (byte)controlIndex_I, (byte)functionIndex_I, (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_AVAILABLE, ref ctrlAvailable)) { throw new Exception("Oops - FAILED ControlPropertyGet for TABLET_PROPERTY_AVAILABLE"); } bIsAvailable = (ctrlAvailable > 0); if (!bIsAvailable) { Debug.WriteLine("Cannot override control"); break; } // Set flag indicating we're overriding the control. if (!CWintabExtensions.ControlPropertySet( mLogContext.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, (byte)controlIndex_I, (byte)functionIndex_I, (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_OVERRIDE, propOverride)) { throw new Exception("Oops - FAILED ControlPropertySet for TABLET_PROPERTY_OVERRIDE"); } // Set the control name. if (!CWintabExtensions.ControlPropertySet( mLogContext.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, (byte)controlIndex_I, (byte)functionIndex_I, (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_OVERRIDE_NAME, ctrlname)) { throw new Exception("Oops - FAILED ControlPropertySet for TABLET_PROPERTY_OVERRIDE_NAME"); } // Get the location of the control if (!CWintabExtensions.ControlPropertyGet( mLogContext.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, (byte)controlIndex_I, (byte)functionIndex_I, (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_LOCATION, ref ctrlLocation)) { throw new Exception("Oops - FAILED ControlPropertyGet for TABLET_PROPERTY_LOCATION"); } if (!CWintabExtensions.ControlPropertyGet( mLogContext.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, (byte)controlIndex_I, (byte)functionIndex_I, (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_MIN, ref ctrlMinRange)) { throw new Exception("Oops - FAILED ControlPropertyGet for TABLET_PROPERTY_MIN"); } if (!CWintabExtensions.ControlPropertyGet( mLogContext.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, (byte)controlIndex_I, (byte)functionIndex_I, (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_MAX, ref ctrlMaxRange)) { throw new Exception("Oops - FAILED ControlPropertyGet for TABLET_PROPERTY_MAX"); } // Set tablet OLED with icon (if supported by the tablet). // Ignore return value for now. CWintabExtensions.SetDisplayProperty( mLogContext, extTagIndex_I, tabletIndex_I, controlIndex_I, functionIndex_I, mTestImageIconPath); // Finally, call function to setup control layout for rendering. // Control will be updated when WT_PACKETEXT packets received. setupFunc_I( (int)tabletIndex_I, (int)controlIndex_I, (int)functionIndex_I, bIsAvailable, (int)ctrlLocation, (int)ctrlMinRange, (int)ctrlMaxRange); SetControlProperties(tabletIndex_I, extTagIndex_I, controlIndex_I, functionIndex_I, numControls_I, ctrlname); } while (false); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Remove application overrides for extension. /// </summary> /// <param name="tabletIndex_I"></param> /// <param name="extTagIndex_I"></param> void RemoveOverridesForExtension( UInt32 tabletIndex_I, EWTXExtensionTag extTagIndex_I) { UInt32 numCtrls = 0; UInt32 numFuncs = 0; UInt32 propOverride = 0; // false try { // Get number of controls of this type. if (!CWintabExtensions.ControlPropertyGet( mLogContext.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, 0, // ignored 0, // ignored (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_CONTROLCOUNT, ref numCtrls)) { throw new Exception("Oops - Failed ControlPropertyGet for TABLET_PROPERTY_CONTROLCOUNT"); } // All tablets should have ExpressKeys (we assume). if (numCtrls == 0 && EWTXExtensionTag.WTX_EXPKEYS2 == extTagIndex_I) { throw new Exception("Oops - SetupControlsForExtension didn't find any ExpressKeys!"); } // For each control, find its number of functions ... for (UInt32 controlIndex = 0; controlIndex < numCtrls; controlIndex++) { if (!CWintabExtensions.ControlPropertyGet( mLogContext.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, (byte)controlIndex, 0, // ignored (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_FUNCCOUNT, ref numFuncs)) { throw new Exception("Oops - Failed ControlPropertyGet for TABLET_PROPERTY_FUNCCOUNT"); } // ... and override our setting for each function. for (UInt32 functionIndex = 0; functionIndex < numFuncs; functionIndex++) { if (!CWintabExtensions.ControlPropertySet( mLogContext.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, (byte)controlIndex, (byte)functionIndex, (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_OVERRIDE, propOverride)) { throw new Exception("Oops - FAILED ControlPropertySet for TABLET_PROPERTY_OVERRIDE"); } } } } catch (Exception ex) { throw ex; } }
/// <summary> /// Set tablet OLED display property. /// </summary> /// <param name="context_I">wintab context</param> /// <param name="extTagIndex_I">which extension tag we're setting</param> /// <param name="tabletIndex_I">index of the tablet being set</param> /// <param name="controlIndex_I">the index of the control being set</param> /// <param name="functionIndex_I">the index of the control function being set</param> /// <param name="imageFilePath_I">path to PNG image file</param> /// <returns>true if successful and tablet supports property</returns> public static bool SetDisplayProperty( CWintabContext context_I, EWTXExtensionTag extTagIndex_I, UInt32 tabletIndex_I, UInt32 controlIndex_I, UInt32 functionIndex_I, String imageFilePath_I) { UInt32 iconFmt = 0; // Bail out if image file not found. if (imageFilePath_I == "" || !System.IO.File.Exists(imageFilePath_I)) { return false; } try { if (!CWintabExtensions.ControlPropertyGet( context_I.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, (byte)controlIndex_I, (byte)functionIndex_I, (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_ICON_FORMAT, ref iconFmt)) { throw new Exception("Oops - Failed ControlPropertyGet for TABLET_PROPERTY_ICON_FORMAT"); } if ((EWTExtensionIconProperty)iconFmt != EWTExtensionIconProperty.TABLET_ICON_FMT_NONE) { // Get the width and height of the display icon. UInt32 iconWidth = 0; UInt32 iconHeight = 0; if (!CWintabExtensions.ControlPropertyGet( context_I.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, (byte)controlIndex_I, (byte)functionIndex_I, (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_ICON_WIDTH, ref iconWidth)) { throw new Exception("Oops - Failed ControlPropertyGet for TABLET_PROPERTY_ICON_WIDTH"); } if (!CWintabExtensions.ControlPropertyGet( context_I.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, (byte)controlIndex_I, (byte)functionIndex_I, (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_ICON_HEIGHT, ref iconHeight)) { throw new Exception("Oops - Failed ControlPropertyGet for TABLET_PROPERTY_ICON_HEIGHT"); } return SetIcon(context_I, extTagIndex_I, tabletIndex_I, controlIndex_I, functionIndex_I, imageFilePath_I); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } // Not supported by tablet. return false; }
/// <summary> /// Iterate through and setup all controls on this extension. /// </summary> /// <param name="tabletIndex_I">tablet index</param> /// <param name="extTagIndex_I">extension index tag</param> /// <param name="setupFunc_I">function called to setup extension control layout</param> public void SetupControlsForExtension( UInt32 tabletIndex_I, EWTXExtensionTag extTagIndex_I, DrawControlsSetupFunction setupFunc_I) { UInt32 numCtrls = 0; try { // Get number of controls of this type. if ( !CWintabExtensions.ControlPropertyGet( mLogContext.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, 0, // ignored 0, // ignored (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_CONTROLCOUNT, ref numCtrls) ) { throw new Exception("Oops - Failed ControlPropertyGet for TABLET_PROPERTY_CONTROLCOUNT"); } // All tablets should have ExpressKeys (we assume). if (numCtrls == 0 && EWTXExtensionTag.WTX_EXPKEYS2 == extTagIndex_I) { throw new Exception("Oops - SetupControlsForExtension didn't find any ExpressKeys!"); } for (UInt32 idx = 0; idx < numCtrls; idx++) { SetupFunctionsForControl(tabletIndex_I, extTagIndex_I, idx, numCtrls, setupFunc_I); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Set tablet OLED display property. /// </summary> /// <param name="context_I">wintab context</param> /// <param name="extTagIndex_I">which extension tag we're setting</param> /// <param name="tabletIndex_I">index of the tablet being set</param> /// <param name="controlIndex_I">the index of the control being set</param> /// <param name="functionIndex_I">the index of the control function being set</param> /// <param name="imageFilePath_I">path to PNG image file</param> /// <returns>true if successful and tablet supports property</returns> public static bool SetDisplayProperty( CWintabContext context_I, EWTXExtensionTag extTagIndex_I, UInt32 tabletIndex_I, UInt32 controlIndex_I, UInt32 functionIndex_I, String imageFilePath_I) { UInt32 iconFmt = 0; // Bail out if image file not found. if (imageFilePath_I == "" || !System.IO.File.Exists(imageFilePath_I)) { return(false); } try { if (!CWintabExtensions.ControlPropertyGet( context_I.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, (byte)controlIndex_I, (byte)functionIndex_I, (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_ICON_FORMAT, ref iconFmt)) { throw new Exception("Oops - Failed ControlPropertyGet for TABLET_PROPERTY_ICON_FORMAT"); } if ((EWTExtensionIconProperty)iconFmt != EWTExtensionIconProperty.TABLET_ICON_FMT_NONE) { // Get the width and height of the display icon. UInt32 iconWidth = 0; UInt32 iconHeight = 0; if (!CWintabExtensions.ControlPropertyGet( context_I.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, (byte)controlIndex_I, (byte)functionIndex_I, (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_ICON_WIDTH, ref iconWidth)) { throw new Exception("Oops - Failed ControlPropertyGet for TABLET_PROPERTY_ICON_WIDTH"); } if (!CWintabExtensions.ControlPropertyGet( context_I.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, (byte)controlIndex_I, (byte)functionIndex_I, (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_ICON_HEIGHT, ref iconHeight)) { throw new Exception("Oops - Failed ControlPropertyGet for TABLET_PROPERTY_ICON_HEIGHT"); } return(SetIcon(context_I, extTagIndex_I, tabletIndex_I, controlIndex_I, functionIndex_I, imageFilePath_I)); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } // Not supported by tablet. return(false); }
/// <summary> /// Return the extension mask for the given tag. /// </summary> /// <param name="tag_I">type of extension being searched for</param> /// <returns>0xFFFFFFFF on error</returns> public static UInt32 GetWTExtensionMask(EWTXExtensionTag tag_I) { UInt32 extMask = 0; IntPtr buf = CMemUtils.AllocUnmanagedBuf(extMask); try { UInt32 extIndex = FindWTExtensionIndex(tag_I); // Supported if extIndex != -1 if (extIndex != 0xFFFFFFFF) { int size = (int)CWintabFuncs.WTInfoA( (uint)EWTICategoryIndex.WTI_EXTENSIONS + (uint)extIndex, (uint)EWTIExtensionIndex.EXT_MASK, buf); extMask = (UInt32)CMemUtils.MarshalUnmanagedBuf<UInt32>(buf, size); } } catch (Exception ex) { MessageBox.Show("FAILED GetWTExtensionMask: " + ex.ToString()); } CMemUtils.FreeUnmanagedBuf(buf); return extMask; }
/// <summary> /// Returns extension index tag for given tag, if possible. /// </summary> /// <param name="tag_I">type of extension being searched for</param> /// <returns>0xFFFFFFFF on error</returns> public static UInt32 FindWTExtensionIndex(EWTXExtensionTag tag_I) { UInt32 thisTag = 0; UInt32 extIndex = 0xFFFFFFFF; IntPtr buf = CMemUtils.AllocUnmanagedBuf(thisTag); for (Int32 loopIdx = 0, size = -1; size != 0; loopIdx++) { size = (int)CWintabFuncs.WTInfoA( (uint)EWTICategoryIndex.WTI_EXTENSIONS + (UInt32)loopIdx, (uint)EWTIExtensionIndex.EXT_TAG, buf); if (size > 0) { thisTag = CMemUtils.MarshalUnmanagedBuf<UInt32>(buf, size); if ((EWTXExtensionTag)thisTag == tag_I) { extIndex = (UInt32)loopIdx; break; } } } CMemUtils.FreeUnmanagedBuf(buf); return extIndex; }
/// <summary> /// Remove application overrides for extension. /// </summary> /// <param name="tabletIndex_I"></param> /// <param name="extTagIndex_I"></param> void RemoveOverridesForExtension( UInt32 tabletIndex_I, EWTXExtensionTag extTagIndex_I) { UInt32 numCtrls = 0; UInt32 numFuncs = 0; UInt32 propOverride = 0; // false try { // Get number of controls of this type. if ( !CWintabExtensions.ControlPropertyGet( mLogContext.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, 0, // ignored 0, // ignored (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_CONTROLCOUNT, ref numCtrls) ) { throw new Exception("Oops - Failed ControlPropertyGet for TABLET_PROPERTY_CONTROLCOUNT"); } // All tablets should have ExpressKeys (we assume). if (numCtrls == 0 && EWTXExtensionTag.WTX_EXPKEYS2 == extTagIndex_I) { throw new Exception("Oops - SetupControlsForExtension didn't find any ExpressKeys!"); } // For each control, find its number of functions ... for (UInt32 controlIndex = 0; controlIndex < numCtrls; controlIndex++) { if (!CWintabExtensions.ControlPropertyGet( mLogContext.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, (byte)controlIndex, 0, // ignored (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_FUNCCOUNT, ref numFuncs)) { throw new Exception("Oops - Failed ControlPropertyGet for TABLET_PROPERTY_FUNCCOUNT"); } // ... and override our setting for each function. for (UInt32 functionIndex = 0; functionIndex < numFuncs; functionIndex++) { if (! CWintabExtensions.ControlPropertySet( mLogContext.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, (byte)controlIndex, (byte)functionIndex, (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_OVERRIDE, propOverride)) { throw new Exception("Oops - FAILED ControlPropertySet for TABLET_PROPERTY_OVERRIDE"); } } } } catch (Exception ex) { throw ex; } }
/// <summary> /// Write out an image to a tablet's OLED (Organic Light Emitting Diode) /// if supported by the tablet (eg: Intuos4). /// </summary> /// <param name="context_I">wintab context</param> /// <param name="extTagIndex_I">which extension tag we're setting</param> /// <param name="tabletIndex_I">index of the tablet being set</param> /// <param name="controlIndex_I">the index of the control being set</param> /// <param name="functionIndex_I">the index of the control function being set</param> /// <param name="imageFilePath_I">path to PNG image file</param> private static bool SetIcon( CWintabContext context_I, EWTXExtensionTag extTagIndex_I, UInt32 tabletIndex_I, UInt32 controlIndex_I, UInt32 functionIndex_I, String imageFilePath_I) { try { if (!CWintabExtensions.ControlPropertySetImage( context_I.HCtx, (byte)extTagIndex_I, (byte)tabletIndex_I, (byte)controlIndex_I, (byte)functionIndex_I, (ushort)EWTExtensionTabletProperty.TABLET_PROPERTY_OVERRIDE_ICON, imageFilePath_I)) { throw new Exception("Oops - FAILED ControlPropertySet for TABLET_PROPERTY_OVERRIDE"); } } catch (Exception ex) { throw ex; } return true; }
/// <summary> /// Sets properties for the specified control. /// </summary> /// <param name="tabletIndex_I"></param> /// <param name="extTagIndex_I"></param> /// <param name="controlIndex_I"></param> /// <param name="functionIndex_I"></param> /// <param name="ctrlName_I"></param> private void SetControlProperties(UInt32 tabletIndex_I, EWTXExtensionTag extTagIndex_I, UInt32 controlIndex_I, UInt32 functionIndex_I, UInt32 numControls_I, String ctrlName_I) { try { switch (extTagIndex_I) { case EWTXExtensionTag.WTX_EXPKEYS2: { bool visible = mExtensionControlState.Tablets[tabletIndex_I].expKeys[controlIndex_I].available; // Prepend indication of left or right side to control name. // NOTE - don't forget that any string modifications will eventually be // encoded to UTF8 before being sent to the driver. int location = mExtensionControlState.Tablets[tabletIndex_I].expKeys[controlIndex_I].location; String ctrlName = (location == 0 ? "L_" : "R_") + ctrlName_I; int uiIndex = location == 0 ? (int)controlIndex_I : // left-side indicator (int)(controlIndex_I + Math.Abs((Int32)(numControls_I/2 - 8))); // right-side indicator switch (uiIndex) { // map controlIndex_I to a left-side express key indicator. case 0: Tab0_L_EK1Panel.Visible = visible; Tab0_L_EK1NameLabel.Visible = visible; Tab0_L_EK1NameLabel.Text = ctrlName; break; case 1: Tab0_L_EK2Panel.Visible = visible; Tab0_L_EK2NameLabel.Visible = visible; Tab0_L_EK2NameLabel.Text = ctrlName; break; case 2: Tab0_L_EK3Panel.Visible = visible; Tab0_L_EK3NameLabel.Visible = visible; Tab0_L_EK3NameLabel.Text = ctrlName; break; case 3: Tab0_L_EK4Panel.Visible = visible; Tab0_L_EK4NameLabel.Visible = visible; Tab0_L_EK4NameLabel.Text = ctrlName; break; case 4: Tab0_L_EK5Panel.Visible = visible; Tab0_L_EK5NameLabel.Visible = visible; Tab0_L_EK5NameLabel.Text = ctrlName; break; case 5: Tab0_L_EK6Panel.Visible = visible; Tab0_L_EK6NameLabel.Visible = visible; Tab0_L_EK6NameLabel.Text = ctrlName; break; case 6: Tab0_L_EK7Panel.Visible = visible; Tab0_L_EK7NameLabel.Visible = visible; Tab0_L_EK7NameLabel.Text = ctrlName; break; case 7: Tab0_L_EK8Panel.Visible = visible; Tab0_L_EK8NameLabel.Visible = visible; Tab0_L_EK8NameLabel.Text = ctrlName; break; // map controlIndex_I to a right-side express key indicator. case 8: Tab0_R_EK1Panel.Visible = visible; Tab0_R_EK1NameLabel.Visible = visible; Tab0_R_EK1NameLabel.Text = ctrlName; break; case 9: Tab0_R_EK2Panel.Visible = visible; Tab0_R_EK2NameLabel.Visible = visible; Tab0_R_EK2NameLabel.Text = ctrlName; break; case 10: Tab0_R_EK3Panel.Visible = visible; Tab0_R_EK3NameLabel.Visible = visible; Tab0_R_EK3NameLabel.Text = ctrlName; break; case 11: Tab0_R_EK4Panel.Visible = visible; Tab0_R_EK4NameLabel.Visible = visible; Tab0_R_EK4NameLabel.Text = ctrlName; break; case 12: Tab0_R_EK5Panel.Visible = visible; Tab0_R_EK5NameLabel.Visible = visible; Tab0_R_EK5NameLabel.Text = ctrlName; break; case 13: Tab0_R_EK6Panel.Visible = visible; Tab0_R_EK6NameLabel.Visible = visible; Tab0_R_EK6NameLabel.Text = ctrlName; break; case 14: Tab0_R_EK7Panel.Visible = visible; Tab0_R_EK7NameLabel.Visible = visible; Tab0_R_EK7NameLabel.Text = ctrlName; break; case 15: Tab0_R_EK8Panel.Visible = visible; Tab0_R_EK8NameLabel.Visible = visible; Tab0_R_EK8NameLabel.Text = ctrlName; break; default: throw new Exception("Oops - unknown ExpressKey uiIndex: " + uiIndex.ToString()); } } break; case EWTXExtensionTag.WTX_TOUCHRING: { bool visible = mExtensionControlState.Tablets[tabletIndex_I].touchRings[controlIndex_I].available; int location = mExtensionControlState.Tablets[tabletIndex_I].touchRings[controlIndex_I].location; String TRname = location == 0 ? "Left" : "Right"; String ctrlName = (location == 0 ? "L_" : "R_") + ctrlName_I; switch (controlIndex_I) { case 0: Tab0_TR1NameLabel.Visible = visible; Tab0_TR1NameLabel.Text = TRname; // Set mode button state. switch (functionIndex_I) { case 0: Tab0_TR1Mode1Panel.Visible = visible; Tab0_TR1Mode1NameLabel.Visible = visible; Tab0_TR1Mode1NameLabel.Text = ctrlName; break; case 1: Tab0_TR1Mode2Panel.Visible = visible; Tab0_TR1Mode2NameLabel.Visible = visible; Tab0_TR1Mode2NameLabel.Text = ctrlName; break; case 2: Tab0_TR1Mode3Panel.Visible = visible; Tab0_TR1Mode3NameLabel.Visible = visible; Tab0_TR1Mode3NameLabel.Text = ctrlName; break; case 3: Tab0_TR1Mode4Panel.Visible = visible; Tab0_TR1Mode4NameLabel.Visible = visible; Tab0_TR1Mode4NameLabel.Text = ctrlName; break; default: throw new Exception("Oops - unknown mode index"); } break; case 1: Tab0_TR2NameLabel.Visible = visible; Tab0_TR2NameLabel.Text = TRname; // Set mode button state. switch (functionIndex_I) { case 0: Tab0_TR2Mode1Panel.Visible = visible; Tab0_TR2Mode1NameLabel.Visible = visible; Tab0_TR2Mode1NameLabel.Text = ctrlName; break; case 1: Tab0_TR2Mode2Panel.Visible = visible; Tab0_TR2Mode2NameLabel.Visible = visible; Tab0_TR2Mode2NameLabel.Text = ctrlName; break; case 2: Tab0_TR2Mode3Panel.Visible = visible; Tab0_TR2Mode3NameLabel.Visible = visible; Tab0_TR2Mode3NameLabel.Text = ctrlName; break; case 3: Tab0_TR2Mode4Panel.Visible = visible; Tab0_TR2Mode4NameLabel.Visible = visible; Tab0_TR2Mode4NameLabel.Text = ctrlName; break; default: throw new Exception("Oops - unknown mode index"); } break; default: throw new Exception("Oops - unknown TouchRing controlIndex_I: " + controlIndex_I.ToString()); } } break; case EWTXExtensionTag.WTX_TOUCHSTRIP: { bool visible = mExtensionControlState.Tablets[tabletIndex_I].touchStrips[controlIndex_I].available; int location = mExtensionControlState.Tablets[tabletIndex_I].touchStrips[controlIndex_I].location; String TRname = location == 0 ? "Left" : "Right"; String ctrlName = (location == 0 ? "L_" : "R_") + ctrlName_I; switch (controlIndex_I) { case 0: Tab0_TS1NameLabel.Visible = visible; Tab0_TS1NameLabel.Text = TRname; // Set mode button state. switch (functionIndex_I) { case 0: Tab0_TS1Mode1Panel.Visible = visible; Tab0_TS1Mode1NameLabel.Visible = visible; Tab0_TS1Mode1NameLabel.Text = ctrlName; break; case 1: Tab0_TS1Mode2Panel.Visible = visible; Tab0_TS1Mode2NameLabel.Visible = visible; Tab0_TS1Mode2NameLabel.Text = ctrlName; break; case 2: Tab0_TS1Mode3Panel.Visible = visible; Tab0_TS1Mode3NameLabel.Visible = visible; Tab0_TS1Mode3NameLabel.Text = ctrlName; break; case 3: Tab0_TS1Mode4Panel.Visible = visible; Tab0_TS1Mode4NameLabel.Visible = visible; Tab0_TS1Mode4NameLabel.Text = ctrlName; break; default: throw new Exception("Oops - unknown mode index"); } break; case 1: Tab0_TS2NameLabel.Visible = visible; Tab0_TS2NameLabel.Text = TRname; // Set mode button state. switch (functionIndex_I) { case 0: Tab0_TS2Mode1Panel.Visible = visible; Tab0_TS2Mode1NameLabel.Visible = visible; Tab0_TS2Mode1NameLabel.Text = ctrlName; break; case 1: Tab0_TS2Mode2Panel.Visible = visible; Tab0_TS2Mode2NameLabel.Visible = visible; Tab0_TS2Mode2NameLabel.Text = ctrlName; break; case 2: Tab0_TS2Mode3Panel.Visible = visible; Tab0_TS2Mode3NameLabel.Visible = visible; Tab0_TS2Mode3NameLabel.Text = ctrlName; break; case 3: Tab0_TS2Mode4Panel.Visible = visible; Tab0_TS2Mode4NameLabel.Visible = visible; Tab0_TS2Mode4NameLabel.Text = ctrlName; break; default: throw new Exception("Oops - unknown mode index"); } break; default: throw new Exception("Oops - unknown TouchRing controlIndex_I: " + controlIndex_I.ToString()); } } break; default: throw new Exception("Oops - unknown tagIndex: " + extTagIndex_I.ToString()); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }