size_down_tool = ("sizedown",2,179,37,205)
tools.append(size_down_tool)
size_up_tool = ("sizeup",151,170,172,206)
tools.append(size_up_tool)
move_up_tool = ("moveup",109,239,132,255)
tools.append(move_up_tool)
move_down_tool = ("movedown",106,272,134,295)
tools.append(move_down_tool)
move_left_tool = ("moveleft",84,252,108,274)
tools.append(move_left_tool)
move_right_tool = ("moveright",135,252,157,276)
tools.append(move_right_tool)
color_picker_tool = ("pickcolor",9,407,183,550)
tools.append(color_picker_tool)
close_dialog_tool = ("closedialog",676,293,699,320)
tools.append(close_dialog_tool)
#load the loaddialog image
loadimg = pygame.image.load("loaddialog.png").convert()
loadimgrect = loadimg.get_rect()
#load the savedialog image
saveimg = pygame.image.load("savedialog.png").convert()
saveimgrect = saveimg.get_rect()
#load the toolbar image
toolbar = pygame.image.load("toolbar.png").convert()
toolbarrect = toolbar.get_rect()
#load the hand cursor
cursor_hand = pygame.image.load("cursor-hand.png").convert()
cursor_handrect = cursor_hand.get_rect()
cursor_hand_alphakey = cursor_hand.get_at((0, 0)) #get picel at 1,1
cursor_hand.set_colorkey(cursor_hand_alphakey) #set image transparency
#setup cursor data
cursors = []
cursor = (0,cursor_hand,cursor_handrect,(6,1)) #cursor_id,image,rect,hot-spot
cursors.append(cursor)
current_cursor = cursors[0] #default pointing hand cursor
#display the toolbar
screen.blit (toolbar, (0,0))
#hide the normal mouse cursor
pygame.mouse.set_visible(False)
#function to replace all text in a string
def replaceall(s,s1,s2):
ss = s
p = string.find(ss,s1)
while p > -1:
p = string.find(ss,s1)
if p < 0:
break
ss = ss[:p]+s2+ss[p+len(s1):]
p = string.find(ss,s1)
return ss
#function to display the current cursor
def show_cursor(cursor):
#dont draw cursor if mouse is outside window
if mouseY < 3 or mouseX < 3:
return
cursor_id = cursor[0]
cursor_image = cursor[1]
cursor_rect = cursor[2]
cursor_hotspot = cursor[3]
screen.blit(cursor_image,(mouseX,mouseY))
#Sets and returns the current tool
def gettool():
for tool in tools:
toolname,x1,y1,x2,y2 = tool
if mouseX >= x1 and mouseX <= x2 and mouseY >= y1 and mouseY <= y2:
return toolname
return None
#create a new drawing subsurface because we moved the background image
def new_draw_surface():
global drawimg
global drawclip
global imgoffset
global bgimage
global drawcliprect
rect = bgimage.get_rect()
x,y = imgoffset
x1,y1,x2,y2 = rect
w = x2+x
h = y2+y
if w > 600:
w = 600
if h > 600:
h = 600
x = abs(x)
y = abs(y)
if bgimage:
drawclip = drawimg.subsurface((x,y,w,h))
drawcliprect = drawclip.get_rect()
#function to do the actual painting
def paint():
global drawimg
global drawclip
global toolimg
global imgoffset
global toolsize
x,y = imgoffset
xpos = mouseX - int(toolsize/2) -200
ypos = mouseY - int(toolsize/2)
if drawimg and not spacetoggle:
drawclip.blit(toolimg,(xpos,ypos))
#show tool
show_tool()
#finally display the current cursor
show_cursor(current_cursor)
#display all
pygame.display.flip()