Newer
Older
if Map.toolProps is not None:
if Map.toolProps.width < Map.toolProps_width:
theMap.origin.x += diff
Map.toolProps_width = Map.toolProps.width
theMap.set_dimensions(theMap.width)
Map.saved_region_width = Map.region.width
# Latitude and longitude are set to an equidistant
# cylindrical projection with lat/long 0/0 exactly
# in the middle of the image.
zLong = the_map.width / 2
longFac = z_long / 180
zLat = the_map.height / 2
latFac = z_lat / 90
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
crossChange = True
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
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
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:
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
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 = -(radians(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 = -(radians(sun.sunset.azimuth) - math.pi / 2)
draw_angled_line(color, angle, px, py)
# ------------------------
# draw current time line
# ------------------------
if Map.textureless:
phi = radians(sun.AzNorth) * -1
else:
phi = radians(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:
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
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()
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(text="Pan mode. Grab and move map or text.")
colL.label(text="Ctrl Middlemouse")
colR.label(text="Mouse zoom to point.")
colL.label(text="C")
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(text="----- 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()
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.")