def render(self, width, height, st, at): if renpy.game.less_updates: return null_render(self, width, height, st, at) if st >= self.time: self.events = True return render(self.new_widget, width, height, st, at) step = st // self.quantum + 1 visible = self.old_widget if step > self.steps: step = (self.steps * 2) - step + 1 visible = self.new_widget self.events = True rdr = render(visible, width, height, st, at) rv = renpy.display.render.Render(rdr.width, rdr.height) rv.blit(rdr, (0, 0)) rv.operation = renpy.display.render.PIXELLATE rv.operation_parameter = 2 ** step renpy.display.render.redraw(self, 0) return rv
def render(self, width, height, st, at): if renpy.game.less_updates: return null_render(self, width, height, st, at) if st >= self.time: self.events = True return render(self.new_widget, width, height, st, at) complete = min(1.0, st / self.time) if self.time_warp is not None: complete = self.time_warp(complete) bottom = render(self.old_widget, width, height, st, at) top = render(self.new_widget, width, height, st, at) width = min(top.width, bottom.width) height = min(top.height, bottom.height) rv = renpy.display.render.Render(width, height, opaque=not self.alpha) rv.operation = renpy.display.render.DISSOLVE rv.operation_alpha = self.alpha rv.operation_complete = complete rv.blit(bottom, (0, 0), focus=False, main=False) rv.blit(top, (0, 0), focus=True, main=True) renpy.display.render.redraw(self, 0) return rv
def render(self, width, height, st, at): if renpy.game.less_updates or renpy.display.less_imagedissolve: return null_render(self, width, height, st, at) if st >= self.delay: self.events = True return render(self.new_widget, width, height, st, at) image = render(self.image, width, height, st, at) bottom = render(self.old_widget, width, height, st, at) top = render(self.new_widget, width, height, st, at) width = min(bottom.width, top.width, image.width) height = min(bottom.height, top.height, image.height) rv = renpy.display.render.Render(width, height, opaque=not self.alpha) complete = st / self.delay if self.time_warp is not None: complete = self.time_warp(complete) rv.operation = renpy.display.render.IMAGEDISSOLVE rv.operation_alpha = self.alpha rv.operation_complete = complete rv.operation_parameter = self.ramplen rv.blit(image, (0, 0), focus=False, main=False) rv.blit(bottom, (0, 0), focus=False, main=False) rv.blit(top, (0, 0), focus=True, main=True) renpy.display.render.redraw(self, 0) return rv
def render(self, width, height, st, at): if renpy.game.less_updates or renpy.display.less_imagedissolve: return null_render(self, width, height, st, at) if st >= self.delay: self.events = True bottom = render(self.old_widget, width, height, st, at) top = render(self.new_widget, width, height, st, at) width = min(bottom.width, top.width) height = min(bottom.height, top.height) control = render(self.control, width, height, st, at) rv = renpy.display.render.Render(width, height, opaque=not self.alpha) rv.operation = renpy.display.render.IMAGEDISSOLVE rv.operation_alpha = self.alpha rv.operation_complete = 256.0 / (256.0 + 256.0) rv.operation_parameter = 256 rv.blit(control, (0, 0), focus=False, main=False) if not self.reverse: rv.blit(bottom, (0, 0), focus=False, main=False) rv.blit(top, (0, 0), focus=True, main=True) else: rv.blit(top, (0, 0), focus=True, main=True) rv.blit(bottom, (0, 0), focus=False, main=False) return rv
def render(self, index, width, height, st, at): if self.cache is None: d, rect = self.imagerect[index] return render(d, width, height, st, at).subsurface(rect) return render(self.cache, width, height, st, at).subsurface(self.cache_rect[index])
def render(self, width, height, st, at): if renpy.game.less_updates: return null_render(self, width, height, st, at) if st >= self.time: self.events = True return render(self.new_widget, width, height, st, at) step = st // self.quantum + 1 visible = self.old_widget if step > self.steps: step = (self.steps * 2) - step + 1 visible = self.new_widget self.events = True rdr = render(visible, width, height, st, at) rv = renpy.display.render.Render(rdr.width, rdr.height) rv.blit(rdr, (0, 0)) rv.operation = renpy.display.render.PIXELLATE rv.operation_parameter = 2**step renpy.display.render.redraw(self, 0) return rv
def render(self, width, height, st, at): if renpy.game.less_updates: return null_render(self, width, height, st, at) if st >= self.time: self.events = True return render(self.new_widget, width, height, st, at) step = st // self.quantum + 1 visible = self.old_widget if step > self.steps: step = (self.steps * 2) - step + 1 visible = self.new_widget self.events = True rdr = render(visible, width, height, st, at) rv = renpy.display.render.Render(rdr.width, rdr.height) rv.blit(rdr, (0, 0)) rv.operation = renpy.display.render.PIXELLATE rv.operation_parameter = 2 ** step rv.mesh = True rv.add_shader("renpy.texture") rv.add_property("texture_scaling", "nearest_mipmap_nearest") rv.add_property("anisotropic", False) rv.add_uniform("u_lod_bias", step + 1) renpy.display.render.redraw(self, 0) return rv
def render(self, width, height, st, at): if renpy.game.less_updates or renpy.display.less_imagedissolve: return null_render(self, width, height, st, at) if st >= self.delay: self.events = True bottom = render(self.old_widget, width, height, st, at) top = render(self.new_widget, width, height, st, at) width = min(bottom.width, top.width) height = min(bottom.height, top.height) control = render(self.control, width, height, st, at) rv = renpy.display.render.Render(width, height, opaque=not self.alpha) rv.operation = renpy.display.render.IMAGEDISSOLVE rv.operation_alpha = self.alpha or renpy.config.dissolve_force_alpha rv.operation_complete = 256.0 / (256.0 + 256.0) rv.operation_parameter = 256 rv.blit(control, (0, 0), focus=False, main=False) if not self.reverse: rv.blit(bottom, (0, 0), focus=False, main=False) rv.blit(top, (0, 0), focus=True, main=True) else: rv.blit(top, (0, 0), focus=True, main=True) rv.blit(bottom, (0, 0), focus=False, main=False) return rv
def render(self, width, height, st, at): if renpy.game.less_updates or renpy.display.less_imagedissolve: return null_render(self, width, height, st, at) if st >= self.delay: self.events = True return render(self.new_widget, width, height, st, at) image = render(self.image, width, height, st, at) bottom = render(self.old_widget, width, height, st, at) top = render(self.new_widget, width, height, st, at) width = min(bottom.width, top.width, image.width) height = min(bottom.height, top.height, image.height) rv = renpy.display.render.Render(width, height, opaque=not (self.alpha or renpy.config.dissolve_force_alpha)) complete = st / self.delay if self.time_warp is not None: complete = self.time_warp(complete) rv.operation = renpy.display.render.IMAGEDISSOLVE rv.operation_alpha = self.alpha or renpy.config.dissolve_force_alpha rv.operation_complete = complete rv.operation_parameter = self.ramplen rv.blit(image, (0, 0), focus=False, main=False) rv.blit(bottom, (0, 0), focus=False, main=False) rv.blit(top, (0, 0), focus=True, main=True) renpy.display.render.redraw(self, 0) return rv
def render(self, width, height, st, at): if renpy.game.less_updates: return null_render(self, width, height, st, at) time = 1.0 * st / self.time # Done rendering. if time >= 1.0: self.events = True return render(self.new_widget, width, height, st, at) # How we scale each element of a tuple. scales = (width, height, width, height) crop = interpolate_tuple(self.startcrop, self.endcrop, time, scales) pos = interpolate_tuple(self.startpos, self.endpos, time, scales) top = render(self.top, width, height, st, at) bottom = render(self.bottom, width, height, st, at) width = min(bottom.width, width) height = min(bottom.height, height) rv = renpy.display.render.Render(width, height) rv.blit(bottom, (0, 0), focus=not self.topnew) ss = top.subsurface(crop, focus=self.topnew) rv.blit(ss, pos, focus=self.topnew) renpy.display.render.redraw(self, 0) return rv
def render(self, width, height, st, at): if renpy.game.less_updates: return null_render(self, width, height, st, at) time = 1.0 * st / self.time # Done rendering. if time >= 1.0: self.events = True return render(self.new_widget, width, height, st, at) # How we scale each element of a tuple. scales = (width, height, width, height) new_crop = interpolate_tuple(self.new_startcrop, self.new_endcrop, time, scales) new_pos = interpolate_tuple(self.new_startpos, self.new_endpos, time, scales) old_crop = interpolate_tuple(self.old_startcrop, self.old_endcrop, time, scales) old_pos = interpolate_tuple(self.old_startpos, self.old_endpos, time, scales) new = render(self.new_widget, width, height, st, at) old = render(self.old_widget, width, height, st, at) rv = renpy.display.render.Render(width, height) old_ss = old.subsurface(old_crop, focus=True) rv.blit(old_ss, old_pos, focus=True) new_ss = new.subsurface(new_crop, focus=True) rv.blit(new_ss, new_pos, focus=True) renpy.display.render.redraw(self, 0) return rv
def render(self, width, height, st, at): if renpy.game.less_updates: return null_render(self, width, height, st, at) if st >= self.time: self.events = True return render(self.new_widget, width, height, st, at) if st < self.time: renpy.display.render.redraw(self, 0) alpha = min(255, int(255 * st / self.time)) bottom = render(self.old_widget, width, height, st, at) top = render(self.new_widget, width, height, st, at) bottom_surface = bottom.pygame_surface(self.alpha) top_surface = top.pygame_surface(self.alpha) width = min(top.width, bottom.width) height = min(top.height, bottom.height) def draw(dest, x, y): dw, dh = dest.get_size() w = min(dw, width + x) h = min(dh, height + y) if w <= 0 or h <= 0: return renpy.display.module.blend( bottom_surface.subsurface((-x, -y, w, h)), top_surface.subsurface((-x, -y, w, h)), dest.subsurface((0, 0, w, h)), alpha) if self.alpha: surf = renpy.display.pgrender.surface((width, height), True) draw(surf, 0, 0) renpy.display.render.mutated_surface(surf) rv = renpy.display.render.Render(width, height) rv.blit(surf, (0, 0)) else: rv = renpy.display.render.Render(width, height, draw_func=draw, opaque=True) rv.depends_on(top, True) rv.depends_on(bottom) return rv
def render(self, width, height, st, at): if renpy.game.less_updates: return null_render(self, width, height, st, at) if st >= self.time: self.events = True return render(self.new_widget, width, height, st, at) complete = min(1.0, st / self.time) if self.time_warp is not None: complete = self.time_warp(complete) bottom = render(self.old_widget, width, height, st, at) top = render(self.new_widget, width, height, st, at) width = min(top.width, bottom.width) height = min(top.height, bottom.height) rv = renpy.display.render.Render( width, height, opaque=not (self.alpha or renpy.config.dissolve_force_alpha)) rv.operation = renpy.display.render.DISSOLVE rv.operation_alpha = self.alpha or renpy.config.dissolve_force_alpha rv.operation_complete = complete if renpy.display.render.models: target = rv.get_size() if top.get_size() != target: top = top.subsurface((0, 0, width, height)) if bottom.get_size() != target: bottom = bottom.subsurface((0, 0, width, height)) rv.mesh = True rv.add_shader("renpy.dissolve") rv.add_uniform("u_renpy_dissolve", complete) rv.add_property( "mipmap", renpy.config.mipmap_dissolves if (self.mipmap is None) else self.mipmap) rv.blit(bottom, (0, 0), focus=False, main=False) rv.blit(top, (0, 0), focus=True, main=True) renpy.display.render.redraw(self, 0) return rv
def render(self, width, height, st, at): self.width = width self.height = height if self.update_function is not None: redraw = self.update_function(st) if redraw is not None: renpy.display.render.redraw(self, redraw) if not self.ignore_time: self.displayable_map.clear() if self.dead_child: self.children = [ i for i in self.children if i.live ] self.children.sort(key=lambda sc:sc.zorder) caches = [ ] rv = renpy.display.render.Render(width, height) events = False for i in self.children: events |= i.events cache = i.cache r = i.cache.render if cache.render is None: if cache.st is None: cache.st = st cst = st - cache.st cache.render = r = render(cache.child_copy, width, height, cst, cst) cache.fast = (r.operation == BLIT) and (r.forward is None) and (r.alpha == 1.0) and (r.over == 1.0) rv.depends_on(r) caches.append(cache) if cache.fast: for child, xo, yo, _focus, _main in r.children: rv.children.append((child, xo + i.x, yo + i.y, False, False)) else: rv.subpixel_blit(r, (i.x, i.y)) for i in caches: i.render = None return rv
def render(self, width, height, st, at): self.width = width self.height = height if self.update_function is not None: redraw = self.update_function(st) if redraw is not None: renpy.display.render.redraw(self, redraw) if not self.ignore_time: self.displayable_map.clear() if self.dead_child: self.children = [ i for i in self.children if i.live ] self.children.sort() caches = [ ] rv = renpy.display.render.Render(width, height) events = False for i in self.children: events |= i.events cache = i.cache r = i.cache.render if cache.render is None: if cache.st is None: cache.st = st cst = st - cache.st cache.render = r = render(cache.child, width, height, cst, cst) cache.fast = (r.operation == BLIT) and (r.forward is None) and (r.alpha == 1.0) rv.depends_on(r) caches.append(cache) if cache.fast: for child, xo, yo, _focus, _main in r.children: rv.children.append((child, xo + i.x, yo + i.y, False, False)) else: rv.subpixel_blit(r, (i.x, i.y)) for i in caches: i.render = None return rv
def sizeit(pos, width, height, owidth, oheight): if pos not in pos_d: return owidth, oheight rend = render(pos_d[pos], width, height, st, at) rv = max(owidth, rend.width), max(oheight, rend.height) rend.kill() return rv
def place(pos, x, y, w, h): if pos not in pos_d: return d = pos_d[pos] i = pos_i[pos] rend = render(d, w, h, st, at) self.offsets[i] = pos_d[pos].place(rv, x, y, w, h, rend)
def render(self, width, height, st, at): surf = render(self.child, width, height, st, at) self.offsets = [ (0, 0) ] rv = renpy.display.render.Render(surf.width, surf.height) rv.blit(surf, (0, 0)) return rv
def render(self, width, height, st, at): surf = render(self.child, width, height, st, at) self.offsets = [(0, 0)] rv = renpy.display.render.Render(surf.width, surf.height) rv.blit(surf, (0, 0)) return rv
def render(self, width, height, st, at): if renpy.game.less_updates or renpy.display.less_imagedissolve: return null_render(self, width, height, st, at) if st >= self.delay: self.events = True bottom = render(self.old_widget, width, height, st, at) top = render(self.new_widget, width, height, st, at) width = min(bottom.width, top.width) height = min(bottom.height, top.height) control = render(self.control, width, height, st, at) rv = renpy.display.render.Render(width, height) rv.operation = renpy.display.render.IMAGEDISSOLVE rv.operation_alpha = self.alpha or renpy.config.dissolve_force_alpha rv.operation_complete = 256.0 / (256.0 + 256.0) rv.operation_parameter = 256 if renpy.display.render.models: rv.mesh = True rv.add_shader("renpy.imagedissolve", ) rv.add_uniform("u_renpy_dissolve_offset", 0) rv.add_uniform("u_renpy_dissolve_multiplier", 1.0) rv.add_property( "mipmap", renpy.config.mipmap_dissolves if (self.style.mipmap is None) else self.style.mipmap) rv.blit(control, (0, 0), focus=False, main=False) if not self.reverse: rv.blit(bottom, (0, 0), focus=False, main=False) rv.blit(top, (0, 0), focus=True, main=True) else: rv.blit(top, (0, 0), focus=True, main=True) rv.blit(bottom, (0, 0), focus=False, main=False) return rv
def render(self, width, height, st, at): rv = Render(width, height) self.offsets = self._list_type() for c in self.children: cr = render(c, width, height, st, at) offset = c.place(rv, 0, 0, width, height, cr) self.offsets.append(offset) return rv
def render(self, width, height, st, at): if renpy.game.less_updates: return null_render(self, width, height, st, at) time = 1.0 * st / self.time # Done rendering. if time >= 1.0: self.events = True return render(self.new_widget, width, height, st, at) # How we scale each element of a tuple. scales = (width, height, width, height) def interpolate_tuple(t0, t1): return tuple([ int(s * (a * (1.0 - time) + b * time)) for a, b, s in zip(t0, t1, scales) ]) new_crop = interpolate_tuple(self.new_startcrop, self.new_endcrop) new_pos = interpolate_tuple(self.new_startpos, self.new_endpos) old_crop = interpolate_tuple(self.old_startcrop, self.old_endcrop) old_pos = interpolate_tuple(self.old_startpos, self.old_endpos) new = render(self.new_widget, width, height, st, at) old = render(self.old_widget, width, height, st, at) rv = renpy.display.render.Render(width, height) old_ss = old.subsurface(old_crop, focus = True) rv.blit(old_ss, old_pos, focus = True) new_ss = new.subsurface(new_crop, focus = True) rv.blit(new_ss, new_pos, focus = True) renpy.display.render.redraw(self, 0) return rv
def render(self, width, height, st, at): if renpy.game.less_updates: return null_render(self, width, height, st, at) time = 1.0 * st / self.time # Done rendering. if time >= 1.0: self.events = True return render(self.new_widget, width, height, st, at) # How we scale each element of a tuple. scales = (width, height, width, height) def interpolate_tuple(t0, t1): return tuple([ int(s * (a * (1.0 - time) + b * time)) for a, b, s in zip(t0, t1, scales) ]) crop = interpolate_tuple(self.startcrop, self.endcrop) pos = interpolate_tuple(self.startpos, self.endpos) top = render(self.top, width, height, st, at) bottom = render(self.bottom, width, height, st, at) width = min(bottom.width, width) height = min(bottom.height, height) rv = renpy.display.render.Render(width, height) rv.blit(bottom, (0, 0), focus=not self.topnew) ss = top.subsurface(crop, focus=self.topnew) rv.blit(ss, pos, focus=self.topnew) renpy.display.render.redraw(self, 0) return rv
def render(self, width, height, st, at): if renpy.game.less_updates: return null_render(self, width, height, st, at) if st >= self.time: self.events = True return render(self.new_widget, width, height, st, at) step = st // self.quantum + 1 visible = self.old_widget if step > self.steps: step = (self.steps * 2) - step + 1 visible = self.new_widget self.events = True rdr = render(visible, width, height, st, at) surf = rdr.pygame_surface(False) size = surf.get_size() newsurf = renpy.display.pgrender.surface(size, surf) px = 2**step renpy.display.module.pixellate(surf, newsurf, px, px, px, px) renpy.display.render.mutated_surface(newsurf) rv = renpy.display.render.Render(rdr.width, rdr.height) rv.blit(newsurf, (0, 0)) rv.depends_on(rdr) renpy.display.render.redraw(self, 0) return rv
def render(self, width, height, st, at): if renpy.game.less_updates: return null_render(self, width, height, st, at) if st >= self.time: self.events = True return render(self.new_widget, width, height, st, at) step = st // self.quantum + 1 visible = self.old_widget if step > self.steps: step = (self.steps * 2) - step + 1 visible = self.new_widget self.events = True rdr = render(visible, width, height, st, at) surf = rdr.pygame_surface(False) size = surf.get_size() newsurf = renpy.display.pgrender.surface(size, surf) px = 2 ** step renpy.display.module.pixellate(surf, newsurf, px, px, px, px) renpy.display.render.mutated_surface(newsurf) rv = renpy.display.render.Render(rdr.width, rdr.height) rv.blit(newsurf, (0, 0)) rv.depends_on(rdr) renpy.display.render.redraw(self, 0) return rv
def render(self, width, height, st, at): self.width = width self.height = height child_width = self.child_width or width child_height = self.child_height or height surf = render(self.child, child_width, child_height, st, at) cw, ch = surf.get_size() # width = min(cw, width) # height = min(ch, height) if self.set_adjustments: self.xadjustment.range = max(cw - width, 0) self.xadjustment.page = width self.yadjustment.range = max(ch - height, 0) self.yadjustment.page = height if self.xoffset is not None: if isinstance(self.xoffset, int): value = self.xoffset else: value = max(cw - width, 0) * self.xoffset self.xadjustment.value = value self.xoffset = None if self.yoffset is not None: if isinstance(self.yoffset, int): value = self.yoffset else: value = max(ch - height, 0) * self.yoffset self.yadjustment.value = value self.yoffset = None cxo = -int(self.xadjustment.value) cyo = -int(self.yadjustment.value) self.offsets = [ (cxo, cyo) ] rv = renpy.display.render.Render(width, height) rv.blit(surf, (cxo, cyo)) return rv
def render(self, width, height, st, at): if self.anim_timebase: t = at else: t = st child = render(self.child, width, height, st, at) cw, ch = child.get_size() self.update_position(t, (width, height, cw, ch)) rv = renpy.display.render.Render(cw, ch) rv.blit(child, (0, 0)) self.offsets = [ (0, 0) ] return rv
def render(self, width, height, st, at): if self.anim_timebase: t = at else: t = st child = render(self.child, width, height, st, at) cw, ch = child.get_size() self.update_position(t, (width, height, cw, ch)) rv = renpy.display.render.Render(cw, ch) rv.blit(child, (0, 0)) self.offsets = [(0, 0)] return rv
def render(self, width, height, st, at): color = self.color or self.style.color rv = Render(width, height) if color is None or width <= 0 or height <= 0: return rv SIZE = 10 si = renpy.display.im.SolidImage(color, SIZE, SIZE) sr = render(si, SIZE, SIZE, st, at) rv.forward = Matrix2D(1.0 * SIZE / width, 0, 0, 1.0 * SIZE / height) rv.reverse = Matrix2D(1.0 * width / SIZE, 0, 0, 1.0 * height / SIZE) rv.blit(sr, (0, 0)) return rv
def render(self, width, height, st, at): # Handle redrawing. if self.value is not None: redraw = self.value.periodic(st) if redraw is not None: renpy.display.render.redraw(self, redraw) # Store the width and height for the event function to use. self.width = width self.height = height range = self.adjustment.range #@ReservedAssignment value = self.adjustment.value page = self.adjustment.page if range <= 0: if self.style.unscrollable == "hide": self.hidden = True return renpy.display.render.Render(width, height) elif self.style.unscrollable == "insensitive": self.set_style_prefix("insensitive_", True) self.hidden = False if self.style.bar_invert ^ self.style.bar_vertical: value = range - value bar_vertical = self.style.bar_vertical if bar_vertical: dimension = height else: dimension = width fore_gutter = self.style.fore_gutter aft_gutter = self.style.aft_gutter active = dimension - fore_gutter - aft_gutter if range: thumb_dim = active * page / (range + page) else: thumb_dim = active thumb_offset = abs(self.style.thumb_offset) if bar_vertical: thumb = render(self.style.thumb, width, thumb_dim, st, at) thumb_shadow = render(self.style.thumb_shadow, width, thumb_dim, st, at) thumb_dim = thumb.height else: thumb = render(self.style.thumb, thumb_dim, height, st, at) thumb_shadow = render(self.style.thumb_shadow, thumb_dim, height, st, at) thumb_dim = thumb.width # Remove the offset from the thumb. thumb_dim -= thumb_offset * 2 self.thumb_dim = thumb_dim active -= thumb_dim if range: fore_size = active * value / range else: fore_size = active fore_size = int(fore_size) aft_size = active - fore_size fore_size += fore_gutter aft_size += aft_gutter rv = renpy.display.render.Render(width, height) if bar_vertical: if self.style.bar_resizing: foresurf = render(self.style.fore_bar, width, fore_size, st, at) aftsurf = render(self.style.aft_bar, width, aft_size, st, at) rv.blit(thumb_shadow, (0, fore_size - thumb_offset)) rv.blit(foresurf, (0, 0), main=False) rv.blit(aftsurf, (0, height-aft_size), main=False) rv.blit(thumb, (0, fore_size - thumb_offset)) else: foresurf = render(self.style.fore_bar, width, height, st, at) aftsurf = render(self.style.aft_bar, width, height, st, at) rv.blit(thumb_shadow, (0, fore_size - thumb_offset)) rv.blit(foresurf.subsurface((0, 0, width, fore_size)), (0, 0), main=False) rv.blit(aftsurf.subsurface((0, height - aft_size, width, aft_size)), (0, height - aft_size), main=False) rv.blit(thumb, (0, fore_size - thumb_offset)) else: if self.style.bar_resizing: foresurf = render(self.style.fore_bar, fore_size, height, st, at) aftsurf = render(self.style.aft_bar, aft_size, height, st, at) rv.blit(thumb_shadow, (fore_size - thumb_offset, 0)) rv.blit(foresurf, (0, 0), main=False) rv.blit(aftsurf, (width-aft_size, 0), main=False) rv.blit(thumb, (fore_size - thumb_offset, 0)) else: foresurf = render(self.style.fore_bar, width, height, st, at) aftsurf = render(self.style.aft_bar, width, height, st, at) rv.blit(thumb_shadow, (fore_size - thumb_offset, 0)) rv.blit(foresurf.subsurface((0, 0, fore_size, height)), (0, 0), main=False) rv.blit(aftsurf.subsurface((width - aft_size, 0, aft_size, height)), (width-aft_size, 0), main=False) rv.blit(thumb, (fore_size - thumb_offset, 0)) if self.focusable: rv.add_focus(self, None, 0, 0, width, height) return rv
def wrap_render(child, w, h, st, at): rend = render(child, w, h, st, at) rv = Render(rend.width, rend.height) rv.blit(rend, (0, 0)) return rv
def render(self, width, height, st, at): child = self.style.child if child is None: child = self.child self.parent_width = width self.parent_height = height cr = render(child, width, height, st, at) cw, ch = cr.get_size() rv = Render(cw, ch) rv.blit(cr, (0, 0)) self.w = cw self.h = ch position = (self.style.xpos, self.style.ypos, self.style.xanchor, self.style.yanchor, self.style.xoffset, self.style.yoffset) # If we don't have a position, then look for it in a drag group. if (self.x is None) and (self.drag_group is not None) and (self.drag_name is not None): if self.drag_name in self.drag_group.positions: dgp = self.drag_group.positions[self.drag_name] if len(dgp) == 3: self.x, self.y, self.old_position = dgp else: self.x, self.y = dgp self.old_position = position if self.old_position != position: place = True elif self.x is None: place = True else: place = False # If we don't have a position, run the placement code and use # that to compute our placement. if place: # This is required to get get_placement to work properly. self.x = None place_x, place_y = self.place(None, 0, 0, width, height, rv) self.x = int(place_x) self.y = int(place_y) self.target_x = None self.old_position = position if self.target_x is None: self.target_x = self.x self.target_y = self.y self.target_at = at # Determine if we need to do the snap animation. if at >= self.target_at: self.x = self.target_x self.y = self.target_y else: done = (at - self.at) / (self.target_at - self.at) self.x = absolute(self.x + done * (self.target_x - self.x)) self.y = absolute(self.y + done * (self.target_y - self.y)) redraw(self, 0) if self.draggable or self.clicked is not None: fx, fy, fw, fh = self.drag_handle if isinstance(fx, float): fx = int(fx * cw) if isinstance(fy, float): fy = int(fy * ch) if isinstance(fw, float): fw = int(fw * cw) if isinstance(fh, float): fh = int(fh * ch) rv.add_focus(self, None, fx, fy, fw, fh, fx, fy, cr.subsurface((fx, fy, fw, fh))) self.last_x = self.x self.last_y = self.y self.at = at return rv
def render(self, width, height, st, at): cr = render(self.child, width, height, st, at) return cr.subsurface(self.rect)
def render(self, width, height, st, at): # For convenience and speed. padding = self.style.spacing cols = self.cols rows = self.rows if len(self.children) != cols * rows: if len(self.children) < cols * rows: raise Exception("Grid not completely full.") else: raise Exception("Grid overfull.") # If necessary, transpose the grid (kinda hacky, but it works here.) if self.transpose: self.transpose = False old_children = self.children[:] for y in range(0, rows): for x in range(0, cols): self.children[x + y * cols] = old_children[ y + x * rows ] # Now, start the actual rendering. renwidth = width renheight = height if self.style.xfill: renwidth = (width - (cols - 1) * padding) / cols if self.style.yfill: renheight = (height - (rows - 1) * padding) / rows renders = [ render(i, renwidth, renheight, st, at) for i in self.children ] sizes = [ i.get_size() for i in renders ] cwidth = 0 cheight = 0 for w, h in sizes: cwidth = max(cwidth, w) cheight = max(cheight, h) if self.style.xfill: cwidth = renwidth if self.style.yfill: cheight = renheight width = cwidth * cols + padding * (cols - 1) height = cheight * rows + padding * (rows - 1) rv = renpy.display.render.Render(width, height) self.offsets = [ ] for y in range(0, rows): for x in range(0, cols): child = self.children[ x + y * cols ] surf = renders[x + y * cols] xpos = x * (cwidth + padding) ypos = y * (cheight + padding) offset = child.place(rv, xpos, ypos, cwidth, cheight, surf) self.offsets.append(offset) return rv
def render(self, width, height, st, at): # save some typing. style = self.style xminimum = scale(style.xminimum, width) yminimum = scale(style.yminimum, height) size_group = self.style.size_group if size_group: xminimum = max(xminimum, size_groups[size_group].width(width, height, st, at)) left_margin = scale(style.left_margin, width) left_padding = scale(style.left_padding, width) right_margin = scale(style.right_margin, width) right_padding = scale(style.right_padding, width) top_margin = scale(style.top_margin, height) top_padding = scale(style.top_padding, height) bottom_margin = scale(style.bottom_margin, height) bottom_padding = scale(style.bottom_padding, height) # c for combined. cxmargin = left_margin + right_margin cymargin = top_margin + bottom_margin cxpadding = left_padding + right_padding cypadding = top_padding + bottom_padding child = self.get_child() # Render the child. surf = render(child, width - cxmargin - cxpadding, height - cymargin - cypadding, st, at) sw, sh = surf.get_size() # If we don't fill, shrink our size to fit. if not style.xfill: width = max(cxmargin + cxpadding + sw, xminimum) if not style.yfill: height = max(cymargin + cypadding + sh, yminimum) rv = renpy.display.render.Render(width, height) # Draw the background. The background should render at exactly the # requested size. (That is, be a Frame or a Solid). if style.background: bw = width - cxmargin bh = height - cymargin back = render(style.background, bw, bh, st, at) style.background.place(rv, left_margin, top_margin, bw, bh, back, main=False) offsets = child.place(rv, left_margin + left_padding, top_margin + top_padding, width - cxmargin - cxpadding, height - cymargin - cypadding, surf) # Draw the foreground. The background should render at exactly the # requested size. (That is, be a Frame or a Solid). if style.foreground: bw = width - cxmargin bh = height - cymargin back = render(style.foreground, bw, bh, st, at) style.foreground.place(rv, left_margin, top_margin, bw, bh, back, main=False) self.offsets = [ offsets ] self.window_size = width, height # W0201 return rv
def render(self, width, height, st, at): child = self.style.child if child is None: child = self.child self.parent_width = width self.parent_height = height cr = render(child, width, height, st, at) cw, ch = cr.get_size() rv = Render(cw, ch) rv.blit(cr, (0, 0)) self.w = cw self.h = ch position = (self.style.xpos, self.style.ypos, self.style.xanchor, self.style.yanchor, self.style.xoffset, self.style.yoffset) # If we don't have a position, then look for it in a drag group. if (self.x is None) and (self.drag_group is not None) and (self.drag_name is not None): if self.drag_name in self.drag_group.positions: dgp = self.drag_group.positions[self.drag_name] if len(dgp) == 3: self.x, self.y, self.old_position = dgp else: self.x, self.y = dgp self.old_position = position if self.old_position != position: place = True elif self.x is None: place = True else: place = False # If we don't have a position, run the placement code and use # that to compute our placement. if place: # This is required to get get_placement to work properly. self.x = None place_x, place_y = self.place(None, 0, 0, width, height, rv) self.x = int(place_x) self.y = int(place_y) self.target_x = None self.old_position = position if self.target_x is None: self.target_x = self.x self.target_y = self.y self.target_at = at # Determine if we need to do the snap animation. if self.target_at_delay: # Snap starts now self.target_at = at + self.target_at_delay self.target_at_delay = 0 redraw(self, 0) elif at >= self.target_at: # Snap complete self.x = self.target_x self.y = self.target_y else: # Snap in progress done = (at - self.at) / (self.target_at - self.at) self.x = absolute(self.x + done * (self.target_x - self.x)) self.y = absolute(self.y + done * (self.target_y - self.y)) redraw(self, 0) if self.draggable or self.clicked is not None: fx, fy, fw, fh = self.drag_handle if isinstance(fx, float): fx = int(fx * cw) if isinstance(fy, float): fy = int(fy * ch) if isinstance(fw, float): fw = int(fw * cw) if isinstance(fh, float): fh = int(fh * ch) mask = self.style.focus_mask if mask is True: mask = cr.subsurface((fx, fy, fw, fh)) elif mask is not None: try: mask = renpy.display.render.render(mask, fw, fh, st, at) except: if callable(mask): mask = mask else: raise Exception("Focus_mask must be None, True, a displayable, or a callable.") if mask is not None: fmx = 0 fmy = 0 else: fmx = None fmy = None rv.add_focus(self, None, fx, fy, fw, fh, fmx, fmy, mask) self.last_x = self.x self.last_y = self.y self.at = at return rv
def render(self, width, height, st, at): child = self.style.child if child is None: child = self.child self.parent_width = width self.parent_height = height cr = render(child, width, height, st, at) cw, ch = cr.get_size() rv = Render(cw, ch) rv.blit(cr, (0, 0)) self.w = cw self.h = ch # If we don't have a position, then look for it in a drag group. if (self.x is None) and (self.drag_group is not None) and (self.drag_name is not None): if self.drag_name in self.drag_group.positions: self.x, self.y = self.drag_group.positions[self.drag_name] # If we don't have a position, run the placement code and use # that to compute our placement. if self.x is None: self.x, self.y = self.place(None, 0, 0, width, height, rv) self.x = int(self.x) self.y = int(self.y) if self.target_x is None: self.target_x = self.x self.target_y = self.y self.target_at = at # Determine if we need to do the snap animation. if at >= self.target_at: self.x = self.target_x self.y = self.target_y else: done = (at - self.at) / (self.target_at - self.at) self.x = absolute(self.x + done * (self.target_x - self.x)) self.y = absolute(self.y + done * (self.target_y - self.y)) redraw(self, 0) if self.draggable or self.clicked is not None: fx, fy, fw, fh = self.drag_handle if isinstance(fx, float): fx = int(fx * cw) if isinstance(fy, float): fy = int(fy * ch) if isinstance(fw, float): fw = int(fw * cw) if isinstance(fh, float): fh = int(fh * ch) rv.add_focus(self, None, fx, fy, fw, fh, fx, fy, cr.subsurface((fx, fy, fw, fh))) self.last_x = self.x self.last_y = self.y self.at = at return rv
def render(self, width, height, st, at): width = max(self.style.xminimum, width) height = max(self.style.yminimum, height) image = self.style.child or self.image crend = render(image, width, height, st, at) sw, sh = crend.get_size() sw = int(sw) sh = int(sh) dw = int(width) dh = int(height) bw = self.left + self.right bh = self.top + self.bottom xborder = min(bw, sw - 2, dw) if xborder and bw: left = self.left * xborder / bw right = self.right * xborder / bw else: left = 0 right = 0 yborder = min(bh, sh - 2, dh) if yborder and bh: top = self.top * yborder / bh bottom = self.bottom * yborder / bh else: top = 0 bottom = 0 if renpy.display.draw.info["renderer"] == "sw": return self.sw_render(crend, dw, dh, left, top, right, bottom) def draw(x0, x1, y0, y1): # Compute the coordinates of the left, right, top, and # bottom sides of the region, for both the source and # destination surfaces. # left side. if x0 >= 0: dx0 = x0 sx0 = x0 else: dx0 = dw + x0 sx0 = sw + x0 # right side. if x1 > 0: dx1 = x1 sx1 = x1 else: dx1 = dw + x1 sx1 = sw + x1 # top side. if y0 >= 0: dy0 = y0 sy0 = y0 else: dy0 = dh + y0 sy0 = sh + y0 # bottom side if y1 > 0: dy1 = y1 sy1 = y1 else: dy1 = dh + y1 sy1 = sh + y1 # Quick exit. if sx0 == sx1 or sy0 == sy1: return # Compute sizes. csw = sx1 - sx0 csh = sy1 - sy0 cdw = dx1 - dx0 cdh = dy1 - dy0 if csw <= 0 or csh <= 0 or cdh <= 0 or cdw <= 0: return # Get a subsurface. cr = crend.subsurface((sx0, sy0, csw, csh)) # Scale or tile if we have to. if csw != cdw or csh != cdh: if self.tile: newcr = Render(cdw, cdh) newcr.xclipping = True newcr.yclipping = True for x in xrange(0, cdw, csw): for y in xrange(0, cdh, csh): newcr.blit(cr, (x, y)) cr = newcr else: newcr = Render(cdw, cdh) newcr.forward = Matrix2D(1.0 * csw / cdw, 0, 0, 1.0 * csh / cdh) newcr.reverse = Matrix2D(1.0 * cdw / csw, 0, 0, 1.0 * cdh / csh) newcr.blit(cr, (0, 0)) cr = newcr # Blit. rv.blit(cr, (dx0, dy0)) return rv = Render(dw, dh) self.draw_pattern(draw, left, top, right, bottom) return rv
def render(self, width, height, st, at): # Do we need to adjust the child times due to our being a layer? if self.layer_name or (self.layers is not None): adjust_times = True else: adjust_times = False minx = self.style.xminimum if minx is not None: width = max(width, scale(minx, width)) miny = self.style.yminimum if miny is not None: height = max(height, scale(miny, height)) if self.first: self.first = False if adjust_times: it = renpy.game.interface.interact_time self.start_times = [ i or it for i in self.start_times ] self.anim_times = [ i or it for i in self.anim_times ] layout = self.style.box_layout if layout is None: layout = self.default_layout self.layout = layout # W0201 else: layout = self.layout # Handle time adjustment, store the results in csts and cats. if adjust_times: t = renpy.game.interface.frame_time csts = [ t - start for start in self.start_times ] cats = [ t - anim for anim in self.anim_times ] else: csts = [ st ] * len(self.children) cats = [ at ] * len(self.children) offsets = [ ] if layout == "fixed": rv = None if self.style.order_reverse: iterator = zip(reversed(self.children), reversed(csts), reversed(cats)) else: iterator = zip(self.children, csts, cats) rv = renpy.display.render.Render(width, height, layer_name=self.layer_name) xfit = self.style.xfit yfit = self.style.yfit fit_first = self.style.fit_first if fit_first == "width": first_fit_width = True first_fit_height = False elif fit_first == "height": first_fit_width = False first_fit_height = True elif fit_first: first_fit_width = True first_fit_height = True else: first_fit_width = False first_fit_height = False sizes = [ ] for child, cst, cat in iterator: surf = render(child, width, height, cst, cat) size = surf.get_size() sizes.append(size) if first_fit_width: width = rv.width = size[0] first_fit_width = False if first_fit_height: height = rv.height = size[1] first_fit_height = False if surf: offset = child.place(rv, 0, 0, width, height, surf) offsets.append(offset) else: offsets.append((0, 0)) if xfit: width = 0 for o, s in zip(offsets, sizes): width = max(o[0] + s[0], width) if fit_first: break rv.width = width if width > renpy.config.max_fit_size: raise Exception("Fixed fit width ({}) is too large.".format(width)) if yfit: height = 0 for o, s in zip(offsets, sizes): height = max(o[1] + s[1], height) if fit_first: break rv.height = height if height > renpy.config.max_fit_size: raise Exception("Fixed fit width ({}) is too large.".format(height)) if self.style.order_reverse: offsets.reverse() self.offsets = offsets return rv # If we're here, we have a box, either horizontal or vertical. Which is good, # as we can share some code between boxes. spacing = self.style.spacing first_spacing = self.style.first_spacing if first_spacing is None: first_spacing = spacing spacings = [ first_spacing ] + [ spacing ] * (len(self.children) - 1) box_wrap = self.style.box_wrap xfill = self.style.xfill yfill = self.style.yfill xminimum = self.style.xminimum yminimum = self.style.yminimum # The shared height and width of the current line. The line_height must # be 0 for a vertical box, and the line_width must be 0 for a horizontal # box. line_width = 0 line_height = 0 # The children to layout. children = list(self.children) if self.style.box_reverse: children.reverse() spacings.reverse() # a list of (child, x, y, w, h, surf) tuples that are turned into # calls to child.place(). placements = [ ] # The maximum x and y. maxx = 0 maxy = 0 # The minimum size of x and y. minx = 0 miny = 0 def layout_line(line, xfill, yfill): """ Lays out a single line. `line` a list of (child, x, y, surf) tuples. `xfill` the amount of space to add in the x direction. `yfill` the amount of space to add in the y direction. """ xfill = max(0, xfill) yfill = max(0, yfill) if line: xperchild = xfill / len(line) yperchild = yfill / len(line) else: xperchild = 0 yperchild = 0 maxxout = maxx maxyout = maxy for i, (child, x, y, surf) in enumerate(line): sw, sh = surf.get_size() sw = max(line_width, sw) sh = max(line_height, sh) x += i * xperchild y += i * yperchild sw += xperchild sh += yperchild placements.append((child, x, y, sw, sh, surf)) maxxout = max(maxxout, x + sw) maxyout = max(maxyout, y + sh) return maxxout, maxyout x = 0 y = 0 if layout == "horizontal": if yfill: miny = height else: miny = yminimum line_height = 0 line = [ ] remwidth = width if xfill: target_width = width else: target_width = xminimum for d, padding, cst, cat in zip(children, spacings, csts, cats): if box_wrap: rw = width else: rw = remwidth surf = render(d, rw, height - y, cst, cat) sw, sh = surf.get_size() if box_wrap and remwidth - sw - padding < 0 and line: maxx, maxy = layout_line(line, target_width - x, 0) y += line_height x = 0 line_height = 0 remwidth = width line = [ ] line.append((d, x, y, surf)) line_height = max(line_height, sh) x += sw + padding remwidth -= (sw + padding) maxx, maxy = layout_line(line, target_width - x, 0) elif layout == "vertical": if xfill: minx = width else: minx = xminimum line_width = 0 line = [ ] remheight = height if yfill: target_height = height else: target_height = yminimum for d, padding, cst, cat in zip(children, spacings, csts, cats): if box_wrap: rh = height else: rh = remheight surf = render(d, width - x, rh, cst, cat) sw, sh = surf.get_size() if box_wrap and remheight - sh - padding < 0: maxx, maxy = layout_line(line, 0, target_height - y) x += line_width y = 0 line_width = 0 remheight = height line = [ ] line.append((d, x, y, surf)) line_width = max(line_width, sw) y += sh + padding remheight -= (sh + padding) maxx, maxy = layout_line(line, 0, target_height - y) else: raise Exception("Unknown box layout: %r" % layout) # Back to the common for vertical and horizontal. if not xfill: width = max(xminimum, maxx) if not yfill: height = max(yminimum, maxy) rv = renpy.display.render.Render(width, height) if self.style.box_reverse ^ self.style.order_reverse: placements.reverse() for child, x, y, w, h, surf in placements: w = max(minx, w) h = max(miny, h) offset = child.place(rv, x, y, w, h, surf) offsets.append(offset) if self.style.order_reverse: offsets.reverse() self.offsets = offsets return rv
def render(self, width, height, st, at): # For convenience and speed. padding = self.style.spacing cols = self.cols rows = self.rows if len(self.children) != cols * rows: if len(self.children) < cols * rows: raise Exception("Grid not completely full.") else: raise Exception("Grid overfull.") if self.transpose: children = [] for y in range(rows): for x in range(cols): children.append(self.children[y + x * rows]) else: children = self.children # Now, start the actual rendering. renwidth = width renheight = height if self.style.xfill: renwidth = (width - (cols - 1) * padding) / cols if self.style.yfill: renheight = (height - (rows - 1) * padding) / rows renders = [render(i, renwidth, renheight, st, at) for i in children] sizes = [i.get_size() for i in renders] cwidth = 0 cheight = 0 for w, h in sizes: cwidth = max(cwidth, w) cheight = max(cheight, h) if self.style.xfill: cwidth = renwidth if self.style.yfill: cheight = renheight width = cwidth * cols + padding * (cols - 1) height = cheight * rows + padding * (rows - 1) rv = renpy.display.render.Render(width, height) offsets = [] for y in range(0, rows): for x in range(0, cols): child = children[x + y * cols] surf = renders[x + y * cols] xpos = x * (cwidth + padding) ypos = y * (cheight + padding) offset = child.place(rv, xpos, ypos, cwidth, cheight, surf) offsets.append(offset) if self.transpose: self.offsets = [] for x in range(cols): for y in range(rows): self.offsets.append(offsets[y * cols + x]) else: self.offsets = offsets return rv
def render(self, width, height, st, at): if self.state: return render(self.child, width, height, st, at) else: return render(self.null, width, height, st, at)
def render(self, width, height, st, at): # Do we need to adjust the child times due to our being a layer? if self.layer_name or (self.layers is not None): adjust_times = True else: adjust_times = False xminimum = self.style.xminimum if xminimum is not None: width = max(width, scale(xminimum, width)) yminimum = self.style.yminimum if yminimum is not None: height = max(height, scale(yminimum, height)) if self.first: self.first = False if adjust_times: it = renpy.game.interface.interact_time - st self.start_times = [ i or it for i in self.start_times ] self.anim_times = [ i or it for i in self.anim_times ] layout = self.style.box_layout if layout is None: layout = self.default_layout self.layout = layout # W0201 else: layout = self.layout # Handle time adjustment, store the results in csts and cats. if adjust_times: t = renpy.game.interface.frame_time csts = [ t - start for start in self.start_times ] cats = [ t - anim for anim in self.anim_times ] else: csts = [ st ] * len(self.children) cats = [ at ] * len(self.children) self.offsets = [ ] if layout == "fixed": rv = None for child, cst, cat in zip(self.children, csts, cats): surf = render(child, width, height, cst, cat) if rv is None: if self.style.fit_first: sw, sh = surf.get_size() width = min(width, sw) height = min(height, sh) rv = renpy.display.render.Render(width, height, layer_name=self.layer_name) if surf: offset = child.place(rv, 0, 0, width, height, surf) self.offsets.append(offset) else: self.offsets.append((0, 0)) if rv is None: rv = renpy.display.render.Render(width, height, layer_name=self.layer_name) return rv # If we're here, we have a box, either horizontal or vertical. Which is good, # as we can share some code between boxes. spacing = self.style.spacing first_spacing = self.style.first_spacing if first_spacing is None: first_spacing = spacing spacings = [ first_spacing ] + [ spacing ] * (len(self.children) - 1) box_wrap = self.style.box_wrap xfill = self.style.xfill yfill = self.style.yfill # The shared height and width of the current line. The line_height must # be 0 for a vertical box, and the line_width must be 0 for a horizontal # box. line_width = 0 line_height = 0 # a list of (child, x, y, w, h, surf) tuples that are turned into # calls to child.place(). placements = [ ] # The maximum x and y. maxx = 0 maxy = 0 def layout_line(line, xfill, yfill): """ Lays out a single line. `line` a list of (child, x, y, surf) tuples. `xfill` the amount of space to add in the x direction. `yfill` the amount of space to add in the y direction. """ xfill = max(0, xfill) yfill = max(0, yfill) if line: xperchild = xfill / len(line) yperchild = yfill / len(line) else: xperchild = 0 yperchild = 0 maxxout = maxx maxyout = maxy for i, (child, x, y, surf) in enumerate(line): sw, sh = surf.get_size() sw = max(line_width, sw) sh = max(line_height, sh) x += i * xperchild y += i * yperchild sw += xperchild sh += yperchild placements.append((child, x, y, sw, sh, surf)) maxxout = max(maxxout, x + sw) maxyout = max(maxyout, y + sh) return maxxout, maxyout x = 0 y = 0 full_width = False full_height = False if layout == "horizontal": full_height = yfill line_height = 0 line = [ ] remwidth = width for d, padding, cst, cat in zip(self.children, spacings, csts, cats): if box_wrap: rw = width else: rw = remwidth surf = render(d, rw, height - y, cst, cat) sw, sh = surf.get_size() if box_wrap and remwidth - sw - padding <= 0 and line: maxx, maxy = layout_line(line, remwidth if xfill else 0, 0) y += line_height x = 0 line_height = 0 remwidth = width line = [ ] line.append((d, x, y, surf)) line_height = max(line_height, sh) x += sw + padding remwidth -= (sw + padding) maxx, maxy = layout_line(line, remwidth if xfill else 0, 0) elif layout == "vertical": full_width = xfill line_width = 0 line = [ ] remheight = height for d, padding, cst, cat in zip(self.children, spacings, csts, cats): if box_wrap: rh = height else: rh = remheight surf = render(d, width - x, rh, cst, cat) sw, sh = surf.get_size() if box_wrap and remheight - sh - padding <= 0: maxx, maxy = layout_line(line, 0, remheight if yfill else 0) x += line_width y = 0 line_width = 0 remheight = height line = [ ] line.append((d, x, y, surf)) line_width = max(line_width, sw) y += sh + padding remheight -= (sh + padding) maxx, maxy = layout_line(line, 0, remheight if yfill else 0) if not xfill: width = maxx if not yfill: height = maxy rv = renpy.display.render.Render(width, height) for child, x, y, w, h, surf in placements: if full_width: w = width if full_height: h = height offset = child.place(rv, x, y, w, h, surf) self.offsets.append(offset) return rv
def render(self, width, height, st, at): # save some typing. style = self.style xminimum = scale(style.xminimum, width) yminimum = scale(style.yminimum, height) size_group = self.style.size_group if size_group and size_group in size_groups: xminimum = max( xminimum, size_groups[size_group].width(width, height, st, at)) left_margin = scale(style.left_margin, width) left_padding = scale(style.left_padding, width) right_margin = scale(style.right_margin, width) right_padding = scale(style.right_padding, width) top_margin = scale(style.top_margin, height) top_padding = scale(style.top_padding, height) bottom_margin = scale(style.bottom_margin, height) bottom_padding = scale(style.bottom_padding, height) # c for combined. cxmargin = left_margin + right_margin cymargin = top_margin + bottom_margin cxpadding = left_padding + right_padding cypadding = top_padding + bottom_padding child = self.get_child() # Render the child. surf = render(child, width - cxmargin - cxpadding, height - cymargin - cypadding, st, at) sw, sh = surf.get_size() # If we don't fill, shrink our size to fit. if not style.xfill: width = max(cxmargin + cxpadding + sw, xminimum) if not style.yfill: height = max(cymargin + cypadding + sh, yminimum) if renpy.config.enforce_window_max_size: if style.xmaximum is not None: width = min(width, style.xmaximum) if style.ymaximum is not None: height = min(height, style.ymaximum) rv = renpy.display.render.Render(width, height) # Draw the background. The background should render at exactly the # requested size. (That is, be a Frame or a Solid). if style.background: bw = width - cxmargin bh = height - cymargin back = render(style.background, bw, bh, st, at) style.background.place(rv, left_margin, top_margin, bw, bh, back, main=False) offsets = child.place(rv, left_margin + left_padding, top_margin + top_padding, width - cxmargin - cxpadding, height - cymargin - cypadding, surf) # Draw the foreground. The background should render at exactly the # requested size. (That is, be a Frame or a Solid). if style.foreground: bw = width - cxmargin bh = height - cymargin back = render(style.foreground, bw, bh, st, at) style.foreground.place(rv, left_margin, top_margin, bw, bh, back, main=False) if self.child: self.offsets = [offsets] self.window_size = width, height # W0201 return rv
def render(self, width, height, st, at): if self.anim_timebase: t = at else: t = st if renpy.game.less_updates: if self.delay: t = self.delay if self.repeat: t = t % self.period else: t = self.period elif self.delay and t >= self.delay: t = self.delay if self.repeat: t = t % self.period elif self.repeat: t = t % self.period renpy.display.render.redraw(self, 0) else: if t > self.period: t = self.period else: renpy.display.render.redraw(self, 0) if self.period > 0: t /= self.period else: t = 1 if self.time_warp: t = self.time_warp(t) if self.bounce: t = t * 2 if t > 1.0: t = 2.0 - t child = render(self.child, width, height, st, at) cw, ch = child.get_size() if self.add_sizes: res = self.function(t, (width, height, cw, ch)) else: res = self.function(t) res = tuple(res) if len(res) == 2: self.position = res + (self.style.xanchor, self.style.yanchor) else: self.position = res rv = renpy.display.render.Render(cw, ch) rv.blit(child, (0, 0)) self.offsets = [ (0, 0) ] return rv
def render(self, width, height, st, at): if renpy.game.less_updates or renpy.display.less_imagedissolve: return null_render(self, width, height, st, at) if st >= self.delay: self.events = True return render(self.new_widget, width, height, st, at) image = render(self.image, width, height, st, at) bottom = render(self.old_widget, width, height, st, at) top = render(self.new_widget, width, height, st, at) width = min(bottom.width, top.width, image.width) height = min(bottom.height, top.height, image.height) rv = renpy.display.render.Render(width, height) complete = st / self.delay if self.time_warp is not None: complete = self.time_warp(complete) rv.operation = renpy.display.render.IMAGEDISSOLVE rv.operation_alpha = self.alpha or renpy.config.dissolve_force_alpha rv.operation_complete = complete rv.operation_parameter = self.ramplen if renpy.display.render.models: target = rv.get_size() if image.get_size() != target: image = image.subsurface((0, 0, width, height)) if top.get_size() != target: top = top.subsurface((0, 0, width, height)) if bottom.get_size() != target: bottom = bottom.subsurface((0, 0, width, height)) ramp = self.ramplen # Prevent a DBZ if the user gives us a 0 ramp. if ramp < 1: ramp = 1 # Compute the offset to apply to the alpha. start = -1.0 end = ramp / 256.0 offset = start + (end - start) * complete rv.mesh = True rv.add_shader("renpy.imagedissolve", ) rv.add_uniform("u_renpy_dissolve_offset", offset) rv.add_uniform("u_renpy_dissolve_multiplier", 256.0 / ramp) rv.add_property( "mipmap", renpy.config.mipmap_dissolves if (self.style.mipmap is None) else self.style.mipmap) rv.blit(image, (0, 0), focus=False, main=False) rv.blit(bottom, (0, 0), focus=False, main=False) rv.blit(top, (0, 0), focus=True, main=True) renpy.display.render.redraw(self, 0) return rv
def render(self, width, height, st, at): # Do we need to adjust the child times due to our being a layer? if self.layer_name or (self.layers is not None): adjust_times = True else: adjust_times = False minx = self.style.xminimum if minx is not None: width = max(width, scale(minx, width)) miny = self.style.yminimum if miny is not None: height = max(height, scale(miny, height)) if self.first: self.first = False if adjust_times: it = renpy.game.interface.interact_time self.start_times = [i or it for i in self.start_times] self.anim_times = [i or it for i in self.anim_times] layout = self.style.box_layout if layout is None: layout = self.default_layout self.layout = layout # W0201 else: layout = self.layout # Handle time adjustment, store the results in csts and cats. if adjust_times: t = renpy.game.interface.frame_time csts = [t - start for start in self.start_times] cats = [t - anim for anim in self.anim_times] else: csts = [st] * len(self.children) cats = [at] * len(self.children) offsets = [] if layout == "fixed": rv = None if self.style.order_reverse: iterator = zip(reversed(self.children), reversed(csts), reversed(cats)) else: iterator = zip(self.children, csts, cats) rv = renpy.display.render.Render(width, height, layer_name=self.layer_name) xfit = self.style.xfit yfit = self.style.yfit fit_first = self.style.fit_first if fit_first == "width": first_fit_width = True first_fit_height = False elif fit_first == "height": first_fit_width = False first_fit_height = True elif fit_first: first_fit_width = True first_fit_height = True else: first_fit_width = False first_fit_height = False sizes = [] for child, cst, cat in iterator: surf = render(child, width, height, cst, cat) size = surf.get_size() sizes.append(size) if first_fit_width: width = rv.width = size[0] first_fit_width = False if first_fit_height: height = rv.height = size[1] first_fit_height = False if surf: offset = child.place(rv, 0, 0, width, height, surf) offsets.append(offset) else: offsets.append((0, 0)) if xfit: width = 0 for o, s in zip(offsets, sizes): width = max(o[0] + s[0], width) if fit_first: break rv.width = width if width > renpy.config.max_fit_size: raise Exception( "Fixed fit width ({}) is too large.".format(width)) if yfit: height = 0 for o, s in zip(offsets, sizes): height = max(o[1] + s[1], height) if fit_first: break rv.height = height if height > renpy.config.max_fit_size: raise Exception( "Fixed fit width ({}) is too large.".format(height)) if self.style.order_reverse: offsets.reverse() self.offsets = offsets return rv # If we're here, we have a box, either horizontal or vertical. Which is good, # as we can share some code between boxes. spacing = self.style.spacing first_spacing = self.style.first_spacing if first_spacing is None: first_spacing = spacing spacings = [first_spacing] + [spacing] * (len(self.children) - 1) box_wrap = self.style.box_wrap xfill = self.style.xfill yfill = self.style.yfill xminimum = self.style.xminimum yminimum = self.style.yminimum # The shared height and width of the current line. The line_height must # be 0 for a vertical box, and the line_width must be 0 for a horizontal # box. line_width = 0 line_height = 0 # The children to layout. children = list(self.children) if self.style.box_reverse: children.reverse() spacings.reverse() # a list of (child, x, y, w, h, surf) tuples that are turned into # calls to child.place(). placements = [] # The maximum x and y. maxx = 0 maxy = 0 # The minimum size of x and y. minx = 0 miny = 0 def layout_line(line, xfill, yfill): """ Lays out a single line. `line` a list of (child, x, y, surf) tuples. `xfill` the amount of space to add in the x direction. `yfill` the amount of space to add in the y direction. """ xfill = max(0, xfill) yfill = max(0, yfill) if line: xperchild = xfill / len(line) yperchild = yfill / len(line) else: xperchild = 0 yperchild = 0 maxxout = maxx maxyout = maxy for i, (child, x, y, surf) in enumerate(line): sw, sh = surf.get_size() sw = max(line_width, sw) sh = max(line_height, sh) x += i * xperchild y += i * yperchild sw += xperchild sh += yperchild placements.append((child, x, y, sw, sh, surf)) maxxout = max(maxxout, x + sw) maxyout = max(maxyout, y + sh) return maxxout, maxyout x = 0 y = 0 if layout == "horizontal": if yfill: miny = height else: miny = yminimum line_height = 0 line = [] remwidth = width if xfill: target_width = width else: target_width = xminimum for d, padding, cst, cat in zip(children, spacings, csts, cats): if box_wrap: rw = width else: rw = remwidth surf = render(d, rw, height - y, cst, cat) sw, sh = surf.get_size() if box_wrap and remwidth - sw - padding < 0 and line: maxx, maxy = layout_line(line, target_width - x, 0) y += line_height x = 0 line_height = 0 remwidth = width line = [] line.append((d, x, y, surf)) line_height = max(line_height, sh) x += sw + padding remwidth -= (sw + padding) maxx, maxy = layout_line(line, target_width - x, 0) elif layout == "vertical": if xfill: minx = width else: minx = xminimum line_width = 0 line = [] remheight = height if yfill: target_height = height else: target_height = yminimum for d, padding, cst, cat in zip(children, spacings, csts, cats): if box_wrap: rh = height else: rh = remheight surf = render(d, width - x, rh, cst, cat) sw, sh = surf.get_size() if box_wrap and remheight - sh - padding < 0: maxx, maxy = layout_line(line, 0, target_height - y) x += line_width y = 0 line_width = 0 remheight = height line = [] line.append((d, x, y, surf)) line_width = max(line_width, sw) y += sh + padding remheight -= (sh + padding) maxx, maxy = layout_line(line, 0, target_height - y) else: raise Exception("Unknown box layout: %r" % layout) # Back to the common for vertical and horizontal. if not xfill: width = max(xminimum, maxx) if not yfill: height = max(yminimum, maxy) rv = renpy.display.render.Render(width, height) if self.style.box_reverse ^ self.style.order_reverse: placements.reverse() for child, x, y, w, h, surf in placements: w = max(minx, w) h = max(miny, h) offset = child.place(rv, x, y, w, h, surf) offsets.append(offset) if self.style.order_reverse: offsets.reverse() self.offsets = offsets return rv
def render(self, width, height, st, at): if self.anim_timebase: t = at else: t = st if renpy.game.less_updates: if self.delay: t = self.delay if self.repeat: t = t % self.period else: t = self.period elif self.delay and t >= self.delay: t = self.delay if self.repeat: t = t % self.period elif self.repeat: t = t % self.period renpy.display.render.redraw(self, 0) else: if t > self.period: t = self.period else: renpy.display.render.redraw(self, 0) if self.period > 0: t /= self.period else: t = 1 if self.time_warp: t = self.time_warp(t) if self.bounce: t = t * 2 if t > 1.0: t = 2.0 - t child = render(self.child, width, height, st, at) cw, ch = child.get_size() if self.add_sizes: res = self.function(t, (width, height, cw, ch)) else: res = self.function(t) res = tuple(res) if len(res) == 2: self.position = res + (self.style.xanchor, self.style.yanchor) else: self.position = res rv = renpy.display.render.Render(cw, ch) rv.blit(child, (0, 0)) self.offsets = [(0, 0)] return rv