Jump to content

Text Coordinates


Warrior124

Recommended Posts

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 by hixxy
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...