#ATTRCURSORX for Brushes

Discuss any general programming issues here
Post Reply
evil
Posts: 138
Joined: Mon Jun 14, 2010 1:38 pm

#ATTRCURSORX for Brushes

Post by evil » Fri Jan 17, 2020 3:47 pm

Hiho!

When printing directly onto the display, GetAttribute(#Display,id,#ATTRCURSORX) gives me the actual cursor position, where the next text would be printed.
Is there an equivalent for brushes??

User avatar
airsoftsoftwair
Posts: 3359
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: #ATTRCURSORX for Brushes

Post by airsoftsoftwair » Mon Jan 20, 2020 11:22 pm

You mean when using SelectBrush() mode?

evil
Posts: 138
Joined: Mon Jun 14, 2010 1:38 pm

Re: #ATTRCURSORX for Brushes

Post by evil » Tue Jan 21, 2020 12:44 am

Correct.

I create a brush, select it and print some text in it. Afterwards I need the actual cursor-position inside the brush.
It must be set somewhere, because when printing more text into the brush, It will be printed right after the first text...

User avatar
airsoftsoftwair
Posts: 3359
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: #ATTRCURSORX for Brushes

Post by airsoftsoftwair » Tue Jan 21, 2020 10:10 pm

Ok, so the way this works is that the cursor position is always reset to 0:0 when calling SelectBrush(). When calling EndSelect(), the old cursor position is restored. Maintaining an individual cursor position for every brush is probably overkill but you could easily stuff this into into your brush objects using SetObjectData(), e.g.

Code: Select all

; use this instead of SelectBrush()
Function p_MySelectBrush(id)
     Local cursor_x = GetObjectData(#BRUSH, id, "cursor_x")
     Local cursor_y = GetObjectData(#BRUSH, id, "cursor_y")
     SelectBrush(id)
     Locate(cursor_x, cursor_y)
EndFunction

; use this instead of EndSelect()
Function p_MyEndSelectBrush(id)
    Local cursor_x = GetAttribute(#DISPLAY, 0, #ATTRCURSORX)
    Local cursor_y = GetAttribute(#DISPLAY, 0, #ATTRCURSORY)
    SetObjectData(#BRUSH, id, "cursor_x", cursor_x)
    SetObjectData(#BRUSH, id, "cursor_y", cursor_y)
    EndSelect
EndFunction

evil
Posts: 138
Joined: Mon Jun 14, 2010 1:38 pm

Re: #ATTRCURSORX for Brushes

Post by evil » Tue Jan 21, 2020 11:55 pm

Cool! That helps a lot!

Thanks for the hint

Best regards

George!

Post Reply