c# pdf viewer open source : How to rearrange pages in a pdf reader application SDK tool html wpf .net online World%20of%20Warcraft%20Programming%20(2nd%20Edition)35-part1833

CHA P T ER
16
Binding Keys and Clicks
to Addon Code
Most of the user input discussed so far has revolved around the mouse
and graphical interface elements. Chapter 12 gave you a taste of
OnClick
,
OnEnter
,andafewotherhandlers,aswellasthe
Button
and
EditBox
widgets.
In Chapter 15, you learned how to change the behavior of action buttons
depending on which mouse button was used and/or which modifier keys
were pressed at the time. This chapter shows you how to interact with the
keyboardand mousedirectly,outsidethecontextofUIwidgets.
TIP
TheonlyformsofuserinputtheWoWinterfacerecognizesatthetimeofthis
writingarekeyboardandmouse. Ifyouwanttouse alternativemeans tocontrol
thegame,say agamepadorvoicecommands,youhavetoconfigurethehardware
orsoftwaresothatthey imitateakeyboardormouse.Thereisevidenceof
possiblejoystickorgamepadsupportinafuturepatch, butnothingisofficially
partoftheUIyet.
The key bindingsystem treats both types of inputthe same way. Each key
or mouse button goes by a particular name. For basic letters, numbers, and
symbols,the name is simply the result of hitting the key with Caps Lock on.
Specialkeysandmousebuttons havedescriptivenameslike
LEFT
,
NUMPAD3
,or
BUTTON1.
Forthe sakeofsimplicity,we’llrefertotheseaskeys,which youcan
taketomean ‘‘keyormousebutton name.’’Youusethekey-bindinginterface
(accessiblefromthemain gamemenu)asshownin Figure16-1toassign these
variouskeys tospecificactions.
Keys and commands have a many-to-one relationship—you can bind many
keys to one command, but you can’t bind one key to many commands. You
309
How to rearrange pages in a pdf reader - re-order PDF pages in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
Support Customizing Page Order of PDF Document in C# Project
how to reorder pdf pages in; change page order in pdf online
How to rearrange pages in a pdf reader - VB.NET PDF Page Move Library: re-order PDF pages in vb.net, ASP.NET, MVC, Ajax, WinForms, WPF
Sort PDF Document Pages Using VB.NET Demo Code
pdf change page order acrobat; move pdf pages
310
Part III
AdvancedAddonTechniques
can seethisinthescreenshot,which hastwocolumnsofkeybuttons foreach
command(behindthescenes,you’re notlimitedtotwo).
Figure 16-1: WoWkeybindinginterface
Thecommandsthatappearinthedefaultkeybindinginterfacearespecified
in
FrameXML\Bindings.xml
.You can also provide a
Bindings.xml
file in the
rootdirectoryofyouraddontoaddcustombindingstothelist.
Defining Bindings in XML
The structure of
Bindings.xml
is very simple. The root element is
Bindings
,
and each command is represented by a single
Binding
element. The key
binding interface builds the listof bindings in the same order they appear in
the file. When addons provide a
Bindings.xml
,their bindings appear at the
endofthelistintheordertheaddons areloaded.Takea lookatanentryfrom
thedefaultuserinterface:
<Bindings>
...
<Binding name=“TOGGLESHEATH“>
ToggleSheath();
C# TIFF: How to Reorder, Rearrange & Sort TIFF Pages Using C# Code
C# TIFF - Sort TIFF File Pages Order in C#.NET. Reorder, Rearrange and Sort TIFF Document Pages in C#.NET Application. C# TIFF Page Sorting Overview.
reorder pdf page; pdf reverse page order
VB.NET TIFF: Modify TIFF File by Adding, Deleting & Sort TIFF
you want to change or rearrange current TIFF &ltsummary> ''' Sort TIFF document pages in designed powerful & profession imaging controls, PDF document, image
how to move pages in a pdf document; change page order in pdf file
Chapter16
Binding Keysand Clicks to AddonCode
311
</Binding>
...
</Bindings>
The
name
attribute,inthiscase
TOGGLESHEATH
,setsthenameofthisparticular
action. You use this name with the
SetBinding()
functions later in this
chapter. The key binding interface looks for a global string variable called
BINDING_NAME_name
to label the binding in the list. For example, the value
of
BINDING_NAME_TOGGLESHEATH
is
Sheath/Unsheath Weapon
in the English
versionofWoW(see Figure16-1).
Once you bind a key to a command, the code inside the
Binding
tag
is executed whenever you press the key. In this case, because
Z
is bound
to
TOGGLESHEATH
,pressing
Z
calls the
ToggleSheath
function, which cycles
through yourequippedweapons.
NOTE
Thereare certainsituations inwhichkeybindingsmightnotappearto
workcorrectly,suchas whenyoutrytouseakeyboardbindingwhileanEditBox
widgethasthe keyboardfocus. Similarly formousebuttons, anytimethe cursoris
overamouse-enabledframe, theframe consumesbuttonclicksforusewith
OnClick,OnMouseDown,andsoon,whetherornotthehandlers have been
definedforthe frame.
Keybindings areconsultedonly ifthe keysorbuttonsaren’tconsumedby some
otheraspectoftheuserinterface.
Here’s another example from the built-in
Bindings.xml
that illustrates a
couplemorefeatures:
<Binding name=“MOVEANDSTEER“ runOnUp=“true“ header=“MOVEMENT“>
if ( keystate == “down“ ) then
MoveAndSteerStart();
else
MoveAndSteerStop();
end
</Binding>
As with the previous example, this binding includes a
name
attribute
and a Lua chunk. The new
header
attribute sets up a heading for the key
binding interface. In this case WoW looks for
BINDING_HEADER_<attribute>
to determine the text of the header. You can see in Figure 16-1 that
BINDING_HEADER_MOVEMENT
isdefinedas MovementKeysin theEnglishclient.
Ofparticularnoteisthe
runOnUp
attribute,whichtellsthegametoexecutethe
binding code twice: once when the key is pressed down, and again when
the key is released. The code sample shows that WoW provides a
keystate
VB.NET PDF File & Page Process Library SDK for vb.net, ASP.NET
page directly. Moreover, when you get a PDF document which is out of order, you need to rearrange the PDF document pages. In these
reorder pdf pages online; reorder pages in pdf preview
C# PowerPoint - How to Process PowerPoint
pages simply with a few lines of C# code. C# Codes to Sort Slides Order. If you want to use a very easy PPT slide dealing solution to sort and rearrange
how to reverse pages in pdf; pdf rearrange pages
312
Part III
AdvancedAddonTechniques
parameterofeither
“down“
or
“up“
,allowingyoutodeterminewhichcondition
triggeredtheexecution.
Creating Your Own Binding Actions
Nowthatyouhavean ideaofthestructureofthebindings file,takeamoment
to experiment with some bindings of your own. For the next few sections,
you’ll work on an addon called BindingTest. Create a directory under your
AddOns
directory called
BindingTest
.Create
BindingTest.toc
and add the
followingtothe file:
## Interface: 30200
## Title: Key Bindings Test
## Notes: Demonstrates the usage of Bindings.xml
BindingTest.lua
BindingTest.xml
Createempty
BindingTest.lua
and
BindingTest.xml
files;you’ll addcode
tothemlater. Finally,create a file called
Bindings.xml
and input the follow-
ing code:
<Bindings>
<Binding name=“BINDING_TEST1“ header=“BINDING_TEST“>
BindingTest_Test1()
</Binding>
<Binding name=“BINDING_TEST2“ runOnUp=“true“>
BindingTest_Test2(keystate)
</Binding>
</Bindings>
Notice that
Bindings.xml
is not listed in the table of contents file—WoW
always loads
Bindings.xml
ifpresent.
If you start up WoW and open the key bindings interface, you should see
something likeFigure16-2.
Notice how there’s an empty space where the header will go, and how
your custom bindings are simply labeled with the action names from
Bindings.xml
. To remedy this, open your addon’s Lua file and add the
followingglobal strings:
BINDING_HEADER_BINDING_TEST = “Test bindings for Chapter 16“
BINDING_NAME_BINDING_TEST1 = “Test binding #1“
BINDING_NAME_BINDING_TEST2 = “Test binding #2“
Savethefileandreloadtheuserinterfaceusingthe
/reload
slashcommand.
Nowwhenyouopen thekeybindingsscreen itshouldlook likeFigure16-3.
VB.NET Word: How to Process MS Word in VB.NET Library in .NET
well programmed Word pages sorter to rearrange Word pages in extracting single or multiple Word pages at one & profession imaging controls, PDF document, image
reorder pages in pdf reader; how to reorder pages in pdf preview
Process Images in Web Image Viewer | Online Tutorials
used document types are supported, including PDF, multi-page easy to process image and file pages with the deleting a thumbnail, and you can rearrange the file
move pages in pdf file; reverse pdf page order online
Chapter16
Binding Keysand Clicks to AddonCode
313
Figure16-2: Keybindinginterfacewithblanktest bindings
Figure16-3: Keybindinginterfacewithnamedtestbindings
VB.NET PowerPoint: Sort and Reorder PowerPoint Slides by Using VB.
page will teach you to rearrange and readjust amount of robust PPT slides/pages editing methods and powerful & profession imaging controls, PDF document, image
reordering pdf pages; how to rearrange pdf pages
314
Part III
AdvancedAddonTechniques
At this point, you can go ahead and bind keys to these two test bindings.
You’ll probably want to use keys that aren’t already bound to something
important to save youa bit of trouble when you get back to actually playing
the game. Because you haven’t defined the functions yet, activating the key
bindings triggers a Lua error. Add these functions to
BindingTest.lua
and
givethembasicbehavioras follows:
function BindingTest_Test1()
print(“Test binding #1 activated“)
end
function BindingTest_Test2(keystate)
if keystate == “down“ then
print(“Test binding #2 pressed“)
else
print(“Test binding #2 released“)
end
end
After reloading the UI,spend a few moments experimenting with the two
keys youbound.You’llseeresultssimilartoFigure16-4.
Figure 16-4: Sampleoutputfromkeybindings
One pointworth notingfromthis screenshot isthatmorethan one binding
can be ‘‘in progress’’ simultaneously. This is illustrated in the last four lines
whereTest#2 ispressed,then Test #1is activatedtwice, andfinallyTest #2is
released.Thenumberofseparatekeysthatyoucanuseatthesametimevaries
dependingon yourkeyboardhardwareandoperatingsystem.
Binding Keys to Actions
The key binding interface works fairly well for basic binding control, but it
doeshaveafewlimitations.Firstoff,manyuserscomplain abouttheinterface
itselfbecauseit’sratherdifficulttonavigate—especiallywhen youstartpiling
on more and more addons with their additional sections. There’s also the
problemmentionedearlierwhereonlytwokeysareshown foragivenaction.
You may choose tobypass the default interface altogether for your addon,
orperhapsyouwanttomakeanaddonthatreplacesthekeybindinginterface
Chapter16
Binding Keysand Clicks to AddonCode
315
itselfwithsomethingabitmoreflexible.Eitherway,you’llneedtosetthekey
bindingsprogrammatically.
Building a Simple Binding UI
To give you an overview of the various binding APIs, create a basicbinding
interfacefortheBindingTestaddon.This interfacewill consistoftwobuttons,
one for each binding action. You left-click the buttons to add a binding
and right-click to remove a binding. Figure 16-5 shows an example of this
interfacein use.
Figure16-5: Basickeybindinginterface
Tobegin,open
BindingTest.xml
andaddthefollowingcode:
<Ui xmlns=“http://www.blizzard.com/wow/ui/“
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance“
xsi:schemaLocation=“http://www.blizzard.com/wow/ui/
http://wowprogramming.com/FrameXML/UI.xsd“>
<Button name=“BindingTestButtonTemplate“ inherits= i
“UIPanelButtonTemplate2“ virtual=“true“>
<Size x=“150“ y=“24“/>
<Scripts>
<OnLoad function=“BindingTestButton_OnLoad“/>
<OnClick function=“BindingTestButton_OnClick“/>
<OnEnter function=“BindingTestButton_OnEnter“/>
<OnLeave function=“BindingTestButton_OnLeave“/>
</Scripts>
</Button>
</Ui>
Thetwobuttons willbeidentical in mostrespects,so youdefineatemplate
fromwhich thebuttonswillinherit.The
OnLoad
scriptwillinitializethebutton
with a label and associated binding information based on the button’s ID.
The
OnClick
script will display the bindings frame when clicked, and the
OnEnter
/
OnLeave
scripts will showandhidethe tooltip.
316
Part III
AdvancedAddonTechniques
Createaframetoholdthebuttonsandthebuttonsthemselvesbyaddingthe
followingcode immediatelyafterthetemplatedefinition,withinthe
Ui
tag.
<Frame name=“BindingTestFrame“>
<Size x=“1“ y=“1“/>
<Anchors>
<Anchor point=“CENTER“/>
</Anchors>
<Frames>
<Button name=“BindingTestButton1“ “ i
inherits=“BindingTestButtonTemplate“ id=“1“>
<Anchors>
<Anchor point=“BOTTOM“ relativePoint=“CENTER“/>
</Anchors>
</Button>
<Button name=“BindingTestButton2“ “ i
inherits=“BindingTestButtonTemplate“ id=“2“>
<Anchors>
<Anchor point=“TOP“ relativePoint=“CENTER“/>
</Anchors>
</Button>
</Frames>
</Frame>
The outer frame doesn’t really provide any functionality of its own; it
simply serves to encapsulate the two buttons. If you’d prefernot to have the
buttonsdirectlyin the centerof thescreen,youcananchor
BindingTestFrame
elsewhereandthebuttons willmovewith it.
The buttons themselves are anchored such that one sits directly above the
position of
BindingTestFrame
andtheothersits justbelow.
Finally, you need a frame that can capture keyboard and mouse input so
you can assign the bindings as necessary. You’ll use a button widget to take
advantage of the
OnClick
handler. Start off by creating the basicappearance
ofthe button as follows:
<Button name=“BindingTestCaptureFrame“ hidden=“true“ enableKeyboard= i
“true“ frameStrata=“DIALOG“>
<Size x=“175“ y=“90“/>
<Anchors>
<Anchor point=“CENTER“/>
</Anchors>
<Backdrop bgFile=“Interface\Tooltips\UI-Tooltip-Background“ edgeFile= i
“Interface\Tooltips\UI-Tooltip-Border“ tile=“true“>
Chapter16
Binding Keysand Clicks to AddonCode
317
<EdgeSize val=“16“/>
<TileSize val=“16“/>
<BackgroundInsets left=“5“ right=“5“ top=“5“ bottom=“5“/>
<Color r=“0“ g=“0“ b=“0“/>
</Backdrop>
</Button>
Because this frame pops upin response to clicking oneof the two buttons,
it starts offhidden. As soon as you show the frame itcaptures all keypresses
thankstothe
enableKeyboard
attribute.Thebackdropsection givestheframe
an appearance similar to a tooltip. Next, add a font string immediately after
the
</Backdrop>
tag, but before the
</Button>
tag. This font string will be
usedtodisplayinstructions totheuser.Here’sthecode:
<Layers>
<Layer level=“ARTWORK“>
<FontString inherits=“GameFontNormal“ parentKey=“text“>
<Anchors>
<Anchor point=“TOPLEFT“>
<Offset x=“10“ y=“-10“/>
</Anchor>
<Anchor point=“BOTTOMRIGHT“>
<Offset x=“-10“ y=“10“/>
</Anchor>
</Anchors>
</FontString>
</Layer>
</Layers>
Finally,addthescriptdefinitionsafterthe
</Layers>
tag:
<Scripts>
<OnLoad function=“BindingTestCapture_OnLoad“/>
<OnShow function=“BindingTestCapture_OnShow“/>
<OnKeyDown function=“BindingTestCapture_OnKeyDown“/>
<OnClick function=“BindingTestCapture_OnClick“/>
</Scripts>
The
OnLoad
script initializes the frame. The
OnShow
script changes the text
of the frame to indicate which binding is being changed. The
OnKeyDown
and
OnClick
scripts are used to capture the keyboard and mouse input,
respectively.
Loadthegameatthispointandyou’llseetwoblankbuttons(seeFigure16-6)
in themiddleofthescreen thatdon’tdoanythinginterestingwhenpressed.
318
Part III
AdvancedAddonTechniques
Figure 16-6: Blankbindingtest buttons
Defining Basic Behaviors
Now it’s timeto addthebehaviortoyourUI.Opentheaddon’sLua file ifit’s
notalreadyopen.Aftertheglobal binding labels atthetopofthefile,addthe
followingstrings:
local BUTTON_CAPTION = “Set Test Binding #%d“
local TOOLTIP_TEXT1 = “Left-click to add binding“
local TOOLTIP_TEXT2 = “Right-click to remove first binding“
local TOOLTIP_BINDING_LIST = “Currently bound: |cFFFFFFFF%s|r“
local LIST_SEPARATOR = “|r, |cFFFFFFFF“
local CAPTURE_TEXT = [[
Press a key or click this frame to set test binding #|cFFFFFFFF%d|r.
Press |cFFFFFFFFESC|r to cancel.]]
Thesestrings areusedas follows:
BUTTON_CAPTION
—Thisis the label forthe twomain buttons.
TOOLTIP_xxxx
—Theseare thetextthat appears inthetooltip.
LIST_SEPARATOR
—The‘‘Currentlybound’’sectionofthetooltiplistseach
keyboundtothebutton’sassociatedaction.Thisistheseparatorbetween
itemsin thelist.Notetheuseofcolorcodestomakethekeynamesstand
out.
CAPTURE_TEXT
—Thisisthetextforthecaptureframe.
So you’llbe abletoseetheprogress of your workat each step,create stubs
for all ofthe scripts you defined in the XML by adding thefollowing code to
theendoftheLua file:
function BindingTestButton_OnLoad(self)
end
function BindingTestButton_OnClick(self, button)
end
function BindingTestButton_OnEnter(self)
end
Documents you may be interested
Documents you may be interested