{"action":"reopened","issue":{"url":"https://api.github.com/repos/Bodmer/TFT_eSPI/issues/62","repository_url":"https://api.github.com/repos/Bodmer/TFT_eSPI","labels_url":"https://api.github.com/repos/Bodmer/TFT_eSPI/issues/62/labels{/name}","comments_url":"https://api.github.com/repos/Bodmer/TFT_eSPI/issues/62/comments","events_url":"https://api.github.com/repos/Bodmer/TFT_eSPI/issues/62/events","html_url":"https://github.com/Bodmer/TFT_eSPI/issues/62","id":279673621,"number":62,"title":"[Enhancement] Shift a sprite left or right","user":{"login":"beegee-tokyo","id":512690,"avatar_url":"https://avatars3.githubusercontent.com/u/512690?v=4","gravatar_id":"","url":"https://api.github.com/users/beegee-tokyo","html_url":"https://github.com/beegee-tokyo","followers_url":"https://api.github.com/users/beegee-tokyo/followers","following_url":"https://api.github.com/users/beegee-tokyo/following{/other_user}","gists_url":"https://api.github.com/users/beegee-tokyo/gists{/gist_id}","starred_url":"https://api.github.com/users/beegee-tokyo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beegee-tokyo/subscriptions","organizations_url":"https://api.github.com/users/beegee-tokyo/orgs","repos_url":"https://api.github.com/users/beegee-tokyo/repos","events_url":"https://api.github.com/users/beegee-tokyo/events{/privacy}","received_events_url":"https://api.github.com/users/beegee-tokyo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-12-06T08:57:25Z","updated_at":"2017-12-09T23:28:30Z","closed_at":null,"author_association":"NONE","body":"I am working on a function to display temperature values as a graph on the display. And I wanted to shift(scroll???) the graph when the screen is filled and add the new data at the end. \r\nMy display (ILI9163) has no function to shift the screen content or read back the content of the screen.\r\n\r\nI decided to work with a sprite, but the library has neither a function to read back the sprite content for changing nor a shift(scroll???) function.\r\n\r\nTo achieve what I want, I added 2 sprite functions to the library, **`shiftRectLeft()`** and **`shiftRectRight()`**\r\nMaybe you want to add these to the library.\r\nTested only with an [ILI9163 128x128 TFT](https://www.elecrow.com/144-128x-128-tft-lcd-with-spi-interface-p-855.html)  display and an ESP32.\r\n\r\nThe declarations:\r\n```cpp\r\n           // Shift the sprite <shift> pixels to the left and fill right side with <color>\r\n  void     shiftRectLeft(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t shift, uint32_t color);\r\n           // Shift the sprite <shift> pixels to the right and fill left side with <color>\r\n  void     shiftRectRight(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t shift, uint32_t color);\r\n```\r\nThe functions:\r\n```cpp\r\n/***************************************************************************************\r\n** Function name:           shiftRectLeft\r\n** Description:             shifts sprite left and fill right side with given color\r\n***************************************************************************************/\r\nvoid  TFT_eSprite::shiftRectLeft(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t shift, uint32_t color)\r\n{\r\n  if ((x > _iwidth) || (y > _iheight) || (w == 0) || (h == 0) || !_created) return;\r\n\r\n  for (uint32_t yp = y; yp < y + h; yp++)\r\n  {\r\n    for (uint32_t xp = x + shift; xp < x + w; xp++)\r\n    {\r\n      _img[xp-shift + yp * _iwidth] = _img[xp + yp * _iwidth];\r\n    }\r\n    for (uint32_t xp = x + w; xp < x + w + shift; xp++)\r\n    {\r\n      if (_bpp16)\r\n      {\r\n          _img[xp-shift + yp * _iwidth] = (uint16_t) (color >> 8) | (color << 8);\r\n      }\r\n      else\r\n      {\r\n        _img[xp-shift + yp * _iwidth] = (uint8_t)((color & 0xE000)>>8 | (color & 0x0700)>>6 | (color & 0x0018)>>3);\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n/***************************************************************************************\r\n** Function name:           shiftRectRight\r\n** Description:             shifts sprite right and fill left side with given color\r\n***************************************************************************************/\r\nvoid  TFT_eSprite::shiftRectRight(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t shift, uint32_t color)\r\n{\r\n  if ((x > _iwidth) || (y > _iheight) || (w == 0) || (h == 0) || !_created) return;\r\n\r\n  for (uint32_t yp = y; yp < y + h; yp++)\r\n  {\r\n    for (uint32_t xp = x + w - 1; xp != x; xp--)\r\n    {\r\n      _img[xp + yp * _iwidth] = _img[xp-shift + yp * _iwidth];\r\n    }\r\n    for (uint32_t xp = x; xp < x + shift; xp++)\r\n    {\r\n      if (_bpp16)\r\n      {\r\n          _img[xp + yp * _iwidth] = (uint16_t) (color >> 8) | (color << 8);\r\n      }\r\n      else\r\n      {\r\n        _img[xp + yp * _iwidth] = (uint8_t)((color & 0xE000)>>8 | (color & 0x0700)>>6 | (color & 0x0018)>>3);\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\nExample of usage:\r\n```cpp\r\n#include <Arduino.h>\r\n#include <TFT_eSPI.h>\r\n\r\n/** TFT_eSPI class for display */\r\nTFT_eSPI tft = TFT_eSPI();\r\n/** Sprite needed for graph scrolling */\r\nTFT_eSprite graph1 = TFT_eSprite(&tft);\r\n/** Sprite needed for graph scrolling */\r\nTFT_eSprite graph2 = TFT_eSprite(&tft);\r\n/** Value for graph1 */\r\nint graph1Val = 1;\r\n/** Value for graph2 */\r\nint graph2Val = 1;\r\n\r\nvoid setup() {\r\n  tft.init();\r\n  tft.fillScreen(TFT_BLACK);\r\n  graph1.createSprite(128, 64);\r\n  graph1.fillSprite(TFT_BLACK);\r\n  graph2.createSprite(128, 64);\r\n  graph2.fillSprite(TFT_BLACK);\r\n}\r\n\r\nvoid loop() {\r\n  graph1.shiftRectLeft(0, 0, 128, 64, 1, TFT_BLACK);\r\n  graph1.drawFastVLine(127,64-graph1Val,graph1Val,TFT_YELLOW);\r\n  graph2.shiftRectRight(0, 0, 128, 64, 1, TFT_BLACK);\r\n  graph2.drawFastVLine(0,64-graph2Val,graph2Val,TFT_RED);\r\n\r\n  graph1.pushSprite(0, 32);\r\n  graph2.pushSprite(0, 96);\r\n\r\n  graph1Val++;\r\n  graph2Val++;\r\n  if (graph1Val == 65) graph1Val = 1;\r\n  if (graph2Val == 65) graph2Val = 1;\r\n  delay(50);\r\n}\r\n```\r\nThis example draws two sawtooth graphs, One scrolling from right to left, the other one opposite.\r\n"}}
{"actor":{"display_login":"Bodmer"}}