def render_item_shadows(itemdata, front=False, back=True): Render.get().standard_perspective() # glEnable(GL_STENCIL_TEST) # glStencilFunc(GL_EQUAL, 1, 1) if front: gl.glPolygonOffset(0.0, -4.0) gl.glEnable(gl.GL_POLYGON_OFFSET_FILL) elif back: gl.glPolygonOffset(0.0, 4.0) gl.glEnable(gl.GL_POLYGON_OFFSET_FILL) gl.glDepthMask(False) fs_emu_blending(True) fs_emu_texturing(True) gl.glBindTexture(gl.GL_TEXTURE_2D, Texture.shadow2) for type_, menu, item_index, pos, rotation, scale, ratio, brightness, \ area in reversed(itemdata): gl.glPushMatrix() gl.glTranslate(*pos) gl.glRotate(rotation, 0.0, 1.0, 0.0) gl.glScalef(scale, scale, 1.0) render_item_shadow(ratio=ratio, brightness=brightness, area=area) gl.glScalef(1.0, -1.0, 1.0) gl.glTranslatef(0.0, 0.5, 0.0) # render_item_shadow(ratio=ratio, # brightness=brightness * 0.33, area=area) render_item_shadow(ratio=ratio, brightness=brightness, area=area) gl.glPopMatrix() gl.glPolygonOffset(0.0, 0.0) gl.glDisable(gl.GL_POLYGON_OFFSET_FILL) gl.glDepthMask(True)
def render_top(): Render.get().hd_perspective() gl.glPushMatrix() transition = State.get().current_menu.top_menu_transition gl.glTranslate(0.0, (1.0 - transition) * 90, 0.9) gl.glTranslate(0.0, 0.0, 0.05) if State.get().top_menu == State.get().navigatable: selected_index = State.get().top_menu.get_selected_index() else: selected_index = -1 x = State.get().gl_left for item in State.get().top_menu.left: item.update_size_left() item.x = x item.y = 1080 - TOP_HEIGHT item.h = TOP_HEIGHT x += item.w index = len(State.get().top_menu.left) - 1 for item in reversed(State.get().top_menu.left): item.render_top_left(selected=(index == selected_index)) index -= 1 index = len(State.get().top_menu) - 1 x = State.get().gl_right for item in reversed(State.get().top_menu.right): item.update_size_right() x -= item.w item.x = x item.y = 1080 - TOP_HEIGHT item.h = TOP_HEIGHT if Mouse.focus: selected = (Mouse.focus == item) else: selected = (index == selected_index) item.render_top_right(selected=selected) Mouse.items.append(item) index -= 1 gl.glPopMatrix()
def render(self, transition=1.0): Render.get().hd_perspective() # w = 560 # h = 92 # x = 1920 - w * transition # y = 1080 - 60 - h # y = 1080 - 60 - h - 44 # z = -0.9 # item_top = 1080 - 90 - 50 # item_left = 1920 - 560 + 40 dx = Texture.sidebar_background_shadow.w * (1.0 - transition) gl.glPushMatrix() gl.glTranslate(0.0, 0.0, 0.7) # glTranslated((1.0 - transition) * g_tex_sidebar_background->width, # 0, 0) # fs_emu_set_texture(g_tex_sidebar_background) # fs_emu_render_texture_with_size(g_tex_sidebar_background, # 1920 - g_tex_sidebar_background->width, # 0, g_tex_sidebar_background->width, # g_tex_sidebar_background->height) # fs_emu_render_sidebar() fs_emu_blending(True) fs_emu_texturing(True) gl.glDepthMask(False) Texture.sidebar_background_shadow.render( 1920 - Texture.sidebar_background_shadow.w * transition, 0, Texture.sidebar_background_shadow.w, Texture.sidebar_background_shadow.h, ) if transition > 1.0: padding = 1920 Texture.sidebar_background.render( 1920 - Texture.sidebar_background_shadow.w * transition + Texture.sidebar_background_shadow.w, 0, 1920 + padding, Texture.sidebar_background.h, ) gl.glDepthMask(True) gl.glPopMatrix() y = SIDEBAR_START_Y for i, item in enumerate(self.items): if item.group: if i > 0: y -= GROUP_SPACING selected = i == self.index and State.get().navigatable == self # z = 0.71 fs_emu_texturing(False) gl.glDisable(gl.GL_DEPTH_TEST) if selected: fg_color = [1.0, 1.0, 1.0, 1.0] # gl.glBegin(gl.GL_QUADS) # # gl.glColor3f(0.00, 0x99 / 0xff, 0xcc / 0xff) # gl.glVertex3f(x, y - 18, z) # gl.glVertex3f(x + w, y - 18, z) # gl.glVertex3f(x + w, y + h - 4, z) # gl.glVertex3f(x, y + h - 4, z) # # glColor3f(0.6, 0.6, 0.6) # # glVertex3f(x, y + 4, z) # # glVertex3f(x + w, y + 4, z) # # glVertex3f(x + w, y + h, z) # # glVertex3f(x, y + h, z) # gl.glEnd() fs_emu_blending(True) fs_emu_texturing(True) gl.glDepthMask(False) Texture.item_background.render(1920 - 540 + 13 + dx, y - 18) gl.glDepthMask(True) else: fg_color = [1.0, 1.0, 1.0, 1.0] # glBegin(GL_QUADS) # glColor3f(0.4, 0.4, 0.4) # glVertex3f(x, y, z) # glVertex3f(x + w, y, z) # glVertex3f(x + w, y + 4, z) # glVertex3f(x, y + 4, z) # glEnd() # fs_emu_texturing(True) if i > 0: fg_color[3] *= 0.35 text = item.title # FIXME: REMOVE # fs_emu_blending(False) # fs_emu_blending(True) if item.group: BitmapFont.menu_font.render( text, HEADING_TEXT_LEFT + dx, y + 14, r=0.0, g=0x99 / 0xFF, b=0xCC / 0xFF, ) x, _ = BitmapFont.menu_font.measure(text) x += HEADING_TEXT_LEFT + 12 fs_emu_blending(True) fs_emu_texturing(True) # gl.glDepthMask(False) Texture.heading_strip.render(x + dx, y + 14, 1920 - x, 32) else: BitmapFont.menu_font.render(text, ITEM_TEXT_LEFT + dx, y + 14) gl.glEnable(gl.GL_DEPTH_TEST) # text = item.title.upper() # tw, th = Render.get().text(text, Font.main_path_font, # x + 40, y + 43, color=fg_color) # text = item.subtitle.upper() # fg_color[3] = fg_color[3] * 0.4 # text = item.title.upper() # tw, th = Render.get().text(text, Font.list_subtitle_font, # x + 40, y + 18, color=fg_color) y -= 54 # Gradually erase menu items when transitioning if transition > 1.0: gl.glDisable(gl.GL_DEPTH_TEST) # tr = (transition - 1.0) / 3.0 alpha = max(0.0, (transition - 1.0) / 2.0) Texture.sidebar_background.render( 1920 - Texture.sidebar_background_shadow.w * transition + 200, 0, 1920, Texture.sidebar_background.h, opacity=alpha, ) gl.glEnable(gl.GL_DEPTH_TEST)
def render(self, transition=1.0): Render.get().hd_perspective() # w = 560 # h = 92 # x = 1920 - w * transition # y = 1080 - 60 - h # y = 1080 - 60 - h - 44 # z = -0.9 item_top = 1080 - 90 item_left = 1920 - 560 + 40 item_left += Texture.sidebar_background_shadow.w * (1.0 - transition) gl.glPushMatrix() gl.glTranslate(0.0, 0.0, 0.7) # glTranslated((1.0 - transition) * g_tex_sidebar_background->width, # 0, 0) # fs_emu_set_texture(g_tex_sidebar_background) # fs_emu_render_texture_with_size(g_tex_sidebar_background, # 1920 - g_tex_sidebar_background->width, # 0, g_tex_sidebar_background->width, # g_tex_sidebar_background->height) # fs_emu_render_sidebar() fs_emu_blending(True) fs_emu_texturing(True) gl.glDepthMask(False) Texture.sidebar_background_shadow.render( 1920 - Texture.sidebar_background_shadow.w * transition, 0, Texture.sidebar_background_shadow.w, Texture.sidebar_background_shadow.h) gl.glDepthMask(True) gl.glPopMatrix() # x = x + 70 # w = w - 70 x = item_left y = item_top - 60 w = 560 - 40 - 40 h = 60 for i, item in enumerate(self.items): if item.group: if i > 0: # skip one half row before group heading y -= h / 2 selected = i == self.index and State.get().navigatable == self z = 0.71 fs_emu_texturing(False) if selected: fg_color = [1.0, 1.0, 1.0, 1.0] gl.glBegin(gl.GL_QUADS) gl.glColor3f(0.00, 0x99 / 0xff, 0xcc / 0xff) gl.glVertex3f(x, y + 4, z) gl.glVertex3f(x + w, y + 4, z) gl.glVertex3f(x + w, y + h - 4, z) gl.glVertex3f(x, y + h - 4, z) # glColor3f(0.6, 0.6, 0.6) # glVertex3f(x, y + 4, z) # glVertex3f(x + w, y + 4, z) # glVertex3f(x + w, y + h, z) # glVertex3f(x, y + h, z) gl.glEnd() else: fg_color = [1.0, 1.0, 1.0, 1.0] # glBegin(GL_QUADS) # glColor3f(0.4, 0.4, 0.4) # glVertex3f(x, y, z) # glVertex3f(x + w, y, z) # glVertex3f(x + w, y + 4, z) # glVertex3f(x, y + 4, z) # glEnd() # fs_emu_texturing(True) if i > 0: fg_color[3] *= 0.35 text = item.title # FIXME: REMOVE # fs_emu_blending(False) # fs_emu_blending(True) gl.glDisable(gl.GL_DEPTH_TEST) if item.group: BitmapFont.menu_font.render(text, x + 20, y + 14, r=0.0, g=0x99 / 0xff, b=0xcc / 0xff) else: BitmapFont.menu_font.render(text, x + 20, y + 14) gl.glEnable(gl.GL_DEPTH_TEST) # text = item.title.upper() # tw, th = Render.get().text(text, Font.main_path_font, # x + 40, y + 43, color=fg_color) # text = item.subtitle.upper() # fg_color[3] = fg_color[3] * 0.4 # text = item.title.upper() # tw, th = Render.get().text(text, Font.list_subtitle_font, # x + 40, y + 18, color=fg_color) y -= h
def _render_menu(menu, what=None, skip_center_item=False): if what is None: what = ["ITEMS", "SHADOWS"] # print "render menu with", len(menu), "items" position = menu.get_current_position() # selected = menu.get_selected_index() assert not skip_center_item # min_item = 0 # max_item = len(menu) - 1 num_items = len(menu) # i_position = min(max_item, int(round(position))) i_position = int(round(position)) # print position, " (", selected, ")" # print "selected", selected # glEnable(GL_DEPTH_TEST) def get_item_position(ip_distance): inverse = ip_distance < 0 ip_distance = abs(ip_distance) # y = 0.02 - 0.5 # y = 0.243 y = 0.293 z = -3.1 if ip_distance < 1.0: x = ip_distance * 0.8 ip_rotation = -45.0 * ip_distance z = z + 0.6 - 0.6 * ip_distance else: # x = 0.8 + 0.15 * (ip_distance - 1.0) # x = 0.8 + 0.20 * (ip_distance - 1.0) x = 0.8 + 0.33 * (ip_distance - 1.0) ip_rotation = -45.0 if inverse: return [-x, y, z], -ip_rotation else: return [x, y, z], ip_rotation def yield_render_item_sequence(): if not skip_center_item: yield i_position # if MenuGameTransition.value == 0: #< 0.00001: # for i in range(9, 0, -1): for i in range(1, 10): # if (i_position - i) >= min_item: yield i_position - i # if (i_position + i) <= max_item: yield i_position + i def yield_image_file_sequence(): for img in menu[i_position % num_items].get_image_files(): yield img for i in range(1, 12): # if (i_position - i) >= min_item: # for img in menu[i_position - i].get_image_files(): # yield img # if (i_position + i) <= max_item: # for img in menu[i_position + i].get_image_files(): # yield img for img in menu[(i_position - i) % num_items].get_image_files(): yield img for img in menu[(i_position + i) % num_items].get_image_files(): yield img item_data = [] if "ITEMS" in what: TextureManager.get().load_images(list(yield_image_file_sequence())) # TextureManager.get().load_textures(1) center_item = None light1_position = [-1.5, 0.2, -2.3, 1.0] light2_position = [-0.5, 2.5, -2.3, 1.0] # glDisable(GL_LIGHT2) if LIGHTING: gl.glEnable(gl.GL_LIGHTING) gl.glLightfv(gl.GL_LIGHT1, gl.GL_POSITION, light1_position) gl.glLightfv(gl.GL_LIGHT2, gl.GL_POSITION, light2_position) gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, (1.0, 1.0, 1.0, 1.0)) gl.glColor3f(1.0, 1.0, 1.0) # gloss_list = [] # reflections = [] # glColor3f(1.0, 1.0, 1.0) fs_emu_texturing(True) fs_emu_blending(False) for item_index in list(yield_render_item_sequence()): if num_items < MIN_WRAPAROUND_ITEMS: if not ( 0 <= item_index - (i_position // num_items * num_items) < num_items ): continue rel_index = item_index - position # selected distance = abs(rel_index) # strength = 1.0 gl.glPushMatrix() pos, rotation = get_item_position(rel_index) gl.glTranslate(*pos) scale = 1.0 area = 0.9 item = menu[item_index % num_items] height = math.sqrt(area / item.ratio) width = item.ratio * height if rel_index <= 0.0: spec = 0.8 elif rel_index > 1.0: spec = 0.05 else: spec = 0.8 - rel_index / 1.0 * 0.75 if LIGHTING: gl.glMaterialfv( gl.GL_FRONT, gl.GL_SPECULAR, (spec, spec, spec, 1.0) ) gl.glRotate(rotation, 0.0, 1.0, 0.0) item.render(width, height) if not LIGHTING: if distance < 1.0: gloss_alpha = 0.25 + distance * 0.25 else: gloss_alpha = 0.5 render_item_gloss(gloss_alpha, ratio=item.ratio, area=area) gl.glPopMatrix() item_data.append( ( "ITEM", menu, item_index, pos, rotation, scale, item.ratio, 1.0, area, ) ) # reflections.append((item, pos, rotation, # width, height, spec * 0.3)) if not center_item: State.get().center_item = None if LIGHTING: light1_position[1] = -light1_position[1] light2_position[1] = -light2_position[1] gl.glLightfv(gl.GL_LIGHT1, gl.GL_POSITION, light1_position) gl.glLightfv(gl.GL_LIGHT2, gl.GL_POSITION, light2_position) # glLightfv(GL_LIGHT1, GL_POSITION, (-5.0, -1.5, 1.2, 1.0)) # glLightfv(GL_LIGHT2, GL_POSITION, (-0.5, -5.0, 1.2, 1.0)) gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, (0.3, 0.3, 0.3, 0.0)) # glColor3f(0.3, 0.3, 0.3) # for item, pos, rotation, width, height, spec in reflections: # #if LIGHTING: # # glMaterialfv(GL_FRONT, GL_SPECULAR, (spec, spec, spec, 1.0)) # #else: # # glColor4f(0.33, 0.33, 0.33, 0.33) # # fs_emu_blending(True) # glPushMatrix() # glTranslate(*pos) # glRotate(rotation, 0.0, 1.0, 0.0) # item.render(width, height, reflection=True) # glPopMatrix() if LIGHTING: gl.glDisable(gl.GL_LIGHTING) return item_data
def render(self, transition=1.0): Render.get().hd_perspective() # w = 560 # h = 92 # x = 1920 - w * transition # y = 1080 - 60 - h # y = 1080 - 60 - h - 44 # z = -0.9 item_top = 1080 - 90 item_left = 1920 - 560 + 40 item_left += Texture.sidebar_background_shadow.w * ( 1.0 - transition) gl.glPushMatrix() gl.glTranslate(0.0, 0.0, 0.7) # glTranslated((1.0 - transition) * g_tex_sidebar_background->width, # 0, 0) # fs_emu_set_texture(g_tex_sidebar_background) # fs_emu_render_texture_with_size(g_tex_sidebar_background, # 1920 - g_tex_sidebar_background->width, # 0, g_tex_sidebar_background->width, # g_tex_sidebar_background->height) # fs_emu_render_sidebar() fs_emu_blending(True) fs_emu_texturing(True) gl.glDepthMask(False) Texture.sidebar_background_shadow.render( 1920 - Texture.sidebar_background_shadow.w * transition, 0, Texture.sidebar_background_shadow.w, Texture.sidebar_background_shadow.h) gl.glDepthMask(True) gl.glPopMatrix() # x = x + 70 # w = w - 70 x = item_left y = item_top - 60 w = 560 - 40 - 40 h = 60 for i, item in enumerate(self.items): if item.group: if i > 0: # skip one half row before group heading y -= h / 2 selected = i == self.index and State.get().navigatable == self z = 0.71 fs_emu_texturing(False) if selected: fg_color = [1.0, 1.0, 1.0, 1.0] gl.glBegin(gl.GL_QUADS) gl.glColor3f(0.00, 0x99 / 0xff, 0xcc / 0xff) gl.glVertex3f(x, y + 4, z) gl.glVertex3f(x + w, y + 4, z) gl.glVertex3f(x + w, y + h - 4, z) gl.glVertex3f(x, y + h - 4, z) # glColor3f(0.6, 0.6, 0.6) # glVertex3f(x, y + 4, z) # glVertex3f(x + w, y + 4, z) # glVertex3f(x + w, y + h, z) # glVertex3f(x, y + h, z) gl.glEnd() else: fg_color = [1.0, 1.0, 1.0, 1.0] # glBegin(GL_QUADS) # glColor3f(0.4, 0.4, 0.4) # glVertex3f(x, y, z) # glVertex3f(x + w, y, z) # glVertex3f(x + w, y + 4, z) # glVertex3f(x, y + 4, z) # glEnd() # fs_emu_texturing(True) if i > 0: fg_color[3] *= 0.35 text = item.title # FIXME: REMOVE # fs_emu_blending(False) # fs_emu_blending(True) gl.glDisable(gl.GL_DEPTH_TEST) if item.group: BitmapFont.menu_font.render( text, x + 20, y + 14, r=0.0, g=0x99 / 0xff, b=0xcc / 0xff) else: BitmapFont.menu_font.render(text, x + 20, y + 14) gl.glEnable(gl.GL_DEPTH_TEST) # text = item.title.upper() # tw, th = Render.get().text(text, Font.main_path_font, # x + 40, y + 43, color=fg_color) # text = item.subtitle.upper() # fg_color[3] = fg_color[3] * 0.4 # text = item.title.upper() # tw, th = Render.get().text(text, Font.list_subtitle_font, # x + 40, y + 18, color=fg_color) y -= h