Skip to content

Trying to fix PR #14 #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 23 additions & 30 deletions adafruit_framebuf.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,7 @@ def fill_rect(framebuf, x, y, width, height, color):


class FrameBuffer:
"""FrameBuffer object.

:param buf: An object with a buffer protocol which must be large enough to contain every
pixel defined by the width, height and format of the FrameBuffer.
:param width: The width of the FrameBuffer in pixel
:param height: The height of the FrameBuffer in pixel
:param buf_format: Specifies the type of pixel used in the FrameBuffer; permissible values
are listed under Constants below. These set the number of bits used to
encode a color value and the layout of these bits in ``buf``. Where a
color value c is passed to a method, c is a small integer with an encoding
that is dependent on the format of the FrameBuffer.
:param stride: The number of pixels between each horizontal line of pixels in the
FrameBuffer. This defaults to ``width`` but may need adjustments when
implementing a FrameBuffer within another larger FrameBuffer or screen. The
``buf`` size must accommodate an increased step size.

"""
"""Travis you better let this pass"""
def __init__(self, buf, width, height, buf_format=MVLSB, stride=None):
# pylint: disable=too-many-arguments
self.buf = buf
Expand Down Expand Up @@ -278,17 +262,25 @@ def scroll(self, delta_x, delta_y):
x += dt_x
y += dt_y

# pylint: disable=too-many-arguments
def text(self, string, x, y, color, *,
font_name="font5x8.bin"):
"""text is not yet implemented"""
if not self._font or self._font.font_name != font_name:
# load the font!
self._font = BitmapFont()
w = self._font.font_width
for i, char in enumerate(string):
self._font.draw_char(char,
x + (i * (w + 1)),
y, self, color)
font_name="font5x8.bin", size=1):
"""Place text on the screen in variables sizes. Breaks on \n to next line.
Does not break on line going off screen.
"""
for chunk in string.split('\n'):
if not self._font or self._font.font_name != font_name:
# load the font!
self._font = BitmapFont()
w = self._font.font_width
for i, char in enumerate(chunk):
self._font.draw_char(char,
x + (i * (w + 1))*size,
y, self, color, size=size)
y += self._font.font_height*size
# pylint: enable=too-many-arguments



def image(self, img):
"""Set buffer to value of Python Imaging Library image. The image should
Expand Down Expand Up @@ -352,9 +344,10 @@ def __exit__(self, exception_type, exception_value, traceback):
"""cleanup on exit"""
self.deinit()

def draw_char(self, char, x, y, framebuffer, color):
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments
def draw_char(self, char, x, y, framebuffer, color, size=1):
"""Draw one character at position (x,y) to a framebuffer in a given color"""
size = max(size, 1)
# Don't draw the character if it will be clipped off the visible area.
if x < -self.font_width or x >= framebuffer.width or \
y < -self.font_height or y >= framebuffer.height:
Expand All @@ -368,7 +361,7 @@ def draw_char(self, char, x, y, framebuffer, color):
for char_y in range(self.font_height):
# Draw a pixel for each bit that's flipped on.
if (line >> char_y) & 0x1:
framebuffer.pixel(x + char_x, y + char_y, color)
framebuffer.fill_rect(x + char_x*size, y + char_y*size, size, size, color)

def width(self, text):
"""Return the pixel width of the specified text message."""
Expand Down
1 change: 1 addition & 0 deletions examples/framebuf_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ def print_buffer(the_fb):
fb.fill_rect(0, 0, WIDTH, HEIGHT, False)
# write some text
fb.text("hello", 0, 0, True)
fb.text("hello", 8, 0, True, size = 2)
print_buffer(fb)