mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2002
Posts: 252
T
Talon Offline OP
Fjord artisan
OP Offline
Fjord artisan
T
Joined: Dec 2002
Posts: 252
working on a picwin script, I have an area I've designated to text. This needs to fit a certain Width and Height.

In order to achieve what you'd expect from a common non-picture window, you have to use $wrap(text,font,size,width,N) where N = 0 is total number of wraps to achieve fitting the string within those bounds. if N is non-zero, it returns the Nth segment of text that will fit within the specified width.

This does work perfect, however, there is no control code backlog, so something like "[k]4really long line" will return lines with N > 1 without prefixing it with whatever control codes remained activated during the previous break calculation.

This results in broken output, when trying to duplicate how /echo behaves.

this is an example of
what would happen if
this is where lines
were broken.

Here is a very simplistic example to create a relatively small window and illustrate this.

Just enter whatever you want as a test into the editbox (ensuring it would force a wrap) include control codes, and notice that new wrap positions aren't given old control code states to keep the line going as expected.

If this isn't a bug, then it'd be a nice feature suggestion to add a .prop for this feature let's say $wrap().cc for instance smile

Code:
alias WrapBug { window -dpfe @WrapBug -1 -1 320 240 }
on *:input:@WrapBug: {
  var %a = @WrapBug , %w = $window(@WrapBug).dw , %h = $window(@WrapBug).dh
  var %x = 0 , %y = $wrap($1-,$window(%a).font,$window(%a).fontsize,%w,0) , %height = $height($1-,$window(%a).font,$window(%a).fontsize)
  while (%x < %y) {
    inc %x
    drawscroll -n %a 0 $calc(%height * -1) 0 0 %w %h
    drawrect -nf %a $color(background) 1 0 $calc(%h - %height) %w %height
    drawtext -np %a $color(normal) 0 $calc(%h - %height) $wrap($1-,$window(%a).font,$window(%a).fontsize,%w,%x)
  }
  drawdot %a
}


Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
This is probably not a bug as it has worked this way for so long, I even found a suggestion for it.

I agree mIRC should provide a way to make this easier, but it can be scripted with the $controlat() identifier, which would also be very nice to see, maybe it could even suffice to work around this problem:


Code:
alias picwinchat {
  var %x 50,%y 50,%w 300,%h 300
  window -BfdpC @chat -1 -1 400 400
  ;make the window full white
  drawrect -fr @chat 16777215 0 0 0 400 400
  drawrect -r @chat 0 0 %x %y %w %h
  ;we substract 10 to the real width because we will use a 5 pixel margin on both left/right
  var %n $wrap($1-,verdana,10,$calc(%w - 10),1,0)
  ;the margin
  var %xstart %x + 5 ,%ystart %y + 5,%a 1,%pos 0
  while (%a <= %n) {
    drawtext -rp @chat 0 verdana 10 %xstart %ystart %ctrlcode $+ $wrap($1-,verdana,10,$calc(%w - 10),1,%a)
    inc %pos $len($wrap($1-,verdana,10,$calc(%w - 10),1,%a))
    var %ctrlcode $controlat($1-,%pos)
    inc %a
    inc %ystart 20
  }
} 
type "/picwinchat 04,13test this is a very long text ok some more 07,01word please ok this is enough to illustrate the example i think maybe not" to test it out


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2002
Posts: 252
T
Talon Offline OP
Fjord artisan
OP Offline
Fjord artisan
T
Joined: Dec 2002
Posts: 252
I tried out your $controlat identifier, It seems to be more complex than needed for this situation and leaves a bunch of global variables. It's also rather quite slow since it's re-calculating every time off of $1-.

I had already come up with a solution to this for a temporary fix (or permanent if this isn't deemed a bug, or $wrap().cc feature doesn't get added) which basically just backlogs the state of each control code within each return of $wrap() and sets them locally, and prepends each line with what control codes remained active.

Here's the modified version:

Code:
alias WrapBug { window -dpfe @WrapBug -1 -1 320 240 }
on *:input:@WrapBug: {
  var %a = @WrapBug , %w = $window(@WrapBug).dw , %h = $window(@WrapBug).dh
  var %x = 0 , %y = $wrap($1-,$window(%a).font,$window(%a).fontsize,%w,0) , %height = $height($1-,$window(%a).font,$window(%a).fontsize)
  var %b = 0 , %u = 0 , %r = 0 , %i = 0 , %bg = -1 , %fg = -1 
  while (%x < %y) {
    inc %x
    var %t = $wrap($1-,$window(%a).font,$window(%a).fontsize,%w,%x)
    drawscroll -n %a 0 $calc(%height * -1) 0 0 %w %h
    drawrect -nf %a $color(background) 1 0 $calc(%h - %height) %w %height
    var %pre = $+($iif(%b,$chr(2)),$iif(%u,$chr(31)),$iif(%r,$chr(22)),$iif(%i,$chr(29)),$iif(%bg > -1 && %fg > -1,$+($chr(3),%fg,$chr(44),%bg),$iif(%fg > -1,$+($chr(3),%fg))))
    drawtext -np %a $color(normal) 0 $calc(%h - %height) %pre $+ %t
    if ($regex(CC,%t,/(\x03(?:(?:\d\d?)\x2c)?(?:\d\d?)|[\x02\x1f\x16\x03\x1d\x0f])/g)) {
      var %x1 = 0 , %y1 = $v1
      while (%x1 < %y1) {
        inc %x1
        var %cc = $regml(CC,%x1)
        if (%cc = $chr(3)) { var %bg = -1 , %fg = -1 }
        elseif (%cc = $chr(2)) { var %b = $xor(%b,1) }
        elseif (%cc = $chr(31)) { var %u = $xor(%u,1) }
        elseif (%cc = $chr(22)) { var %r = $xor(%r,1) }
        elseif (%cc = $chr(29)) { var %i = $xor(%i,1) }
        elseif (%cc = $chr(15)) { var %b = 0 , %u = 0 , %r = 0 , %i = 0 , %bg = -1 , %fg = -1 }
        else {
          if ($regex(%cc,/^\x03(\d\d?)$/)) { var %fg = $regml(1) }
          elseif ($regex(%cc,/^\x03(\d\d?)\x2c(\d\d?)$/)) { var %fg = $regml(1) , %bg = $regml(2) }
        }
      }
    }
  }
  drawdot %a
}

Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
$controlat is just the idea, of course it's possible to optimize it the way you did.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard