Skip to content
Snippets Groups Projects
map.py 39 KiB
Newer Older
  • Learn to ignore specific revisions
  •     if not Map.action == 'PAN':
            x = Map.mouse.x
            y = Map.mouse.y
            if x < theMap.origin.x or x > theMap.origin.x + theMap.width:
                crossChange = False
                x = 0
            else:
                testBoundary = theMap.origin.x + theMap.width
                if testBoundary < Map.region.width:
                    rightBoundary = testBoundary
                else:
                    rightBoundary = Map.region.width
                if x > rightBoundary:
                    crossChange = False
                    x = rightBoundary
            cX = x - zLong - theMap.origin.x
    
            if longFac:
                newLongitude = cX / longFac
            else:
                newLongitude = 0.0
    
            if y < theMap.origin.y or y < 0:
                crossChange = False
                y = 0
            elif y > theMap.origin.y + theMap.height:
                crossChange = False
                y = theMap.origin.y + theMap.height
            cY = y - zLat - theMap.origin.y
    
            if latFac:
                newLatitude = cY / latFac
            else:
                newLatitude = 0.0
    
            if newLatitude == Map.latitude and newLongitude == Map.longitude:
                crossChange = False
            else:
                Map.latitude = newLatitude
                Map.longitude = newLongitude
        else:
            if Map.grab.offset.x < Map.grab.spot.x:
                off = Map.grab.spot.x - Map.grab.offset.x
                theMap.origin.x -= off
            else:
                off = Map.grab.offset.x - Map.grab.spot.x
                theMap.origin.x += off
            if Map.grab.offset.y < Map.grab.spot.y:
                off = Map.grab.spot.y - Map.grab.offset.y
                theMap.origin.y -= off
            else:
                off = Map.grab.offset.y - Map.grab.spot.y
                theMap.origin.y += off
            Map.grab.spot.x = Map.mouse.x
            Map.grab.spot.y = Map.mouse.y
    
        Lx = theMap.origin.x
        Ly = theMap.origin.y
    
        # ---------------------
        # Draw a textured quad
        # ---------------------
    
        if not Map.textureless:
            bgl.glEnable(bgl.GL_BLEND)
            if Map.glImage.bindcode == 0:
                Map.load_gl_image()
            bgl.glBindTexture(bgl.GL_TEXTURE_2D, Map.glImage.bindcode[0])
            bgl.glEnable(bgl.GL_TEXTURE_2D)
            bgl.glColor4f(1.0, 1.0, 1.0, Map.object[0].opacity)
            bgl.glBegin(bgl.GL_QUADS)
            bgl.glTexCoord2f(0.0, 0.0)
            bgl.glVertex2f(Lx, Ly)
            bgl.glTexCoord2f(1.0, 0.0)
            bgl.glVertex2f(Lx + theMap.width, Ly)
            bgl.glTexCoord2f(1.0, 1.0)
            bgl.glVertex2f(Lx + theMap.width, Ly + theMap.height)
            bgl.glTexCoord2f(0.0, 1.0)
            bgl.glVertex2f(Lx, theMap.height + Ly)
            bgl.glEnd()
            bgl.glDisable(bgl.GL_TEXTURE_2D)
    
        # -----------------------
        # Output text for stats
        # -----------------------
        if Map.action == 'TIME' or Map.action == 'DAY' or Map.showInfo:
            Map.show_text_in_viewport(Map.object[1])
    
        # ---------------------
        # draw the crosshair
        # ---------------------
        x = theMap.width / 2.0
        if crossChange and not Map.lockCrosshair:
            if Map.action != 'Y':
                Sun.SP.Longitude = newLongitude
        longitude = (Sun.SP.Longitude * x / 180.0) + x
    
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glEnable(bgl.GL_LINES)
        bgl.glLineWidth(1.0)
        alpha = 1.0 if Map.action == 'Y' else 0.5
        color = (0.894, 0.741, .510, alpha)
        bgl.glColor4f(color[0], color[1], color[2], color[3])
        bgl.glBegin(bgl.GL_LINES)
        bgl.glVertex2f(Lx + longitude, Ly)
        bgl.glVertex2f(Lx + longitude, Ly + theMap.height)
        bgl.glEnd()
    
        y = theMap.height / 2.0
        if crossChange and not Map.lockCrosshair:
            if Map.action != 'X':
                Sun.SP.Latitude = newLatitude
        latitude = (Sun.SP.Latitude * y / 90.0) + y
    
        alpha = 1.0 if Map.action == 'X' else 0.5
        color = (0.894, 0.741, .510, alpha)
        bgl.glColor4f(color[0], color[1], color[2], color[3])
        bgl.glBegin(bgl.GL_LINES)
        bgl.glVertex2f(Lx, Ly + latitude)
        bgl.glVertex2f(Lx + theMap.width, Ly + latitude)
        bgl.glEnd()
    
        # ---------------------
        # draw the border
        # ---------------------
        bgl.glDisable(bgl.GL_BLEND)
        color = (0.6, 0.6, .6, 1.0)
        bgl.glColor4f(color[0], color[1], color[2], color[3])
        bgl.glBegin(bgl.GL_LINE_LOOP)
        bgl.glVertex2f(Lx, Ly)
        bgl.glVertex2f(Lx + theMap.width, Ly)
        bgl.glVertex2f(Lx + theMap.width, Ly + theMap.height)
        bgl.glVertex2f(Lx, theMap.height + Ly)
        bgl.glVertex2f(Lx, Ly)
        bgl.glEnd()
    
        if not Sun.ShowRiseSet or not Map.lineWidth:
            bgl.glDisable(bgl.GL_LINES)
            bgl.glFlush()
            return
    
        if Map.action == 'G':
            draw_text_region()
    
        # ------------------------
        # draw the sunrise, sunset
        # ------------------------
    
        def draw_angled_line(color, angle, bx, by):
            x = math.cos(angle) * radius
            y = math.sin(angle) * radius
            bgl.glColor4f(color[0], color[1], color[2], color[3])
            bgl.glBegin(bgl.GL_LINES)
            bgl.glVertex2f(bx, by)
            bgl.glVertex2f(bx + x, by + y)
            bgl.glEnd()
    
        px = Lx + longitude
        py = Ly + latitude
    
        radius = 30 + Map.lineWidth * 10
        if Sun.RiseSetOK and Map.lineWidth:
            color = (0.2, 0.6, 1.0, 0.9)
            angle = -(degToRad(Sun.Sunrise.azimuth) - math.pi / 2)
            bgl.glLineWidth(Map.lineWidth)
            draw_angled_line(color, angle, px, py)
    
            color = (0.86, 0.18, 0.18, 0.9)
            angle = -(degToRad(Sun.Sunset.azimuth) - math.pi / 2)
            draw_angled_line(color, angle, px, py)
    
        # ------------------------
        # draw current time line
        # ------------------------
    
        if Map.textureless:
            phi = degToRad(Sun.AzNorth) * -1
        else:
            phi = degToRad(Sun.Azimuth) * -1
        x = math.sin(phi) * math.sin(-Sun.Theta) * (radius + 10)
        y = math.sin(Sun.Theta) * math.cos(phi) * (radius + 10)
        night = (0.24, 0.29, 0.94, 0.9)
        day = (0.85, 0.77, 0.60, 0.9)
        if Sun.SolarNoon.elevation < 0.0:
            color = night
        elif Sun.Elevation >= Sun.Sunrise.elevation:
            if Sun.Time >= Sun.Sunset.time and \
                    Sun.Elevation <= Sun.Sunset.elevation:
                color = night
            else:
                color = day
        else:
            color = night
        bgl.glLineWidth(Map.lineWidth + 1.0)
    
        bgl.glColor4f(color[0], color[1], color[2], color[3])
        bgl.glBegin(bgl.GL_LINES)
        bgl.glVertex2f(px, py)
        bgl.glVertex2f(px + x, py + y)
        bgl.glEnd()
        bgl.glLineWidth(1.0)
        bgl.glDisable(bgl.GL_LINES)
        bgl.glFlush()
    
    # ---------------------------------------------------------------------------
    
    
    def draw_text_region():
        x = Map.object[1].origin.x
        y = Map.object[1].origin.y - 5
    
        bgl.glEnable(bgl.GL_BLEND)
        color = (0.894, 0.741, .510, 0.2)
        bgl.glColor4f(color[0], color[1], color[2], color[3])
        bgl.glBegin(bgl.GL_QUADS)
        bgl.glVertex2f(x, y)
        bgl.glVertex2f(x + Map.object[1].width, y)
        bgl.glVertex2f(x + Map.object[1].width, y + Map.object[1].height)
        bgl.glVertex2f(x, Map.object[1].height + y)
        bgl.glEnd()
        bgl.glDisable(bgl.GL_BLEND)
    
    
    # ---------------------------------------------------------------------------
    
    
    class SunPos_Help(bpy.types.Operator):
        bl_idname = "object.help_operator"
        bl_label = "Map help"
    
        def execute(self, context):
            self.report({'INFO'}, self.message)
            return {'FINISHED'}
    
        def invoke(self, context, event):
            wm = context.window_manager
            return wm.invoke_popup(self, width=400, height=200)
    
        def draw(self, context):
    
            self.layout.label(text="Available map commands:")
    
    
            row = self.layout.row()
            split = row.split(percentage=.27)
            colL = split.column()
            colR = split.column()
    
            colL.label(text="Esc or Right Mouse ")
    
            colR.label("Close map or text.")
    
            colL.label(text="Left Mouse")
            colR.label(text="Move crosshair.")
            colL.label(text="G or MiddleMouse")
    
            colR.label("Pan mode. Grab and move map or text.")
    
            colL.label(text="Ctrl Middlemouse")
            colR.label(text="Mouse zoom to point.")
            colL.label(text="C")
    
            colR.label("Invert text color.")
    
            colL.label(text="R")
            colR.label(text="Toggle through thickness of the radiating rise/set lines.")
            colL.label(text="S")
            colR.label(text="Show statistics data. Move with pan command.")
    
            self.layout.label("----- The following are changed by moving " +
                              "the mouse or using the scroll wheel.")
    
            self.layout.label(text="----- Use Ctrl for coarse increments or Alt for fine.")
    
            row = self.layout.row()
            split = row.split(percentage=.25)
            colL = split.column()
            colR = split.column()
    
            colL.label(text="Scroll wheel")
            colR.label(text="Zoom to point.")
            colL.label(text="T")
            colR.label(text="Time mode.")
            colL.label(text="D")
            colR.label(text="Day mode.")
            colL.label(text="O")
            colR.label(text="Change map opacity.")
            colL.label(text="X")
            colR.label(text="Lock latitude and change longitude.")
            colL.label(text="Y")
            colR.label(text="Lock longitude and change latitude.")
            colL.label(text="A")
            colR.label(text="Show analemma if object group is set.")
            colL.label(text="E")
            colR.label(text="Show ecliptic if object group is set.")