Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Copyright 2012 Juan José Sánchez Ramírez
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- Author Juan José Sánchez Ramírez
- Version 1.0
- */
- #include "DragonFireSDK.h"
- #include "Scroller.h"
- #include "ScrollButton.h"
- enum Screen
- {
- SCREEN_1,
- SCREEN_2,
- SCREEN_3
- };
- Screen nCurrentScreen = SCREEN_1;
- Scroller scroller1;
- Scroller scroller2;
- Scroller scroller3;
- ScrollButton aScrollerButton[20];
- int nContainer1;
- int nContainer2;
- int nContainer3;
- int nGUIContainer;
- int nFont;
- int nHeaderFont;
- int nHeaderFontH;
- int nHeaderFontS;
- // This function adds text with a 1px highlight and a 1px shadow
- void HeaderTextAdd(int container, int x, int y, char* text)
- {
- TextAdd(container, x, y-1, text, nHeaderFontS);
- TextAdd(container, x, y+1, text, nHeaderFontH);
- TextAdd(container, x, y, text, nHeaderFont);
- }
- // This function moves a page left
- void MoveLeft(Scroller &scroller)
- {
- scroller.SetMinX(-320);
- scroller.SetMaxX(-320);
- scroller.SetActive(false);
- }
- // This function moves a page right
- void MoveRight(Scroller &scroller)
- {
- scroller.SetMinX(320);
- scroller.SetMaxX(320);
- scroller.SetActive(false);
- }
- // This function centers a page
- void CenterPage(Scroller &scroller)
- {
- scroller.SetMinX(0);
- scroller.SetMaxX(0);
- scroller.SetActive(true);
- }
- // This function refreshes the screen
- void UpdateScreen()
- {
- switch(nCurrentScreen)
- {
- case 0:
- CenterPage(scroller1);
- break;
- case 1:
- CenterPage(scroller2);
- break;
- case 2:
- CenterPage(scroller3);
- break;
- };
- }
- // This function will be called when a scroller button is pressed
- int OnButton(int id)
- {
- if (id == 201) // Button on page 3
- {
- ContainerSetx(nContainer2, 0);
- MoveRight(scroller2);
- MoveRight(scroller3);
- nCurrentScreen = SCREEN_1;
- }
- else if (id == 101) // Button on page 2
- {
- MoveLeft(scroller2);
- nCurrentScreen = SCREEN_3;
- }
- else // Buttons on page 1
- {
- MoveLeft(scroller1);
- nCurrentScreen = SCREEN_2;
- }
- UpdateScreen();
- return id;
- }
- // This function marks the beginning of program execution
- void AppMain()
- {
- nContainer1 = ContainerAdd(0, 0, 0);
- nContainer2 = ContainerAdd(0, 320, 0); // Container to the right
- nContainer3 = ContainerAdd(0, 320, 0); // Container to the right
- nGUIContainer = ContainerAdd(0, 0, 0);
- nFont = FontAdd("Helvetica", "Regular", 18, 0x333333);
- nHeaderFont = FontAdd("Helvetica", "Bold", 30, 0xFFFFFF);
- nHeaderFontS = FontAdd("Helvetica", "Bold", 30, 0x333333);
- nHeaderFontH = FontAdd("Helvetica", "Bold", 30, 0x999999);
- // Initiate scroller 320x1096, ID 0, horizontal scroll false
- scroller1.Init(nContainer1, 320, 1096, 0);
- scroller1.SetHorizontalScroll(false);
- // Populate container 1
- ViewAdd(nContainer1, "Images/Wood.png", 0, 0);
- HeaderTextAdd(nContainer1, 8, 76, "First Page");
- for (int i=0; i<20; i++)
- {
- char filename[100];
- StrCopy(filename, "Images/RoundedList");
- if (i == 0)
- StrAppend(filename, "Top");
- else if (i == 19)
- StrAppend(filename, "Bottom");
- aScrollerButton[i].Init(nContainer1, filename, 8, i*44+122, OnButton, i+1);
- char text[100];
- sprintf(text, "Button %d", i+1);
- TextAdd(nContainer1, 28, i*44+134, text, nFont);
- }
- // Initiate scroller 320x480, ID 100, horizontal scroll false, active false, min X 320, max X 320
- scroller2.Init(nContainer2, 320, 480, 100);
- scroller2.SetHorizontalScroll(false);
- scroller2.SetActive(false);
- scroller2.SetMinX(320);
- scroller2.SetMaxX(320);
- // Populate container 2
- ViewAdd(nContainer2, "Images/Wood.png", 0, 0);
- HeaderTextAdd(nContainer2, 8, 76, "Another Page");
- ButtonAdd(nContainer2, "Images/RoundedButton", 8, 122, OnButton, 101);
- TextAdd(nContainer2, 28, 134, "Next page", nFont);
- // Initiate scroller 320x480, ID 200, horizontal scroll false, active false, min X 320, max X 320
- scroller3.Init(nContainer3, 320, 480, 200);
- scroller3.SetHorizontalScroll(false);
- scroller3.SetActive(false);
- scroller3.SetMinX(320);
- scroller3.SetMaxX(320);
- // Populate container 3
- ViewAdd(nContainer3, "Images/Wood.png", 0, 0);
- HeaderTextAdd(nContainer3, 8, 76, "Last Page");
- ButtonAdd(nContainer3, "Images/RoundedButton", 8, 122, OnButton, 201);
- TextAdd(nContainer3, 28, 134, "Go back", nFont);
- // GUI elements
- ViewAdd(nGUIContainer, "Images/TopBar.png", 0, 0);
- ViewAdd(nGUIContainer, "Images/Navigator.png", 0, 20);
- ViewAdd(nGUIContainer, "Images/Toolbar.png", 0, 436);
- }
- // This function is called whenever the app terminates
- void AppExit()
- {
- }
- // This function is called 30 times per second
- void OnTimer()
- {
- scroller1.Update();
- scroller2.Update();
- scroller3.Update();
- for (int i=0; i<20; i++)
- aScrollerButton[i].Update();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement