L:    P:      Зарегистрироваться Забыл пароль?

  Навигация
- Главная
- Актуальность проекта
- Forum
- FAQ
- Code Example
- Code Example2
- About
  Статистика
  Donates
R995347958383
  Our Hosting
HOSTER.RU
  Code Example
  1.  
  2. /*      Syllable GUI example "Hello world" program.
  3.  
  4.         The code is run like this:
  5.                 main()
  6.                         -> MyApp() constructor
  7.                                 -> MyWindow() constructor
  8.        
  9.         Press Alt+W or Alt+Q to quit the app.
  10.        
  11.         Compile this with the commands:
  12.                 c++ -o HelloWorld HelloWorld.cpp -lsyllable
  13.         Or use the HelloWorld examples for OMake:
  14.                 omake
  15.         Or classic Make:
  16.                 make
  17.  
  18.         Run it with:
  19.                 ./HelloWorld
  20.        
  21.         - Anthony Morphett (awmorp@gmail.com), June 2008.
  22. */
  23.  
  24. #include <util/application.h>   // Include the definitions of the classes that we will use
  25. #include <gui/window.h>
  26. #include <gui/stringview.h>
  27.  
  28. using namespace os;                             // This means that we don't need to prefix everything by "os::", e.g. "os::Application"
  29.  
  30. // Tell the compiler that we will define classes MyWindow and MyApp later
  31. class MyApp;
  32. class MyWindow;
  33.  
  34. /*** Define the MyApp class - our customised Application object. ***
  35.         We need to create one of these before we can do anything else GUI-related, as it establishes the connection with the appserver.
  36.         Usually the class definition would go in a separate file, myapp.h, but in this case as it is so simple we include it here.
  37.         We declare the members and methods here, but we don't give the code for the method functions yet. This comes later.
  38. */
  39.  
  40. class MyApp : public Application        // Declaring class MyApp, derived from libsyllable class Application
  41. {
  42. public:
  43.         // We want the following methods/members to be accessible from anywhere in the app, e.g. in main()
  44.  
  45.         // The constructor. The Application constructor requires a mimetype parameter, to identify the application.
  46.         // Usually this is "application/x-vnd.YourAppName" (the x-vnd. part comes from the MIME specification).
  47.         MyApp( const char* pzMimeType );
  48.  
  49.         // The destructor
  50.         ~MyApp();
  51.  
  52. private:
  53.         // We want the following members only to be accessible from within MyApp, ie from code inside some MyApp method.
  54.         // It is good practice to make everything private, unless it needs to be accessed from other objects or elsewhere.
  55.  
  56.         // This will hold a pointer to the window
  57.         MyWindow* m_pcWindow;
  58.  
  59. };      // Don't forget the ; at the end!
  60.  
  61. // *** Define the MyWindow class. This class contains the code for displaying some content in the window. ***
  62.  
  63. class MyWindow : public Window
  64. {
  65. public:
  66.         // Constructor. It adds a StringView to the window, which displays "Hello, world!".
  67.         // The parameter cFrame tells where the window should be on screen.
  68.         MyWindow( const Rect& cFrame );
  69.  
  70.         // Destructor
  71.         ~MyWindow();
  72.  
  73. private:
  74.         // Declare the m_pcStringView member. This will hold a pointer to the StringView which displays the text.
  75.         StringView* m_pcStringView;
  76. };
  77.  
  78. // ****** Now we give the code for the class methods ******
  79.  
  80. // *** First, MyApp ***
  81.  
  82. // The constructor - create a window and show it
  83. MyApp::MyApp( const char* pzMimeType )
  84.         : Application( pzMimeType )     // This means to automatically call the Application constructor first
  85. {
  86.         m_pcWindow = new MyWindow( Rect( 200,200,400,400 ) );   // Create a new window at (200,200)-(400,400) on screen
  87.         m_pcWindow->Show();                     // Show the window - make it visible
  88. }
  89.  
  90. // The destructor. In this case, we don't need to do anything in the destructor, but we must include it (or else the app won't link properly).
  91. MyApp::~MyApp()
  92. {}
  93.  
  94. // *** Next, MyWindow ***
  95.  
  96. MyWindow::MyWindow( const Rect& cFrame )
  97.         : Window( cFrame, "TestApp-window", "Test application!" )
  98.         /*      Call the Window constructor.
  99.                 cFrame is the window's position on screen.
  100.                 "TestApp-window" is the name of the window (this is for debugging, it isn't shown on screen anywhere).
  101.                 "Test application!" is the title that appears in the window's titlebar.
  102.         */
  103. {
  104.         // Create a StringView, with the text "Hello world!".
  105.         // This creates the view in memory, but later we need to manually add it to the window for it to be displayed on screen.
  106.         m_pcStringView = new StringView( GetBounds(), "TestApp-stringview", "Hello, world!", ALIGN_CENTER );
  107.                 /*      GetBounds() - make the view fill the entire window (GetBounds() returns the size of the window).
  108.                         "TestApp-stringview" - the name of the view, used for debugging and for finding the view later. Not shown on screen.
  109.                         "Hello, world!" - the text to display in the view.
  110.                         ALIGN_CENTER - center the text.
  111.                 */
  112.            
  113.         // Add the view to the window. This means it will be displayed in the window.
  114.         AddChild( m_pcStringView );
  115. }
  116.  
  117. // Destructor - no need to do anything
  118. MyWindow::~MyWindow()
  119. {}
  120.  
  121. // ****** Now main(), the entry point to the app ******
  122.  
  123. // main() : the normal entry point to the program. This is the first thing run when the program starts
  124. int main( int nArgc, char* apzArgv[] )
  125. {
  126.         // Create the Application object, which connects to the appserver and creates a window
  127.         MyApp* pcApp = new MyApp( "application/x-vnd.ExampleApp" );     // Create the application object
  128.         pcApp->Run();
  129.  
  130.         return( 0 );
  131. }
  132.  
  133.  
    
  Поиск по сайту
 
  Популярное
  Голосование
Что останавливает вас в написании программ для Syllable?
Жду когда проект сам раскрутится (7)
Не знаю языков программирования (34)
Считаю это пустой тратой времени (16)
Мало документации (6)
Нет времени, но не прочь помочь (22)
Не знаю чем могу помочь (9)
Вяло пытаюсь кодить (0)
Активно занимаюсь разработкой (0)
Copyright © 2007-2008 2z project DiGitaL Время генерации страницы: 0.65 сек