main.cpp

00001 /*
00002     GLICT - Graphics Library Interface Creation Toolkit
00003     Copyright (C) 2006-2007 OBJECT Networks
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 // This program is NOT meant to serve as an example,
00021 // it is sort-of a test suite instead, a mish-mash of unrelated
00022 // widgets to facilitate testing. Go to examples/ folder for
00023 // some examples.
00024 
00025 #ifdef WIN32
00026 #include <windows.h>
00027 #endif
00028 //#include <wingdi.h>
00029 //#include <GL/gl.h>
00030 
00031 #include <GL/glut.h>
00032 #include <stdio.h>
00033 #include <GLICT/container.h>
00034 #include <GLICT/button.h>
00035 #include <GLICT/panel.h>
00036 #include <GLICT/window.h>
00037 #include <GLICT/messagebox.h>
00038 #include <GLICT/textbox.h>
00039 #include <GLICT/list.h>
00040 #include <GLICT/globals.h>
00041 #include <GLICT/fonts.h>
00042 #include <GLICT/skinner.h>
00043 //#include <GLICT/types.h>
00044 
00045 
00046 
00047 #include "glut-helper.h"
00048 #include "texload.h"
00049 glictWindow panela2;
00050 glictPanel panela4;
00051 glictMessageBox msgbox;
00052 glictTextbox textbox;
00053 glictList l;
00054 bool textured=true;
00055 
00056 
00057 unsigned int windowhandle;
00058 glictContainer desktop, desktop2;
00059 glictWindow window2;
00060 int ww, wh;
00061 glictPos mousepos;
00062 glictSkinner skinner;
00063 void display();
00064 
00065 
00066 void key(unsigned char key, int x, int y) {
00067     desktop.CastEvent(GLICT_KEYPRESS, &key, 0);
00068     glutPostRedisplay();
00069 }
00070 
00071 void mouse(int button, int shift, int mousex, int mousey) {
00072     glictPos pos;
00073     pos.x = mousex;
00074     pos.y = mousey;
00075     desktop.TransformScreenCoords(&pos);
00076     if (shift==GLUT_DOWN) desktop.CastEvent(GLICT_MOUSEDOWN, &pos, 0);
00077     if (shift==GLUT_UP) desktop.CastEvent(GLICT_MOUSEUP, &pos, 0);
00078 
00079     //char zz[256];
00080     //sprintf(zz, "%d %d", pos.x, pos.y);
00081     //glutSetWindowTitle(zz);
00082     glutPostRedisplay();
00083 }
00084 void passivemouse(int mousex, int mousey) {
00085     mousepos.x = mousex;
00086     mousepos.y = mousey;
00087     desktop.TransformScreenCoords(&mousepos);
00088     display();
00089 }
00090 void reshape(int x, int y) {
00091     glMatrixMode(GL_PROJECTION);
00092     glLoadIdentity();
00093     glViewport(0,0,x,y);
00094     gluOrtho2D(0,x,0,y);
00095     //glRotatef(180.0, 0.0, 0.0, 1.0);
00096     glRotatef(180.0, 1.0, 0.0, 0.0);
00097     glTranslatef(0,-y,0.0);
00098     //glTranslatef(-x,-y,0.0);
00099     glMatrixMode(GL_MODELVIEW);
00100     //printf("Postavljam sirinu desktopa\n");
00101     desktop.SetWidth((int)(x*0.8));
00102     //printf("Postavljam visinu desktopa\n");
00103     //desktop.SetHeight(y/2);
00104     desktop.SetHeight(y);
00105     //printf("Postavljam poziciju desktopa\n");
00106     desktop.SetPos(0, 0);
00107 
00108     panela2.SetHeight(y/2);
00109 
00110     glictGlobals.h = y;
00111     glictGlobals.w = x;
00112     ww = x;
00113     wh = y;
00114 //    desktop.SetPos(0,0);
00115 
00116     //desktop.ReportDebug();
00117     display();
00118 }
00119 #include <math.h>
00120 float kut = 0.;
00121 void display() {
00122     glDisable(GL_STENCIL_TEST);
00123     //glDisable(GL_SCISSOR_TEST);
00124     //printf("PAINT STARTUP\nPAINT STARTUP\nPAINT STARTUP\n-------------------\n");
00125     glClearColor(0.0,0.0,0.0,0.0);
00126     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00127 
00128     glEnable(GL_STENCIL_TEST);
00129     //glEnable(GL_SCISSOR_TEST);
00130     glPushMatrix();
00131 
00132 
00133     //glRotatef(10., 0., 0., 1.);
00134     desktop.RememberTransformations();
00135     desktop.Paint();
00136     glPopMatrix();
00137 
00138     /*glPushMatrix();
00139     //glTranslatef( sin(kut++ * 3.14 / 180.)*90., 150., 0.);
00140     //glScalef(2.00,2.00,2.00);
00141     //glRotatef(5.0,0.0,0.0,1.0);
00142     glTranslatef(100, 50, 0);
00143 
00144     desktop.RememberTransformations();
00145     desktop.SetScissor();
00146     desktop.Paint();
00147 
00148     glPopMatrix();
00149 */
00150     glDisable(GL_STENCIL_TEST);
00151     glBegin(GL_QUADS);
00152     glColor4f(0.5,0.5,0.5,1.0);
00153     glVertex2f(mousepos.x, mousepos.y);
00154     glVertex2f(mousepos.x-10, mousepos.y);
00155     glVertex2f(mousepos.x-10, mousepos.y-10);
00156     glVertex2f(mousepos.x, mousepos.y-10);
00157     glEnd();
00158     glEnable(GL_STENCIL_TEST);
00159 
00160     /*glEnable(GL_ALPHA_TEST);
00161     {
00162         glictSize s = {100, 100};
00163         skinner.Paint(&s);
00164     }
00165     glDisable(GL_ALPHA_TEST);*/
00166 
00167     glutReportErrors();
00168     //printf("FINISHED PAINT.\n");
00169     glutSwapBuffers();
00170     //desktop.ReportDebug();
00171 }
00172 bool buttonstate = true;
00173 void onpanel2paint(glictRect* real, glictRect* clipped, glictContainer* callerclass) {
00174 
00175 
00176     glPushAttrib(GL_VIEWPORT);
00177     glViewport(clipped->left, glictGlobals.h - clipped->bottom, clipped->right - clipped->left, clipped->bottom - clipped->top);
00178     printf("%g %g %g %g\n", clipped->left, glictGlobals.h - clipped->bottom, clipped->right - clipped->left, clipped->bottom - clipped->top);
00179     //glClear(GL_COLOR_BUFFER_BIT);
00180 
00181     glMatrixMode(GL_PROJECTION);
00182     //glPushMatrix();
00183     //glLoadIdentity();
00184     //gluOrtho2D(0, 200, 0, 200);
00185 
00186 
00187     glMatrixMode(GL_MODELVIEW);
00188     glPushMatrix();
00189     glLoadIdentity();
00190 
00191     glTranslatef(100, 200, 0);
00192     glBegin(GL_TRIANGLES);
00193     glColor3f(1.,0.,0.);
00194     glVertex2f(0, 0);
00195     glColor3f(0.,1.,0.);
00196     glVertex2f(100,0);
00197     glColor3f(0.,0.,1.);
00198     glVertex2f(100,100);
00199     glEnd();
00200 
00201     glColor3f(1,1,1);
00202     glMatrixMode(GL_MODELVIEW);
00203     glPopMatrix();
00204 
00205     //glMatrixMode(GL_PROJECTION);
00206     //glPopMatrix();
00207 
00208     glPopAttrib();
00209 }
00210 
00211 void omd(glictPos *a, glictContainer* callclass) {
00212     printf("OMD\n");
00213 }
00214 void omu(glictPos *a, glictContainer* callclass) {
00215     printf("OMU\n");
00216 }
00217 void onnbclick(glictPos *a, glictContainer *callclass) {
00218     l.RemoveObject(callclass);
00219     l.DelayedRemove();
00220     delete callclass;
00221 }
00222 void onlb2click(glictPos *a, glictContainer* callclass) {
00223     glictButton* nb = new glictButton;
00224     nb->SetOnClick(onnbclick);
00225     l.AddObject(nb);
00226 }
00227 void onpanel5click(glictPos *a, glictContainer* callclass) {
00228     buttonstate = !buttonstate;
00229 
00230     (dynamic_cast<glictButton*>(callclass))->SetCaption(buttonstate ? "Button" : "Clicked\n(indeed)\nvery much");
00231     (dynamic_cast<glictButton*>(callclass))->SetWidth(100);
00232     (dynamic_cast<glictButton*>(callclass))->SetFont("system", buttonstate ? 10 : 5);
00233 
00234     panela2.SetCaption(buttonstate ? "Sample Window" : textbox.GetCaption()); // window
00235 
00236     if (buttonstate)
00237         panela2.SetPos(0,0);
00238     else
00239         panela2.SetPos(120,90);
00240 }
00241 
00242 
00243 void paintrectcallback(float left, float right, float top, float bottom, glictColor &col) {
00244         if (col.a >= 0) glColor4f(col.r-0.5, col.g, col.b*0, col.a);
00245         /*glBegin(GL_LINES);
00246 
00247                 glVertex2f(left, top-1);
00248                 glVertex2f(left, bottom);
00249 
00250                 glVertex2f(left, bottom);
00251                 glVertex2f(right-1, bottom);
00252 
00253                 glVertex2f(right-1, top-1);
00254                 glVertex2f(right-1, bottom);
00255 
00256 
00257                 glVertex2f(right-1, top-2);
00258                 glVertex2f(left, top-2);
00259         glEnd();*/
00260 
00261 
00262         glBegin(GL_QUADS);
00263         glVertex2f(left, top);
00264         glVertex2f(left, bottom);
00265         glVertex2f(right, bottom);
00266         glVertex2f(right, top);
00267         glEnd();
00268 }
00269 
00270                 glictWindow login;
00271                 glictPanel pnlLogin;
00272                 glictPanel pnlLoginProtocol, pnlLoginServer, pnlLoginUsername, pnlLoginPassword;
00273                 glictTextbox txtLoginProtocol, txtLoginServer, txtLoginUsername, txtLoginPassword;
00274                 glictButton btnLoginLogin, btnLoginCancel;
00275 
00276 
00277 
00278 void glinit() {
00279     glictPanel* panela = new glictPanel;
00280     //panela2 = new glictWindow;
00281     glictPanel* panela3 = new glictPanel;
00282     glictButton* panela5 = new glictButton;
00283     glictButton* panela6 = new glictButton;
00284 
00285     desktop.AddObject((panela));
00286     panela->SetBGColor(0.5,0.5,1.0,1.0);
00287     panela->AddObject((&panela2));
00288     panela->SetWidth(600);
00289     panela->SetHeight(512);
00290 
00291 
00292     panela5->SetBGColor(1,0,0,1);
00293     panela5->SetPos(0,90);
00294     //panela5->SetCustomData((void*)"Hello");
00295     panela->AddObject(panela5);
00296 
00297 
00298     panela2.SetBGColor(0.2,1.0,0.2,1.0);
00299     panela2.SetPos(0,0);
00300     panela2.SetHeight(50);
00301     panela2.SetWidth(400);
00302 
00303     panela2.SetCaption("Sample Window");
00304     panela2.SetOnPaint(onpanel2paint);
00305 
00306     /*panela3->SetPos(12,12);
00307     panela2->AddObject(panela3);*/
00308 
00309 
00310     panela2.AddObject(&panela4);
00311     panela4.SetHeight(128);
00312     panela4.SetCaption("pnl");
00313     panela4.SetVirtualSize(500,500);
00314     panela4.SetPos(10,20);
00315     panela4.AddObject(panela6);
00316 
00317     panela6->SetBGColor(1,0,0,1);
00318     panela6->SetPos(4,4);
00319     panela6->SetPos(0,115);
00320 
00321     panela5->SetOnClick(onpanel5click);
00322     panela5->SetWidth(64);
00323 
00324 
00325     panela->AddObject(&msgbox);
00326     msgbox.SetMessage("Hello there. What's better,\nto live or to die? You should not\ntake care about such\nsilly stuff.");
00327     msgbox.SetCaption("Nice Messagebox");
00328     msgbox.SetPos(50,50);
00329     msgbox.SetHeight(120);
00330 
00331     panela2.AddObject(&textbox);
00332     textbox.SetPos(50,0);
00333     textbox.SetCaption("Text");
00334     textbox.SetHeight(64);
00335     textbox.SetWidth(250);
00336     textbox.SetAllowedChars("abc");
00337 
00338     desktop2.AddObject(&window2);
00339     desktop2.SetHeight(200);
00340     desktop2.SetWidth(200);
00341     window2.SetHeight(25);
00342     window2.SetWidth(25);
00343     window2.SetPos(100,100);
00344 
00345 
00346 
00347 
00348 
00349     glictButton* lb1 = new glictButton, *lb2 = new glictButton;
00350     panela->AddObject(&l);
00351     l.AddObject(lb1);
00352     l.AddObject(lb2);
00353     l.SetPos(100,0);
00354         l.SetWidth(100);
00355     l.SetHeight(70);
00356     lb1->SetCaption("oi");
00357     lb2->SetCaption("me");
00358     lb2->SetOnClick(onlb2click);
00359 
00360 
00361         panela->AddObject(&login);
00362         login.SetWidth(300);
00363         login.SetHeight(180);
00364         login.SetCaption("Log in");
00365         login.AddObject(&pnlLogin);
00366         login.SetPos(200, 100);
00367         pnlLogin.SetCaption("Please enter the username, password and \n"
00368                             "server address of the server to connect to.\n"
00369                             "\n"
00370                             "We advise you not to connect to CipSoft's\n"
00371                             "servers using this client, as this is a \n"
00372                             "breach of Tibia Rules.");
00373         pnlLogin.SetWidth(300);
00374         pnlLogin.SetPos(0,0);
00375         pnlLogin.SetHeight(92);
00376         pnlLogin.SetBGActiveness(false);
00377 
00378     char tmp[256] = {0};
00379 
00380         login.AddObject(&pnlLoginProtocol);
00381         pnlLoginProtocol.SetCaption("Protocol:");
00382         pnlLoginProtocol.SetPos(0, 5*15);
00383         pnlLoginProtocol.SetHeight(14);
00384         pnlLoginProtocol.SetWidth(70);
00385         pnlLoginProtocol.SetBGActiveness(false);
00386         login.AddObject(&txtLoginProtocol);
00387         txtLoginProtocol.SetPos(100, 5*15);
00388         txtLoginProtocol.SetHeight(14);
00389         txtLoginProtocol.SetWidth(150);
00390 
00391     txtLoginProtocol.SetCaption(tmp);
00392 
00393         login.AddObject(&pnlLoginServer);
00394         pnlLoginServer.SetCaption("Server:");
00395         pnlLoginServer.SetPos(0, 6*15);
00396         pnlLoginServer.SetHeight(14);
00397         pnlLoginServer.SetWidth(70);
00398         pnlLoginServer.SetBGActiveness(false);
00399         login.AddObject(&txtLoginServer);
00400         txtLoginServer.SetPos(100, 6*15);
00401         txtLoginServer.SetHeight(14);
00402         txtLoginServer.SetWidth(150);
00403 
00404         txtLoginServer.SetCaption( tmp );
00405 
00406         login.AddObject(&pnlLoginUsername);
00407         pnlLoginUsername.SetCaption("Username:");
00408         pnlLoginUsername.SetPos(0, 7*15);
00409         pnlLoginUsername.SetHeight(14);
00410         pnlLoginUsername.SetWidth(70);
00411         pnlLoginUsername.SetBGActiveness(false);
00412         login.AddObject(&txtLoginUsername);
00413         txtLoginUsername.SetPos(100, 7*15);
00414         txtLoginUsername.SetHeight(14);
00415         txtLoginUsername.SetWidth(150);
00416 
00417         txtLoginUsername.SetCaption(tmp);
00418 
00419         login.AddObject(&pnlLoginPassword);
00420         pnlLoginPassword.SetCaption("Password:");
00421         pnlLoginPassword.SetPos(0, 8*15);
00422         pnlLoginPassword.SetHeight(14);
00423         pnlLoginPassword.SetWidth(70);
00424         pnlLoginPassword.SetBGActiveness(false);
00425         login.AddObject(&txtLoginPassword);
00426         txtLoginPassword.SetPos(100, 8*15);
00427         txtLoginPassword.SetHeight(14);
00428         txtLoginPassword.SetWidth(150);
00429         txtLoginPassword.SetPassProtectCharacter('*');
00430 
00431         txtLoginPassword.SetCaption(tmp);
00432 
00433         login.AddObject(&btnLoginLogin);
00434         btnLoginLogin.SetPos(170, 14 + 9*15);
00435         btnLoginLogin.SetWidth(130);
00436         btnLoginLogin.SetCaption("Log in");
00437         btnLoginLogin.SetBGColor(.6,.6,.6,1.);
00438 
00439         login.AddObject(&btnLoginCancel);
00440         btnLoginCancel.SetPos(0, 14 + 9*15);
00441         btnLoginCancel.SetWidth(130);
00442         btnLoginCancel.SetCaption("Cancel");
00443         btnLoginCancel.SetBGColor(.6,.6,.6,1.);
00444 
00445 
00446 
00447 
00448     if (txtLoginPassword.GetCaption() != "") {
00449         printf("%s !!!!!!!!!!!\n", txtLoginPassword.GetCaption().c_str());
00450     }
00451 
00452 
00453 
00454 
00455     glictGlobals.clippingMode = GLICT_STENCILTEST;
00456     //glictGlobals.clippingMode = GLICT_SCISSORTEST;
00457 
00458 
00459 
00460     if (textured) {
00461         glictSize elementsize = {20, 20};
00462         skinner.SetTL(BitmapLoad("topleft.bmp"), &elementsize);
00463         skinner.SetTR(BitmapLoad("topright.bmp"), &elementsize);
00464         skinner.SetBL(BitmapLoad("bottomleft.bmp"), &elementsize);
00465         skinner.SetBR(BitmapLoad("bottomright.bmp"), &elementsize);
00466 
00467         skinner.SetTop(BitmapLoad("top.bmp"), &elementsize);
00468         skinner.SetLeft(BitmapLoad("left.bmp"), &elementsize);
00469         skinner.SetRight(BitmapLoad("right.bmp"), &elementsize);
00470         skinner.SetBottom(BitmapLoad("bottom.bmp"), &elementsize);
00471 
00472         skinner.SetCenter(BitmapLoad("center.bmp"), &elementsize);
00473 
00474 
00475     }
00476 
00477     if (textured) {
00478         glictSkinner *skn = new glictSkinner, *skn2 = new glictSkinner;
00479         glictSize elementsize = {8, 8};
00480         skn->SetTL(BitmapLoad("topleft.bmp"), &elementsize);
00481         skn->SetTR(BitmapLoad("topright.bmp"), &elementsize);
00482         skn->SetBL(BitmapLoad("bottomleft.bmp"), &elementsize);
00483         skn->SetBR(BitmapLoad("bottomright.bmp"), &elementsize);
00484 
00485         skn->SetTop(BitmapLoad("top.bmp"), &elementsize);
00486         skn->SetLeft(BitmapLoad("left.bmp"), &elementsize);
00487         skn->SetRight(BitmapLoad("right.bmp"), &elementsize);
00488         skn->SetBottom(BitmapLoad("bottom.bmp"), &elementsize);
00489 
00490         skn->SetCenter(BitmapLoad("center.bmp"), &elementsize);
00491 
00492 
00493         panela4.SetOnMouseDown(omd);
00494         panela4.SetOnMouseUp(omu);
00495 
00496 
00497 
00498         skn2->SetTL(BitmapLoad("toplefth.bmp"), &elementsize);
00499         skn2->SetTR(BitmapLoad("toprighth.bmp"), &elementsize);
00500         skn2->SetBL(BitmapLoad("bottomlefth.bmp"), &elementsize);
00501         skn2->SetBR(BitmapLoad("bottomrighth.bmp"), &elementsize);
00502 
00503         skn2->SetTop(BitmapLoad("toph.bmp"), &elementsize);
00504         skn2->SetLeft(BitmapLoad("lefth.bmp"), &elementsize);
00505         skn2->SetRight(BitmapLoad("righth.bmp"), &elementsize);
00506         skn2->SetBottom(BitmapLoad("bottomh.bmp"), &elementsize);
00507 
00508         skn2->SetCenter(BitmapLoad("centerh.bmp"), &elementsize);
00509 
00510 
00511         glictGlobals.windowBodySkin = skn;
00512 
00513         glictGlobals.buttonSkin = skn;
00514         glictGlobals.buttonHighlightSkin = skn2;
00515         glictGlobals.buttonTextColor.r = 0;
00516         glictGlobals.buttonTextColor.g = 0;
00517         glictGlobals.buttonTextColor.b = 0;
00518         glictGlobals.buttonTextColor.a = 1;
00519 
00520         glictGlobals.windowTitleColor.r = 0;
00521         glictGlobals.windowTitleColor.g = 0;
00522         glictGlobals.windowTitleColor.b = 0;
00523         glictGlobals.windowTitleColor.a = 1;
00524 
00525         glictGlobals.panelTextColor.r = 0;
00526         glictGlobals.panelTextColor.g = 0;
00527         glictGlobals.panelTextColor.b = 0;
00528         glictGlobals.panelTextColor.a = 1;
00529 
00530 
00531     }
00532 
00533     //glictGlobals.enableGlTranslate = false;
00534     //glictGlobals.paintrectCallback = paintrectcallback;
00535 
00536 
00537     glictFont* sysfont = glictCreateFont("system");
00538 
00539     sysfont->SetFontParam(GLUT_STROKE_MONO_ROMAN);
00540     sysfont->SetRenderFunc(glutxStrokeString);
00541     sysfont->SetSizeFunc(glutxStrokeSize);
00542 
00543 
00544 /*
00545                 sysfont->SetFontParam(WinFontCreate("Arial", WINFONT_BOLD, 7));
00546                 sysfont->SetRenderFunc(WinFontDraw);
00547                 sysfont->SetSizeFunc(WinFontSize);
00548 */
00549 
00550 }
00551 int main(int argc, char** argv) {
00552 
00553     glutInit(&argc, argv);
00554     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL);
00555     glutInitWindowSize (640, 480);
00556     glutInitWindowPosition (0, 0);
00557 
00558     windowhandle = glutCreateWindow ("GLICT Demo");
00559 
00560     glinit();
00561 
00562     glutSetWindow(windowhandle);
00563     glutShowWindow();
00564 
00565     glutDisplayFunc(display);
00566     glutReshapeFunc(reshape);
00567     glutMouseFunc(mouse);
00568 
00569     glutKeyboardFunc(key);
00570 //    glutIdleFunc (display);
00571 
00572 
00573 
00574     //glutPassiveMotionFunc(passivemouse);
00575 
00576     glutMainLoop();
00577     return 0;
00578 }

SourceForge.net Logo
generated with doxygen 1.5.3 on Mon Oct 29 18:09:26 2007