Skip to content
General IRCd

Text Coordinates

A TG007 community discussion started by Warrior124.

Discussion 11 posts
Page 1 of 1
Open
Topic #8168 · 11 published posts · 3,248 views

Is there anyway of getting the coordinates of a word anywhere in a window? Say you are looking for the word "Test" in a sentence that reads "This is one test in a set of ongoing tests being conducted this week". I need to be able to get the coordinates of the word "Test" on any line, and anywhere the word "Test" appears. Is there anyway of doing this?

I dont think theres anyway you can do that. I think the only way you can do it from a text event would be to evaluate the length of the entire sentence ($1-) and make it look for that word. I've never tried it, but, looking through the helpfile for '$window' returns the following.

$window(N/@name)

Returns properties for a window.

 

Properties: x, y, w, h, dx, dy, dw, dh, bw, bh, mdi, title, state, font, fontsize, logfile, stamp, icon, ontop, type, anysc, wid, cid, hwnd, sbtext, sbcolor, script

 

x,y,w,h return the left, top positions, and the width and height of the window respectively.

dx,dy return the left, top positions of the window relative to the desktop.

dw,dh return the width and height of the text display area.

bw,bh return the width and height of the bitmap for a graphic window.

mdi returns $true if the window is mdi, otherwise returns $false

state returns minimized/maximized/hidden/normal

title returns the text in the titlebar of the window

 

font returns the name of the current font

fontsize returns the size of the current font

fontbold returns $true if the font is bold, otherwise returns $false

logfile returns name of logfile if one is open for the window

stamp returns timestamp setting

icon returns on/off depending on whether icon is visible

ontop returns ontop status for a window

type returns window type

anysc returns $true if the /window -i switch was specified

wid returns the window id

 

cid returns the associated connection id

sbtext returns the switchbar button text

sbcolor returns the switchbar highlight color

script returns the script name of the current font

 

You can also use the format $window(@wildcard,N) which returns the Nth window matching the wildcard window name.

 

Note: You can also get the .w and .h properties by specifying: -1 for the width and height of the screen, -2 for the main mIRC window, and -3 for the MDI window where all other windows inside mIRC are displayed.

Might help, might not.

ty, xfusion. However, it isn't what I'm looking for. I,m wanting to use a picture window where certain text would be replaced with pics. Such as :+) would be replaced with the pic called smile.gif, or something to that point. I know to add a pic inside the picture window you will have to use the /drawpic command. However, with that command you need to specify the coordinates where the pic needs to be drawn.

Then you'd probably have to evaluate $window(@name).h, $window(@name).x, $window(@name).y, $window(@name).w. I haven't played with picwin in that fashion, but, you could probably visit here and they may be able to help you better then us.

I know exactly what you mean Warrior. I actually did it once... How? I have no idea, but I did. This was back when TCN was in operation. Since then I have lost most of my mIRC knowledge. I just know simple stuff now. I don't plan on expanding my knowledge anymore than what it is anyway.

 

I actually did the idea you're working on to make a non-dll powered emoticon chat. Of course I didn't know about buffers back then so everything was slow and I just gave up on it. I couldn't scroll it either, so meh.

 

I wish I could help you more :S I honestly do not know how I did it. :( I wish I knew though... So sorry warrior :(

err0r: 666 + 1337 = 2003 backwards is 3002 which is how many people ozzy has banned from tg
err0r: spooky

lol, np bro. I'll get it figured out... hopefully, lol. :(

Not possible. There's no way of knowing which line is the first visible line in the window.

You can return how many lines are in the window though $line(@windowname,0) :)

Maybe try to use $line(@windowname,0) in association with $(text) ..

I have no idea how to write a code like that, but it may be worth a shot.

Well, it's probably a lengthy process. First, identifying the total lines, then finding the first line, evaluating the rest and looking through the text to find your specified world.

You can return how many lines are in the window though $line(@windowname,0) :)

 

That's not what I meant. I meant that let's say you scroll halfway down a buffer, so the 50th line in the buffer is now the first visible line in the box. There's no way you can find out which line is the first visible one (ie. the first line to appear on the screen, at the top).

 

However, I misunderstood what you were asking. It's 100% possible in picture windows but it'll be a hell of a lot of work. You'll have to make all sorts of $width/$height calculations, as well as adding/subtracting values for padding around the text, etc.

 

You'll have to store all data that you draw onto the window somewhere since mIRC doesn't keep an internal buffer for picture windows. You'll have to store fontname, fontsize, whether it's bold, etc as well, because you're going to have to work out the exact coordinates of each word to do what you want to do.

 

I'll make up a small example that supports only a couple of lines then you might wish to extend it to a full blown buffering system or something.

 

Rather than comment the code (I'm no good at explaining things unless I have a specific question to answer), ask me any questions about the code if you don't understand it.

 

/*

Tell the script how the text will appear.

$bold - specifies whether the text will be bold or not.
$font - returns the font name.
$fontsize - returns the font size.
$leftspacing - returns the number of pixels between the left of the window and the text.
$linespacing - returns the number of pixels between each line.

*/

alias -l bold { return $false }
alias -l font { return courier new }
alias -l fontsize { return 10 }
alias -l leftspacing { return 5 }
alias -l linespacing { return 2 }

alias -l addline { 
  var %i = 1, %y = $linespacing
  while ($hget(hotlinks_buffer,%i) != $null) {
    %y = $calc(%y + $height($v1,$font,$fontsize) + $linespacing)
    inc %i
  }
  drawtext $iif($bold,-o) @hotlinks 1 $qt($font) $fontsize $leftspacing %y $1-
  hadd -m hotlinks_buffer $calc($hget(hotlinks_buffer,0).item + 1) $1-
}
alias -l makebuffer { window -dkp @hotlinks }
alias phe {
  if ($hget(hotlinks_buffer)) { hfree $v1 }
  makebuffer
  addline Hello there,
  addline hover over any of these words and the word you're hovering should echo in the status window.
}

on *:close:@hotlinks:{ 
  if ($hget(hotlinks_buffer)) { hfree $v1 }
}
menu @hotlinks {
  mouse:{
    var %i = 1, %data, %y = $linespacing
    while ($hget(hotlinks_buffer,%i) != $null) {
      %data = $v1
      if ($mouse.y isnum $+(%y,-,$calc(%y + $height(%data,$font,$fontsize)))) { 
        var %g = 1, %x = $leftspacing, %word
        while ($gettok(%data,%g,32) != $null) {
          %word = $v1
          if ($mouse.x isnum $+(%x,-,$calc(%x + $width(%word,$font,$fontsize,$iif($bold,1,0),0)))) {
            echo -a HOVERED WORD: %word ~ COORDS: %x %y
            return
          }
          %x = $calc(%x + $width(%word $+ $chr(32),$font,$fontsize,0,0))
          inc %g
        }
      }
      %y = $calc(%y + $height(%data,$font,$fontsize) + $linespacing)
      inc %i
    }
  }
}

 

Type /phe to run the example.

 

Hover over any word in the window and it should echo in the status window. I know this isn't exactly what you asked for, but the code that finds out exactly where the coordinates of the words you're after is in there, so feel free to use it in your own.

 

Edit: this is an incredibly simple buffering system. It doesn't take scrolling into account (having to use a scrollbar when text overflows), or when text is too wide to fit on one line.

 

You'll have a lot more work to do than this simple example.

Edited Apr 1, 2007 3:06 PM by hixxy