view orpg/map/_fog.py @ 112:61fc775862f7 alpha

Traipse Alpha 'OpenRPG' {091009-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary: {091006} 00: Adds Bookmarks (Alpha) with cool Smiley Star and Plus Symbol images! 03: Changes made to the map for increased portability. SnowDog has changes planned in Core, though. Added an initial push to the BCG. Not much to see, just shows off how it is re-writing Main code. {091008} 00: Fix to remote admin commands 01: Minor fix to texted based server, works in /System/ folder Some Core changes to gametree to correctly disply Pretty Print, thanks David! {091009} 00: Fix to Splitter Nodes not being created. Plugin Control panel works with images now Fix to massive amounts of images loading; from Core
author sirebral
date Fri, 09 Oct 2009 23:26:21 -0500
parents 4385a7d0efd1
children
line wrap: on
line source

from math import sqrt

import wx

import orpg.dirpath
from orpg.orpgCore import *

from _object import MapObject

class FogLayer(MapObject):
    def __init__(self, canvas):
        MapObject.__init__(self, canvas=canvas)

    def Draw(self, dc):
        path = dc.CreatePath()
        r, g, b = self.RGBHex.rgb_tuple(self.canvas.fogColor)
        if self.canvas.toolWnd.gmToolBar.IsShown():
            brush = wx.Brush(wx.Color(r, g, b, 128))
        else:
            brush = wx.Brush(wx.Color(r, g, b, 255))
        dc.SetBrush(brush)

        self.region = wx.Region(0, 0, self.canvas.size[0]+2, self.canvas.size[1]+2)

        points = []
        lp = 's'
        for point in self.canvas.fogRegion:
            if point == 's' or point == 'h':
                if lp == 's' and len(points) > 0:
                    self.region.XorRegion(wx.RegionFromPoints(points))
                    self.region.SubtractRegion(wx.RegionFromPoints(points))
                elif len(points) > 0:
                    self.region.UnionRegion(wx.RegionFromPoints(points))
                lp = point
                points = []
            else:
                points.append((point.x, point.y))

        if len(points) > 0:
            if lp == 's':
                self.region.XorRegion(wx.RegionFromPoints(points))
                self.region.SubtractRegion(wx.RegionFromPoints(points))
            else:
                self.region.UnionRegion(wx.RegionFromPoints(points))

        dc.ClipRegion(self.region)

        dc.DrawRectangle(0, 0, self.canvas.size[0]+2, self.canvas.size[1]+2)

        dc.SetBrush(wx.NullBrush)

    def OnLeftDown(self, pos):
        self.start = pos
        self.lastPoint = pos
        if self.canvas.toolWnd.currentFog == 'Show':
            self.canvas.fogRegion.append('s')
        else:
            self.canvas.fogRegion.append('h')
        self.canvas.fogRegion.append(pos)

    def OnMotion(self, pos):
        cdc = wx.ClientDC(self.canvas)
        self.canvas.PrepareDC(cdc)

        dc = wx.GraphicsContext.Create(cdc)
        dc.Scale(self.canvas.zoomScale, self.canvas.zoomScale)

        dc.SetPen(wx.WHITE_PEN)

        path = dc.CreatePath()

        xd = (self.lastPoint.x-pos.x)*(self.lastPoint.x-pos.x)
        yd = (self.lastPoint.y-pos.y)*(self.lastPoint.y-pos.y)
        distance = sqrt(xd+yd)

        if distance > 5:
            path.MoveToPoint(self.lastPoint.x, self.lastPoint.y)
            path.AddLineToPoint(pos.x, pos.y)

            self.canvas.fogRegion.append(pos)
            self.lastPoint = pos

        path.CloseSubpath()
        dc.StrokePath(path)

        dc.SetPen(wx.NullPen)

    def OnLeftUp(self, pos):
        self.canvas.fogRegion.append(pos)
        self.canvas.fogRegion.append(self.start)
        self.canvas.UpdateMap()