Room drawing script

Post new topic   Reply to topic Script Sharing View previous topic :: View next topic  
Author Message
Scotsman
Site Admin


Joined: 03 Aug 2004
Posts: 705
Location: MadWolf Software

PostPosted: Fri Jul 14, 2006 9:17 pm    Post subject: Room drawing script Reply with quote

Code:
import manor
global draw_on, lines, numLines, remLines, I_Send, red, green, blue
draw_on = 0
numLines = 0
lines = []
remLines = []
I_Send = 0
red = 0
green = 0
blue = 0

class remRecv:
    def __init__(self, userID, lineNum):
        self.userID = userID
        self.lineNum = lineNum
       
class stroke:   
    def __init__(self, red, green, blue, x, y):
        self.red = red
        self.green = green
        self.blue = blue
        self.points = shape()
        self.points.move(x, y)
       
    def point(self, x, y):
        self.points.line(x, y)
   
    def bounds(self):
        return self.points.bounds().inset(-1, -1)
   
    def draw(self, gworld):
        gworld.foreColor(0xFF, self.red, self.green, self.blue)
        self.points.draw(gworld, 0, 0)

def newStroke(userID, data, params):
    global lines, numLines, remLines
   
    r, g, b, x, y = data
    lines.append(stroke(r, g, b, x, y))
    count = 0
    for i in remLines:
        if i.userID == userID:
            del remLines[count]
        count += 1
           
    remLines.append(remRecv(userID, numLines))
    numLines += 1

def newPoint(userID, data, params):
    global lines, remLines
   
    x,y = data
    for i in remLines:
        if i.userID == userID:
            lines[i.lineNum].point(x, y)
            manor.dirtyRect(lines[i.lineNum].bounds())

def fullStroke(userID, data, params):
    global lines, numLines
   
    r, g, b, points = data
    lines.append(stroke(r, g, b, 0, 0))
    lines[numLines].points = shape(points);
    manor.dirtyRect(lines[numLines].bounds())
    numLines += 1;

def clearStrokes(userID, data, params):
    global lines, numLines
   
    for i in lines:
        manor.dirtyRect(i.bounds())
    lines = []
    numLines = 0

def sendStrokes(userID, data, params):
    global lines, I_Send
   
    if I_Send == 1:
        for i in lines:
            manor.sendData("stroke", [userID], [i.red, i.green, i.blue, str(i.points)])
       
def mouseTracker(params):
    global lines, currLine, lx, ly
   
    if manor.stillDown() != 0:
        x,y = manor.getMouseRmPos()
        if x != lx or y != ly:
            lx = x
            ly = y
            lines[currLine].point(x,y)
            manor.broadcastData("point", 0, [x, y])
            manor.dirtyRect(lines[currLine].bounds())
        manor.setTimer(0, mouseTracker, 0)

def mnr_mousedown(x, y):
    global lines, draw_on, currLine, numLines, red, green, blue, lx, ly
   
    handled = 0
    if draw_on == 1:
        lx = x
        ly = y
        lines.append(stroke(red, green, blue, x, y))
        manor.broadcastData("new", 0, [red, green, blue, x, y])
        currLine = numLines
        numLines += 1
        #print x,y
        handled = 1
       
        manor.setTimer(0, mouseTracker, 0)
   
    return handled
   
def mnr_render(gworld, layer):
    global lines
   
    if layer == 2:
        gworld.penSize(2, 2)
        for i in lines:
            i.draw(gworld)
   
    return 0

def mnr_keydown(char, key):
    global draw_on, red, green, blue
   
    handled = 0
    #print key
    if key == 122 or key == 112:
        handled = 1
        if draw_on == 0:
            draw_on = 1
            manor.statusMsg("Draw mode on", 0)
        else:
            manor.statusMsg("", 0)
            draw_on = 0
   
    if draw_on == 1:
        if key == 120 or key == 113:
            red = 0xFF
            green = 0
            blue = 0
            handled = 1

        if key == 99 or key == 114:
            red = 0
            green = 0xFF
            blue = 0
            handled = 1

        if key == 118 or key == 115:
            red = 0
            green = 0
            blue = 0xFF
            handled = 1

        if key == 96 or key == 116:
            red = 0
            green = 0
            blue = 0
            handled = 1
           
    return handled

def mnr_outchat(chatText):
    global lines, numLines
   
    if chatText == "'clean":
        manor.broadcastData("clean", 0, 0)
        for i in lines:
            manor.dirtyRect(i.bounds())
        lines = []
        numLines = 0
   
    return chatText
   
