Page 1 of 1 1
Topic Options
#149733 - 2005-10-12 07:54 AM box issues
2manyhats Offline
Fresh Scripter

Registered: 2005-09-07
Posts: 33
I have a textbox with lines of text representing mapped drives in it.
The first line, as an example, can be lined up as such.
Code:
 
at( 7,23) "you are connected to drive p" + chr(10) +


The next 2 lines of code will allow the next line of text to be positioned right underneath the first
Code:

$indent="23 blank spaces"
? + ($indent) + "you are connected to drive q" + chr(10) +



The problem is the text box gets overwritten with clear space by ($indent).
Any ideas or workarounds?

Without the text box I know it would be easy and fundamental but I don't do anything the easy way

Top
#149734 - 2005-10-12 09:35 AM Re: box issues
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Your second line writes over the first line casue you only give a margin from the left.
The code below shows the second line below the first one.

Code:

AT(7,23) "you are connected to drive p"
AT(8,23) + "you are connected to drive q"



Edited by Mart (2005-10-12 09:36 AM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#149735 - 2005-10-12 11:33 AM Re: box issues
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
It's tricky.

I've got a binary somewhere which I wrote to report the current cursor position on the console for exactly this sort of thing.

To be honest, it's usually easier to keep track of the position yourself. The only tricky bit is that you need to deal with lines that wrap.

If you really want to get into managing text windows, I wrote an entire library in KiXtart to allow you to create and destroy windows, complete with up and down scrolling and stuff.

In practice this is probably more than you need, and simply tracking the cursor will do:
Code:
Break ON
$=SetOption("Explicit","ON")

GLOBAL $_CursorY

$_CursorY=7

CLS
udfShowText(23,"First line of text")
udfShowText(23,"Second line of text")
udfShowText(23,"Third line of text")

Function udfShowText($CursorX,$s)
At($_CursorY,$CursorX) $s
$_CursorY=$_CursorY+1
EndFunction



If you want to fully manage independant areas of the console, here is a demo script:
Code:
; vim600:ts=3 sw=3 ai filetype=kix

$=SetOption("Explicit","ON")
$=SetOption("HideCursor","OFF")

CLS

; Pane demo script.
;
; This demo shows two scrolling panes, displaying the contents of the Windows and System 32 directories.
;

Dim $paneWin,$paneSys
Dim $sWinFile, $sSysFile
Dim $iWinPass, $iSysPass

$iWinPass=1
$iSysPass=1

Box(3,9,12,60,"double")
Box(13,9,22,60,"double")
$paneWin=PaneCreate(4,10,8,50)
$paneSys=PaneCreate(14,10,8,50)

At(3,12) "Files present in "+%SYSTEMROOT%
At(13,12) "Files present in "+%SYSTEMROOT%+"\System32"

$sWinFile=Dir(%SYSTEMROOT%,0)
$sSysFile=Dir(%SYSTEMROOT%+"\System32",1)
While Not KBHit()

$paneWin=PaneWrite($paneWin,@CRLF+@TIME+" "+$iWinPass+" "+$sWinFile)
$PaneSys=PaneScrollDown($paneSys)
$paneSys=PaneAt($paneSys,0,0,@TIME+" "+$iSysPass+" "+$sSysFile)
PaneUpdate($paneWin,"w+/n")
PaneUpdate($paneSys,"g+/n")

$sWinFile=Dir("",0)
If @ERROR $iWinPass=$iWinPass+1 $sWinFile=Dir(%SYSTEMROOT%,0) EndIf
$sSysFile=Dir("",1)
If @ERROR $iSysPass=$iSysPass+1 $sSysFile=Dir(%SYSTEMROOT%+"\System32",1) EndIf
Sleep(0.2)
Loop

Get $

Exit 0

; Cut here 8<----------------------------------------------------------------------------------->8
; Begin Pane Functions


Function PaneCreate($iTop, $iLeft, $iHeight, $iWidth)

If Not IsDeclared($_Pane_Top)
Global $_Pane_Top ; Pane position offset from top of console
Global $_Pane_Left ; Pane position offset from left of console
Global $_Pane_Height ; Pane height
Global $_Pane_Width ; Pane width
Global $_Pane_Cursor_X ; Cursor vertical (Row)
Global $_Pane_Cursor_Y ; Cursor horizontal (Column)
Global $_Pane_Blank ; Enough spaces to blank a line
Global $_Pane_Change_X_Low ; First row with a change on it.
Global $_Pane_Change_X_High ; Last row with a change on it.
Global $_Pane_Content ; Actual pane content

$_Pane_Top=0
$_Pane_Left=1
$_Pane_Height=2
$_Pane_Width=3
$_Pane_Cursor_X=4
$_Pane_Cursor_Y=5
$_Pane_Blank=6
$_Pane_Change_X_Low=7
$_Pane_Change_X_High=8
$_Pane_Content=9
EndIf

Dim $P

ReDim $P[$_Pane_Content+1]

$P[$_Pane_Top]=CInt($iTop)
$P[$_Pane_Left]=CInt($iLeft)
$P[$_Pane_Height]=CInt($iHeight)
$P[$_Pane_Width]=CInt($iWidth)
$P[$_Pane_Cursor_X]=0
$P[$_Pane_Cursor_Y]=0
$P[$_Pane_Change_X_Low]=0
$P[$_Pane_Change_X_High]=$iHeight-1
$P[$_Pane_Content]=""

; Create the blank line field
While Len($P[$_Pane_Blank])<$iWidth $P[$_Pane_Blank]=Left($P[$_Pane_Blank]+" ",$P[$_Pane_Width]) Loop
; Blank the pane
While $iHeight $P[$_Pane_Content]=$P[$_Pane_Content]+$P[$_Pane_Blank] $iHeight=$iHeight-1 Loop

$PaneCreate=$P
EndFunction

Function PaneAt($P, $iRow, $iColumn, Optional $sText)
$P[$_Pane_Cursor_X]=CInt($iRow)
$P[$_Pane_Cursor_Y]=CInt($iColumn)
If $sText<>"" $P=PaneWrite($P,$sText) EndIf
$PaneAt=$P
EndFunction

Function PaneWrite($P,$sText)
Dim $X,$Y,$C,$s,$POS

$X=$P[$_Pane_Cursor_X]
$Y=$P[$_Pane_Cursor_Y]
$C=$P[$_Pane_Content]

While $sText<>""
$s=Left($sText,1)
Select
Case $s=Chr(10)
$X=$X+1
If $X=$P[$_Pane_Height]
$X=$X-1
$P[$_Pane_Content]=$C
$P=PaneScrollUp($P)
$C=$P[$_Pane_Content]
EndIf
Case $s=Chr(13)
$Y=0
Case 1
$Y=$Y+1
If $Y=$P[$_Pane_Width]
$Y=0
$sText="X"+Chr(10)+$sText
Else
$POS=$X*$P[$_Pane_Width]+$Y+1
$C=CStr(SubStr($C,1,$POS-1))+$S+SubStr($C,$POS+1)
EndIf
EndSelect
$sText=SubStr($sText,2)
Loop
$P[$_Pane_Cursor_X]=$X
$P[$_Pane_Cursor_Y]=$Y
$P[$_Pane_Content]=$C

$PaneWrite=$P
EndFunction

Function PaneScrollUp($P)
$P[$_Pane_Content]=SubStr($P[$_Pane_Content],$P[$_Pane_Width]+1)+$P[$_Pane_Blank]
$PaneScrollUp=$P
EndFunction

Function PaneScrollDown($P)
$P[$_Pane_Content]=Left($P[$_Pane_Blank]+$P[$_Pane_Content],$P[$_Pane_Width]*$P[$_Pane_Height])
$PaneScrollDown=$P
EndFunction

Function PaneUpdate($P, Optional $sColor)
Dim $sCursorState,$i

$sCursorState=SetOption("HideCursor","ON")
For $i=0 To $P[$_Pane_Height]
If $sColor Color $sColor EndIf
At($P[$_Pane_Top]+$i, $P[$_Pane_Left])
SubStr($P[$_Pane_Content],1+$P[$_Pane_Width]*$i,$P[$_Pane_Width])
Next

At($P[$_Pane_Top]+$P[$_Pane_Cursor_X], $P[$_Pane_Left]+$P[$_Pane_Cursor_y])

$sCursorState=SetOption("HideCursor",$sCursorState)

EndFunction


Top
#149736 - 2005-10-12 04:28 PM Re: box issues
2manyhats Offline
Fresh Scripter

Registered: 2005-09-07
Posts: 33
Mart, you are correct, your example works. But lets say for example that all users can possibly belong to 3 groups for simplicity sake. You only belong to group 1 and 3 but not 2. Membership in each group maps a drive and you want each line to display exactly below the first. It can't be done using "at" for every line being displayed to the screen. You would have something that is kind of ugly. I currently do it the way that you describe. I'm just tired of it looking so ugly.

Thanks for the input, though.
Kevin

Top
#149737 - 2005-10-12 04:37 PM Re: box issues
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Well if you don't want it to be ugly you could use kixforms. It's got a proper GUI instead of a console windows and it has much more configurable options for example for fonts and layout.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#149738 - 2005-10-12 04:51 PM Re: box issues
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
... or use either of the methods I've outlined above.
Top
#149739 - 2005-10-12 05:01 PM Re: box issues
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Like Richard said, just keep track of the y coordinate yourself.

Code:

$cur_y = 7
if ingroup($group1)
;map drive
at($cur_y,23) "Mapped to p drive"
$cur_y = $cur_y+1
endif

if ingroup($group2)
;map drive
at($cur_y,23) "Mapped to q drive"
$cur_y = $cur_y+1
endif
if ingroup($group3)
;map drive
at($cur_y,23) "Mapped to s drive"
$cur_y = $cur_y+1
endif


Top
#149740 - 2005-10-12 05:12 PM Re: box issues
2manyhats Offline
Fresh Scripter

Registered: 2005-09-07
Posts: 33
Richard, it took me a few minutes to digest your function and I am truly impressed! I know it's not a lot of code (referring to the udfshowtext) but it works perfectly. This must be a hidden gem because I didn't see it on the kixtart.org udf page. For anyone concerned about asthetics, this is great! I will try to find time to digest the rest of you code, but I'm not there yet.

Kevin

Top
#149741 - 2005-10-12 05:16 PM Re: box issues
2manyhats Offline
Fresh Scripter

Registered: 2005-09-07
Posts: 33
I also think your right, Mart. Time for me to get out of the stone age and learn something new being, "kixforms". Never even tried. Old habits die hard.

Edited by 2manyhats (2005-10-12 05:25 PM)

Top
#149742 - 2005-10-12 05:21 PM Re: box issues
2manyhats Offline
Fresh Scripter

Registered: 2005-09-07
Posts: 33
Your example makes it look easy. I wish I knew that you could keep track of coordinates long ago. I guess not being a programmer I don't envision all the possabilities out there to do just about anything.
Top
#149743 - 2005-10-13 09:38 AM Re: box issues
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Quote:


....
Time for me to get out of the stone age and learn something new being, "kixforms".
....





Yeah, get out of the dark ages of scripting and move forward the a sunny and bright future by using kixforms. Kixforms.NET is out as an alpha. Sweet stuff.
Shawn, Jooel, Benny69 and friends did some cool things.

Quote:


....
Never even tried. Old habits die hard.
....




LOL, shame on you


Edited by Mart (2005-10-13 09:39 AM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#149744 - 2005-10-13 09:42 AM Re: box issues
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Yeah, take a look over on the KiXforms site for some good information to help get you going.

KiXforms.NET Discussion
http://www.kixforms.org/forum/viewforum.php?f=7&sid=39957fc9874d3087c96d85dc497e306a

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.079 seconds in which 0.048 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org