achimdoebler/UGUI

where is the sample code for usage?

heihuhu310 opened this issue · 5 comments

good job, thanks for yours ugui!

Hey @RuyiDu , not sure if you're still looking for an answer to this question (which I think is a valid one). I just got uGUI running on my STM32F746-Discovery board. Here's the code I used (sorry if the formatting doesn't show correctly):

#include "stm32_BSP.h   // Or whatever else you need to include for your BSP/processor
#include "ugui.h"

void UserSetPixel (UG_S16 x, UG_S16 y, UG_COLOR c) {
  /*
   * This line is specific to your board and libraries, and will need to be changed unless
   * you're using STM32Cube's BSP for the STM32F7 Disco Board. If not, you can remove
   * the "0xFF000000 |" part, it's just a way to fix uGUI not currently supporting the alpha channel.
   */
  BSP_LCD_DrawPixel(x, y, 0xFF000000 | c);
}

int main(void)
{
  /* Configure uGUI */
  UG_Init(&gui, UserSetPixel , 480, 272);

  /* Draw text with uGUI */
  UG_FontSelect(&FONT_8X14);
  UG_ConsoleSetArea(0, 60, 480, 212);
  UG_ConsoleSetBackcolor(C_BLACK);
  UG_ConsoleSetForecolor(C_RED);
  UG_ConsolePutString("Beginning System Initialization...\n");
  UG_ConsoleSetForecolor(C_GREEN);
  UG_ConsolePutString("System Initialization Complete\n");

  while (1 == 1) {
    // Do stuff here I guess?
  }

  return 0;
}

Btw, a lot of this is detailed at length in the PDF supplied with the SourceForge distribution (I'm using v0.3). Make sure to give it a read for clarity!

I have a suggestion. When calling the pset() function, the code selects pset(fc) or pset(bc). These calls could be replaced with pfc() and pbc(). pfc() and pbc() would be almost identical, with pfc() using the foreground color and pbc() the background color. The code becomes smaller and faster.

With this change all code runs (quite a bit) faster, but monochrome would go from second class citizen to first class, with excellent performance. pfc() andpbc() could be inlined (possibly through defines), removing the calls entirely.

I'll make this change myself, as it is so easy to do (merit of uGui). I hope to post back when the code is running. btw, thanks for a great lib :)

please use spaces not TABs, certainly don't mix them.

it seems my suggestion won't pan out, there are too many uses of pset that this is more complicated than expected.

Code is not working for ambiq microcontrollers