The Moving Toolbar

Contributed by [AFX]

The Moving Toolbar

1. Introduction

OK, so you want to know how to make a draggable toolbar? Well, it isn't as hard as you might think it is, it just requires some common sense and knowledge of scripting. In this small, brief tutorial, I will try to explain how to accomplish this, but of course you will have to pay attention to what I am trying to explain.

For this, you will need (stated above) to know some advanced scripting (some $gettok and $calc), and you will need Dragonzaps' MDX.dll, Bars.mdx and Ctl_gen.mdx for the toolbar movement. If you can't find this DLL, you can scroll to the bottom of this file and find the link there.

2. Moving On (An example)

For this, I am going to use an example to show you how this is done. The reason is, because I had a hard time porting this to a snippet (and I was kind of lazy), so if I use this example, you should be able to understand more and possibly develop furthur on this idea.

First and foremost, a dialog table is needed. We will generate a simple table that consists of a listbox, a box, and 2 button controls. Why 2 buttons? You will understand why later in the tutorial.

dialog tb {
  title ""
  size -1 -1 35000 3
  option dbu
  list 1, 6 2 126 12, size
  box "", 2, -2 -3 35000 19
  button "", 3, 3 2 2 11
  button "", 4, 1 2 2 11,
}

OK. We have our dialog table with the listbox, box, and 2 buttons, but we aren't done! So you can guess what is next: the dialogs' INIT event of course. In this event, we will call the most important dialog necessities here, for example, making one of the buttons a Divider control, and the other the actual toolbar.

For tutorial reasons, we will assume your mIRC directory is C:\mIRC, and the path to MDX.dll/Bars.mdx/Ctl_gen.mdx will be right in the directory itself (in C:\mIRC). We are also going to use this alias to call it every time we need to use it, along with the Bars.mdx and Ctl_gen.mdx files that comes with the DLL.

alias mdx { dll $shortfn($mircdirMDX.dll) $1- }
alias bars { return $shortfn($mircdirBars.mdx) }
alias ctl { return $shortfn($mircdirCtl_gen.mdx) }

NOTE: MDX is used here, so if you haven't gotten the DLL yet, I advise you do.

on *:dialog:tb:init:0: {
  mdx MarkDialog $dname
  mdx SetControlMDX $dname 1 ToolBar list wrap flat arrows nodivider > $bars
  mdx SetControlMDX $dname 3 Divider vertical > $ctl
  mdx SetDialog $dname style
  mdx SetBorderStyle $dname 1

  ;you don't have to have this, this is just an example for the toolbar
  ;feel free to add your own icons and what not
  did -i $dname 1 1 bmpsize 16 16
  did -i $dname 1 1 setimage icon small $ico(Connect)
  did -i $dname 1 1 setimage icon small $ico(Disconnect)
  did -i $dname 1 1 setimage icon small $ico(Setup)
  did -i $dname 1 1 setimage icon small $ico(Servers)
  did -i $dname 1 1 setimage icon small $ico(DCCTransfers)
  did -a $dname 1 +av 1 $chr(9) $+ Connect
  did -a $dname 1 -
  did -a $dname 1 +a 3 $chr(9) $+ Setup
  did -a $dname 1 +a 4 $chr(9) $+ Network Settings
  did -a $dname 1 +a 5 $chr(9) $+ DCC Transfers
}

3. The Moving Toolbar in Action

Allright! So we have the toolbar scripting done, and have our proper controls set. So now you ask: how do we make it move?. Well, this is what this section covers. $gettok and $calc are used here, so be aware some knowledge on those 2 identifiers are needed in order for this to work proper.

Back in Step 1, I said we needed 2 button controls, and here is why. When you have a divider control present on a button, the button disappears, but you can still select the divider and move it around. Well, one of the buttons is going to be the actual mover, and the other button is going to be a dummy one, that has no scripting in it what so ever. It will actually be the "real" button that will be moving both the listbox (now Toolbar) and the "dummy" button.

So, now we must script a working sclick for the "real" button, so that it moves the bar and "dummy" button, so as follows:

on *:dialog:tb:sclick:3: {
    if ($gettok($did($dname,3),1,32) = move) {
    ;the "dummy" button
    mdx MoveControl $dname 4 $gettok($did($dname,6),3,32) 4 4 22
    ;the Toolbar control
    mdx MoveControl $dname 1 $calc($gettok($did($dname,6),3,32) +9) 4 249 24
    did -f $dname 4
  }
}

And we are done! Now, for some explanation on the code:

Line 1: checks if the Divider is being or is ready to be moved Line 2: moves the "dummy" button to the proper place when dragging Line 3: moves the Toolbar control to the proper place when dragging Line 4: sets focus to the "dummy" button after (in case the button looks funny, it will return to its normal look after. I have only had this problem on 1 computer.)

On line 2, the $gettok that is being used refers to the x co-ordinates the "dummy" button is being moved to. On line 3, the $calc + $gettok combination that is being used refers to x co-ordinates the Toolbar control is being moved to.

If you noticed in line 3 why $calc is being used, it is to maintain the position of the Toolbar control to match its' exact position when the original dialog table is first called, therefore it will look exactly like it did when you first saw it, except it is moveable, and keeping its original position from the "dummy" button.

The last 2 values on line 3 refer to the Toolbars' width and height. When using the MoveControl command, you usually have to multiply the original dialog id's x/y/w/h values by 2 to retain their actual look and such. You may change these to any values you wish to fit your script.

4. Completion/Summary

That ends my tutorial now, and that is how you make a draggable toolbar! It doesn't have to just be a Toolbar control your moving, you can move anything you wish, as long as you follow the guidelines I have talked about. Once you have fully understand these, then I am sure you will have no problems doing this at all. Thanks for reading my tutorial, I hope it served it's purpose in helping you understand how it works. See you next time.

Contact Info

Website: www.merkFXscript.n3.net Email: [email protected] IRC: [AFX] on irc.dal.net:6667 in #clan-x-scripterz

MDX.dll and other components can be found Here

All content is copyright by mircscripts.org and cannot be used without permission. For more details, click here.