Announcement

Collapse
No announcement yet.

Issue with drawing rectangles and coding questions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issue with drawing rectangles and coding questions

    I have written some code that draws a rectangle, but I'm finding that if I only draw once to the main function it draws and quickly disappears, if I loop it forever the rectanlge draws and then redraws causing a blinking effect. Is it possible to get the rectangle to not blink?

    Also, is there support for switch statements yet?

  • #2


    I think the module will reset when the main function ends. So, if you don't have that loop, the rectangle will be drawn but then, due to the reset, the screen will be cleared.
    So you might just draw the rectangle once and then enter a (empty) loop.

    Comment


    • #3


      If the main() function contains a forever loop then the function shouldn't end correct? If that is the case then that is how my code is currently setup.

      Comment


      • #4


        Perhaps you could post the code.....
        _______________
        Best Regards,
        Howard

        Comment


        • #5


          Will do when I am home later this evening.

          Comment


          • #6
            Here is the code

            Code:
            #platform "uOLED-32024-P1T"/* ****************************************** MasterKeg Control System* Version:  1.0* Author:   Jesse Koester* Created:  25 FEB 2010* Desc:     Menu and display system that controls a kegorator.****************************************** */// MENUS.DAT and MENUS.GCI are install on th FAT16 formatted uSD card#inherit "4DGL_16bitColours.fnc"#constant OK   1#constant FAIL 0// Menu Constants#constant SPLASH    0#constant MAIN      1var p;                          // buffer pointervar menu_img;                   // handle for the image listvar n, exit, r;var cMenu;                      // Track current menuvar co2Refresh;var temp[3];     // a place for up to 40 charactersvar tap1[50], tap2[50], tap3[50], tap4[50], tap5[50], tap6[50];//=======================================================================//---------------------------------------------------------------------------------------// return true if screen touched, also sets ok flagfunc CheckTouchExit()return (exit := (touch_Get(TOUCH_STATUS) == TOUCH_PRESS));   // if there's a press, exitendfunc//---------------------------------------------------------------------------------------func changeMenu(var menuId)gfx_Cls();cMenu := menuId;endfuncfunc showImage(var imgArray, var imgId, var xPos, var yPos)img_Show(imgArray, imgId);img_SetPosition(imgArray, imgId, 0, 0);endfuncfunc tapButtons(var menuId1, var menuId2)if(touch_Get(TOUCH_STATUS) == TOUCH_PRESS )if((touch_Get(1) > 10 &amp;&amp; touch_Get(1) < 146) &amp;&amp; (touch_Get(2) > 272 &amp;&amp; touch_Get(2) < 320))changeMenu(menuId1);else if((touch_Get(1) > 154 &amp;&amp; touch_Get(1) < 230) &amp;&amp; (touch_Get(2) > 272 &amp;&amp; touch_Get(2) < 320))changeMenu(menuId2);endifendifendfuncfunc main()tap1[0] := "Ir";tap1[1] := "is";tap1[2] := "h ";cMenu := 0;co2Refresh := 1;touch_Set(TOUCH_ENABLE);                               // enable the touch screenr := OK; // return valueexit := 0;if (!file_Mount())print("File error ", file_Error());while(!CheckTouchExit());  // just hang if we didnt get the image listr := FAIL;goto quit;endif// fast build, slow execution, lower memory requirement//img := file_LoadImageControl("test1.dat", "test1.gci", 0);  // build the image control, returning a pointer to the structure allocation// slow build, fast execution, higher memory requirementmenu_img := file_LoadImageControl("MENUS.dat", "MENUS.gci", 1);  // build the image control, returning a pointer to the structure allocationif (menu_img)print("image control=",[HEX] menu_img,"\n");  // show the address of the image control allocationelseputstr("Failed to build image control....\n");while(CheckTouchExit() == 0);  // just hang if we didnt get the image listr := FAIL;goto quit;endifgfx_Cls();repeat// Set Full Screen Touch Regiontouch_DetectRegion(0, 0, 240, 320);if(cMenu == 0)// Build Splash Screen MenushowImage(menu_img, 0, 0, 0);if(touch_Get(TOUCH_STATUS) == TOUCH_PRESS )changeMenu(1);endifn := 0;else if(cMenu == 1)temp[0] := '74';txt_MoveCursor(6, 4);           // move the cursor to line 4, column 5txt_Set(TEXT_COLOUR, RED);txt_Set(FONT_SIZE, 3);putstr(temp);gfx_Rectangle(60, 155, 215, 165, GREEN);gfx_Rectangle(14, 185, 24, 245, GREEN);gfx_Rectangle(92, 185, 102, 245, GREEN);gfx_Rectangle(169, 185, 179, 245, GREEN);gfx_Rectangle(14, 250, 24, 310, GREEN);gfx_Rectangle(92, 250, 102, 310, GREEN);gfx_Rectangle(169, 250, 179, 310, GREEN);showImage(menu_img, 1, 0, 0);// Set Touch sense for each button// C02 Level Button// Tap 1 Buttonif(touch_Get(TOUCH_STATUS) == TOUCH_PRESS )if((touch_Get(1) > 10 &amp;&amp; touch_Get(1) < 75) &amp;&amp; (touch_Get(2) > 185 &amp;&amp; touch_Get(2) < 245))changeMenu(2);else if((touch_Get(1) > 85 &amp;&amp; touch_Get(1) < 153) &amp;&amp; (touch_Get(2) > 185 &amp;&amp; touch_Get(2) < 245))changeMenu(3);else  if((touch_Get(1) > 163 &amp;&amp; touch_Get(1) < 230) &amp;&amp; (touch_Get(2) > 185 &amp;&amp; touch_Get(2) < 245))changeMenu(4);else if((touch_Get(1) > 10 &amp;&amp; touch_Get(1) < 75) &amp;&amp; (touch_Get(2) > 250 &amp;&amp; touch_Get(2) < 320))changeMenu(5);else if((touch_Get(1) > 85 &amp;&amp; touch_Get(1) < 153) &amp;&amp; (touch_Get(2) > 250 &amp;&amp; touch_Get(2) < 320))changeMenu(6);else if((touch_Get(1) > 163 &amp;&amp; touch_Get(1) < 230) &amp;&amp; (touch_Get(2) > 250 &amp;&amp; touch_Get(2) < 320))changeMenu(7);else if((touch_Get(1) > 125 &amp;&amp; touch_Get(1) < 230) &amp;&amp; (touch_Get(2) > 30 &amp;&amp; touch_Get(2) < 135))changeMenu(8);endifendifn := 0;else if(cMenu == 2)txt_MoveCursor(6, 4);           // move the cursor to line 4, column 5txt_Set(TEXT_COLOUR, BLACK);txt_Set(FONT_SIZE, 3);putstr(tap1);showImage(menu_img, 2, 0, 0);tapButtons(1,1);else if(cMenu == 3)showImage(menu_img, 3, 0, 0);tapButtons(1,1);else if(cMenu == 4)showImage(menu_img, 4, 0, 0);tapButtons(1,1);else if(cMenu == 5)showImage(menu_img, 5, 0, 0);tapButtons(1,1);else if(cMenu == 6)showImage(menu_img, 6, 0, 0);tapButtons(1,1);else if(cMenu == 7)showImage(menu_img, 7, 0, 0);tapButtons(1,1);else if(cMenu == 8)if(touch_Get(TOUCH_STATUS) == TOUCH_PRESS )changeMenu(1);endifprint("TEMP CONTROL\n");endifforeverquit:mem_Free(menu_img);      // release the image controlfile_Unmount();     // (program must release all resources)return r;endfunc

            Comment


            • #7


              Any suggestions?

              Comment


              • #8


                I didnt think the was an else if statement as you are using it -

                Comment


                • #9


                  You are correct I looked at the code library and there isnt an else if, however it does still switch out the images.

                  I tested it outside of the if statement and it still blinks.

                  Comment


                  • #10


                    cant test (display at work) - will try and test tomorrow - but still think the if statements will cause a problem ( have you taken them all out) - on a side note - in your change menu routine would you not be better to put the touch_Get(1) & touch_Get(2) to variables and not keep calling the routine? - send me your graphics files if you get a chance

                    Comment


                    • #11


                      the blinking makes me suspect that changeMenu() gets called where it shouldn't, because that's the only place (apart from the init) where you do a gfx_Cls(). alternating gfx_Cls() and drawing ops will cause flickering...

                      Comment


                      • #12


                        One handy trick is to put code to toggle pins at certain points in your code, then to monitor with a scope.....
                        _______________
                        Best Regards,
                        Howard

                        Comment

                        Working...
                        X