def __init__(бре, површ, положај, шкработине, име_боје): print("РамОдСлике __init__", име_боје) бре.положај = положај # претпоставка је да се положај мења споља бре.површ = површ бре.пуо = sdl2.SDL_Rect() бре.пуо.x = 0 бре.пуо.y = 0 бре.пуо.w = 16 бре.пуо.h = 16 средина = sdl2.SDL_Rect() средина.x = 3 средина.y = 3 средина.w = 10 средина.h = 10 бре.плава = sdl2.SDL_CreateRGBSurfaceWithFormat( 0, 16, 16, 32, sdl2.SDL_PIXELFORMAT_RGBA32) sdl2.SDL_SetSurfaceBlendMode(бре.плава, sdl2.SDL_BLENDMODE_BLEND) sdl2.SDL_FillRect(бре.плава, бре.пуо, инт_боја(бре.плава.contents.format, БОЈЕ[име_боје])) sdl2.SDL_FillRect( бре.плава, средина, инт_боја(бре.плава.contents.format, БОЈЕ['transparent'])) бре.шкработине = шкработине бре.шкработине.додај(2, бре)
def fill(self, color, rect=None, special_flags=0): """...""" sfc = self.surface fmt = sfc.format.contents color = Color(*color) pixel = sdl2.SDL_MapRGBA(fmt, color.r, color.g, color.b, color.a) if rect is not None: sdl_rect = to_sdl_rect(rect) if sdl_rect.x < 0: sdl_rect.w = sdl_rect.w + sdl_rect.x sdl_rect.x = 0 if sdl_rect.y < 0: sdl_rect.w = sdl_rect.h + sdl_rect.y sdl_rect.y = 0 if sdl_rect.w <= 0 or sdl_rect.h <= 0: return Rect(0, 0, 0, 0) err = sdl2.SDL_FillRect(self.surface, sdl_rect, pixel) if err: raise sdl2.SDLError() return Rect(sdl_rect.x, sdl_rect.y, sdl_rect.w, sdl_rect.h) else: err = sdl2.SDL_FillRect(self.surface, None, pixel) if err: raise sdl2.SDLError() return Rect(0, 0, self.w, self.h)
def _do_flip(self): """Draw the canvas to the screen.""" sdl2.SDL_FillRect(self.work_surface, None, self.border_attr) if self.composite_artifacts: self.work_pixels[:] = video_graphical.apply_composite_artifacts( self.pixels[self.vpagenum], 4 // self.bitsperpixel) sdl2.SDL_SetSurfacePalette(self.work_surface, self.composite_palette) else: self.work_pixels[:] = self.pixels[self.vpagenum] sdl2.SDL_SetSurfacePalette(self.work_surface, self.show_palette[self.blink_state]) # apply cursor to work surface self._show_cursor(True) # convert 8-bit work surface to (usually) 32-bit display surface format pixelformat = self.display_surface.contents.format conv = sdl2.SDL_ConvertSurface(self.work_surface, pixelformat, 0) # scale converted surface and blit onto display if not self.smooth: sdl2.SDL_BlitScaled(conv, None, self.display_surface, None) else: # smooth-scale converted surface w, h = self.window_width, self.window_height zoomx = ctypes.c_double(w / (self.size[0] + 2.0 * self.border_x)) zoomy = ctypes.c_double(h / (self.size[1] + 2.0 * self.border_y)) # only free the surface just before zoomSurface needs to re-allocate # so that the memory block is highly likely to be easily available # this seems to avoid unpredictable delays sdl2.SDL_FreeSurface(self.zoomed) self.zoomed = sdl2.sdlgfx.zoomSurface(conv, zoomx, zoomy, sdl2.sdlgfx.SMOOTHING_ON) # blit onto display sdl2.SDL_BlitSurface(self.zoomed, None, self.display_surface, None) # create clipboard feedback if self.clipboard.active(): rects = (sdl2.SDL_Rect(r[0] + self.border_x, r[1] + self.border_y, r[2], r[3]) for r in self.clipboard.selection_rect) sdl_rects = (sdl2.SDL_Rect * len(self.clipboard.selection_rect))(*rects) sdl2.SDL_FillRect( self.overlay, None, sdl2.SDL_MapRGBA(self.overlay.contents.format, 0, 0, 0, 0)) sdl2.SDL_FillRects( self.overlay, sdl_rects, len(sdl_rects), sdl2.SDL_MapRGBA(self.overlay.contents.format, 128, 0, 128, 0)) sdl2.SDL_BlitScaled(self.overlay, None, self.display_surface, None) # flip the display sdl2.SDL_UpdateWindowSurface(self.display) # destroy the temporary surface sdl2.SDL_FreeSurface(conv)
def put_glyph(self, pagenum, row, col, cp, is_fullwidth, fore, back, blink, underline, for_keys): """Put a character at a given position.""" if not self.text_mode: # in graphics mode, a put_rect call does the actual drawing return attr = fore + self.num_fore_attrs*back + 128*blink x0, y0 = (col-1)*self.font_width, (row-1)*self.font_height # NOTE: in pygame plugin we used a surface fill for the NUL character # which was an optimisation early on -- consider if we need speedup. try: glyph = self.glyph_dict[cp] except KeyError: logging.warning('No glyph received for code point %s', cp.encode('hex')) try: glyph = self.glyph_dict['\0'] except KeyError: logging.error('No glyph received for code point 0') return # pixels2d uses column-major mode and hence [x][y] indexing (we can change this) glyph_width = glyph.shape[0] # changle glyph color by numpy scalar mult (is there a better way?) self.pixels[pagenum][ x0:x0+glyph_width, y0:y0+self.font_height] = ( glyph*(attr-back) + back) if underline: sdl2.SDL_FillRect( self.canvas[self.apagenum], sdl2.SDL_Rect(x0, y0 + self.font_height - 1, glyph_width, 1), attr) self.screen_changed = True
def clear_rows(self, back_attr, start, stop): """Clear a range of screen rows.""" scroll_area = sdl2.SDL_Rect( 0, (start-1)*self.font_height, self.size[0], (stop-start+1)*self.font_height) sdl2.SDL_FillRect(self.canvas[self.apagenum], scroll_area, back_attr) self.screen_changed = True
def _show_cursor(self, do_show): """Draw or remove the cursor on the visible page.""" if not self.cursor_visible or self.vpagenum != self.apagenum: return screen = self.work_surface pixels = self.work_pixels top = (self.cursor_row-1) * self.font_height left = (self.cursor_col-1) * self.font_width if not do_show: pixels[left : left+self.font_width, top : top+self.font_height ] = self.under_cursor return # copy area under cursor self.under_cursor = numpy.copy( pixels[left : left+self.font_width, top : top+self.font_height]) if self.text_mode: # cursor is visible - to be done every cycle between 5 and 10, 15 and 20 if self._cycle/self.blink_cycles in (1, 3): curs_height = min(self.cursor_to - self.cursor_from+1, self.font_height - self.cursor_from) curs_rect = sdl2.SDL_Rect( self.border_x + left, self.border_y + top + self.cursor_from, self.cursor_width, curs_height) sdl2.SDL_FillRect(screen, curs_rect, self.cursor_attr) else: pixels[ left : left+self.cursor_width, top + self.cursor_from : top + self.cursor_to + 1 ] ^= self.cursor_attr self.last_row = self.cursor_row self.last_col = self.cursor_col
def fill_interval(self, pagenum, x0, x1, y, index): """Fill a scanline interval in a solid attribute.""" rect = sdl2.SDL_Rect(x0, y, x1-x0+1, 1) sdl2.SDL_FillRect(self.canvas[pagenum], rect, index) self.screen_changed = True
def fill_rect(self, pagenum, x0, y0, x1, y1, index): """Fill a rectangle in a solid attribute.""" rect = sdl2.SDL_Rect(x0, y0, x1-x0+1, y1-y0+1) sdl2.SDL_FillRect(self.canvas[pagenum], rect, index) self.screen_changed = True