nux-1.16.0
|
00001 /* 00002 * Copyright 2010 Inalogic Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU General Public License version 3, as published 00006 * by the Free Software Foundation. 00007 * 00008 * This program is distributed in the hope that it will be useful, but 00009 * WITHOUT ANY WARRANTY; without even the implied warranties of 00010 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00011 * PURPOSE. See the GNU General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU General Public License 00014 * version 3 along with this program. If not, see 00015 * <http://www.gnu.org/licenses/> 00016 * 00017 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00018 * 00019 */ 00020 00021 #include "Nux/Nux.h" 00022 #include "Nux/VLayout.h" 00023 #include "Nux/HLayout.h" 00024 #include "Nux/WindowThread.h" 00025 #include "NuxGraphics/GraphicsEngine.h" 00026 00027 #include "Nux/TextureArea.h" 00028 #include "NuxImage/CairoGraphics.h" 00029 00030 00031 void ThreadWidgetInit(nux::NThread* thread, void* InitData) 00032 { 00033 nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, 64, 64); 00034 cairo_t *cr = cairo_graphics.GetContext(); 00035 00036 cairo_set_line_width (cr, 1); 00037 cairo_set_source_rgba (cr, 0.0f, 1.0f, 0.5f, 1.0f); 00038 cairo_rectangle (cr, 0, 0, 32, 32); 00039 cairo_fill (cr); 00040 cairo_set_source_rgba (cr, 1.0f, 0.0f, 0.5f, 1.0f); 00041 cairo_rectangle (cr, 32, 32, 32, 32); 00042 cairo_fill (cr); 00043 cairo_destroy (cr); 00044 00045 nux::NBitmapData* bitmap = cairo_graphics.GetBitmap(); 00046 00047 // Texture2D is the high level representation of an image that is backed by an actual opengl texture. 00048 nux::Texture2D* texture2D = new nux::Texture2D(); 00049 texture2D->Update(bitmap); 00050 00051 nux::VLayout* MainVLayout((new nux::VLayout())); 00052 00053 // TextureArea is a widget that uses the image we have created above to render on the screen. 00054 nux::TextureArea* texture_area = new nux::TextureArea(); 00055 texture_area->SetTexture(texture2D); 00056 00057 texture_area->SetMinMaxSize(64, 64); 00058 MainVLayout->AddView(texture_area, 1, nux::eCenter, nux::eFix); 00059 MainVLayout->SetContentDistribution(nux::eStackCenter); 00060 00061 nux::GetWindowThread ()->SetLayout(MainVLayout); 00062 } 00063 00064 int main(int argc, char **argv) 00065 { 00066 nux::NuxInitialize(0); 00067 nux::WindowThread* wt = nux::CreateGUIThread(TEXT("Cairo Graphics"), 400, 300, 0, &ThreadWidgetInit, 0); 00068 wt->Run(NULL); 00069 delete wt; 00070 return 0; 00071 }