def mnr_enter(userID):
    global I_Send
   
    if userID == manor.myID() or manor.myID() == 0:
        manor.logstr("")
        manor.logstr("Drawing available")
        manor.logstr("")
        manor.logstr("F1 Toggles draw mode on and off")
        manor.logstr("F2 Red pen")
        manor.logstr("F3 Green pen")
        manor.logstr("F4 Blue pen")
        manor.logstr("F5 Black pen")
       
    #print manor.getRoomUserCount()
    if manor.getRoomUserCount() == 1:
        I_Send = 1

def mnr_leave(userID):
    global I_Send
   
    if userID != manor.myID():
        if (manor.getIdxRoomUser(0) == userID and manor.getIdxRoomUser(1) == manor.myID()) or (manor.getIdxRoomUser(0) == manor.myID()):
            I_Send = 1

manor.regDataReceive("new", newStroke, 0)
manor.regDataReceive("point", newPoint, 0)
manor.regDataReceive("stroke", fullStroke, 0)
manor.regDataReceive("reqStroke", sendStrokes, 0)
manor.regDataReceive("clean", clearStrokes, 0)
manor.broadcastData("reqStroke", 0, 0)
Back to top
View user's profile Send private message Visit poster's website
Cheiron



Joined: 21 Apr 2005
Posts: 388
Location: Copenhagen, Denmark

PostPosted: Sun Jul 16, 2006 6:26 am    Post subject: Reply with quote

Thanks for the script, it works good.

However there are two concerns...

1)I dunno if it because of script but the area in manor window around text box and the propchest etc seems to double... like two renderings slightly offset after drawing a while.

2) I had an incident yesterday with a user abusing script and drawing obscene stuff in room. Would it be possible to add to script some sort of way (e.g. a log message) about who is drawing?... I had no way of knowing who did it and innocent people got involved, before I could deduce who did it.

Regards,
Che
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Scotsman
Site Admin


Joined: 03 Aug 2004
Posts: 705
Location: MadWolf Software

PostPosted: Sun Jul 16, 2006 11:25 am    Post subject: Reply with quote

sure, in the newStroke, fullStroke, and clearStroke routines you could add a logmessage for who did it
Back to top
View user's profile Send private message Visit poster's website
LongFang



Joined: 18 Feb 2005
Posts: 124
Location: Rembert SC.

PostPosted: Thu Feb 01, 2007 4:14 am    Post subject: Can this be Done Reply with quote

i have been playing with the room Draw
and im now wondering can this be made to
work in Borgz so thats its ready everwhere?
_________________
Im Not Lost. I know im on Earth

¥£ongFang »W°Ğ°Ğ«
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Scotsman
Site Admin


Joined: 03 Aug 2004
Posts: 705
Location: MadWolf Software

PostPosted: Thu Feb 01, 2007 1:17 pm    Post subject: Reply with quote

Not really. Borgs don't get told what the room graphics world is.
Back to top
View user's profile Send private message Visit poster's website
Cheiron



Joined: 21 Apr 2005
Posts: 388
Location: Copenhagen, Denmark

PostPosted: Mon Feb 05, 2007 6:02 pm    Post subject: Reply with quote

that room drawing script messes up sometimes. For reasons murky to me, suddently it dashes out a line to one of the edges of drawing area, which spoils the whole purpose of it.... no incremental eraser so ... sigh
_________________
Cheiron
______________________________
"Any scientist with respect for himself should start
the day by rejecting his own pet hypotheses".
(Konrad Lorenz)

"Wir müssen wissen
Wir werden wissen"
(David Hilbert)
Back to top
View user's profile Send private message Send e-mail Visit poster's website
LongFang



Joined: 18 Feb 2005
Posts: 124
Location: Rembert SC.

PostPosted: Fri Feb 09, 2007 3:16 pm    Post subject: Found why Reply with quote

I have noticed this as well and played with it
untill I could make it happen
I have found this happens most by having your
Mouse off the Manor Screne and in the Box part of
the program
_________________
Im Not Lost. I know im on Earth

¥£ongFang »W°Ğ°Ğ«
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Cheiron



Joined: 21 Apr 2005
Posts: 388
Location: Copenhagen, Denmark

PostPosted: Sun Feb 11, 2007 5:37 pm    Post subject: Reply with quote

the mouse is for obvious reasons not outside drawing area, since it happens in middle of drawing a line.
_________________
Cheiron
______________________________
"Any scientist with respect for himself should start
the day by rejecting his own pet hypotheses".
(Konrad Lorenz)

"Wir müssen wissen
Wir werden wissen"
(David Hilbert)
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic All times are GMT - 6 Hours
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum