Permalink
Browse files

added GUI prototype with widgets, and all necessary files. core moved…

… to core folder
  • Loading branch information...
1 parent 9eb1fca commit 5f8c2ca4d430127a61252eb0a5ba836468b28a5f @WonderCsabo committed Jun 2, 2011
Showing with 14,267 additions and 232 deletions.
  1. BIN SDL.dll
  2. BIN SDL_ttf.dll
  3. +54 −0 application.cpp
  4. +25 −0 application.hpp
  5. +39 −0 button.cpp
  6. +23 −0 button.hpp
  7. +237 −0 core/core.cpp
  8. +28 −0 exitbutton.hpp
  9. +101 −0 include/SDL/SDL.h
  10. +63 −0 include/SDL/SDL_active.h
  11. +284 −0 include/SDL/SDL_audio.h
  12. +29 −0 include/SDL/SDL_byteorder.h
  13. +202 −0 include/SDL/SDL_cdrom.h
  14. +311 −0 include/SDL/SDL_config.h
  15. +22 −0 include/SDL/SDL_copying.h
  16. +69 −0 include/SDL/SDL_cpuinfo.h
  17. +209 −0 include/SDL/SDL_endian.h
  18. +72 −0 include/SDL/SDL_error.h
  19. +356 −0 include/SDL/SDL_events.h
  20. +28 −0 include/SDL/SDL_getenv.h
  21. +187 −0 include/SDL/SDL_joystick.h
  22. +135 −0 include/SDL/SDL_keyboard.h
  23. +326 −0 include/SDL/SDL_keysym.h
  24. +78 −0 include/SDL/SDL_loadso.h
  25. +106 −0 include/SDL/SDL_main.h
  26. +143 −0 include/SDL/SDL_mouse.h
  27. +177 −0 include/SDL/SDL_mutex.h
  28. +11 −0 include/SDL/SDL_name.h
  29. +6,556 −0 include/SDL/SDL_opengl.h
  30. +110 −0 include/SDL/SDL_platform.h
  31. +55 −0 include/SDL/SDL_quit.h
  32. +155 −0 include/SDL/SDL_rwops.h
  33. +620 −0 include/SDL/SDL_stdinc.h
  34. +225 −0 include/SDL/SDL_syswm.h
  35. +120 −0 include/SDL/SDL_thread.h
  36. +125 −0 include/SDL/SDL_timer.h
  37. +249 −0 include/SDL/SDL_ttf.h
  38. +28 −0 include/SDL/SDL_types.h
  39. +91 −0 include/SDL/SDL_version.h
  40. +951 −0 include/SDL/SDL_video.h
  41. +191 −0 include/SDL/begin_code.h
  42. +46 −0 include/SDL/close_code.h
  43. +946 −0 include/SDL/doxyfile
  44. +240 −0 include/graphics.hpp
  45. +16 −0 label.cpp
  46. +18 −0 label.hpp
  47. +27 −0 labelmodbutton.hpp
  48. BIN lib/libSDL.dll.a
  49. +41 −0 lib/libSDL.la
  50. BIN lib/libSDLmain.a
  51. BIN lib/libgraphics.a
  52. BIN lib/libgraphicsd.a
  53. BIN lib/libsdl_ttf.a
  54. BIN libfreetype-6.dll
  55. +16 −232 main.cpp
  56. +22 −0 widget.cpp
  57. +30 −0 widget.hpp
  58. +74 −0 widgets.cbp
  59. BIN zlib1.dll
View
BIN SDL.dll
Binary file not shown.
View
Binary file not shown.
View
@@ -0,0 +1,54 @@
+#include "application.hpp"
+
+#include <graphics.hpp>
+using namespace genv;
+
+Application::Application(int x, int y): sizeX(x), sizeY(y)
+{
+ isExiting = false;
+ focus = 0;
+}
+Application::~Application()
+{
+ for (unsigned int i = 0; i < widgets.size(); i++)
+ delete widgets[i];
+}
+void Application::AddWidget(Widget *w)
+{
+ widgets.push_back(w);
+}
+void Application::Run()
+{
+ gout.open(sizeX, sizeY);
+ while (gin && !isExiting) // amíg fogadhat eseményeket és nincs kilépési módban
+ {
+ event ev; gin >> ev;
+
+ if ((ev.keycode == key_tab || ev.keycode == key_right) && widgets.size() > 0) // tab hatására változik a fókusz
+ focus++;
+ if(widgets.size() > 0 && ev.keycode == key_left)
+ focus--;
+
+ if(focus>2)
+ focus = 0;
+ if(focus<0)
+ focus = 2;
+
+ for (unsigned int i = 0; i < widgets.size(); i++)
+ widgets[i]->SetFocus(focus == i);
+
+ for (unsigned int i = 0; i < widgets.size(); i++)
+ { // vectorban található vezérlõk
+ widgets[i]->HandleEvent(ev); // eseménykezelés
+ }
+
+ gout << move_to(0, 0) << color(0,0,0) << box(sizeX, sizeY);
+ for (unsigned int i = 0; i < widgets.size(); i++)
+ widgets[i]->Show(); // megjelenítés
+ gout << refresh;
+ }
+}
+void Application::Shutdown()
+{
+ isExiting = true; // kilépés inicializálása
+}
View
@@ -0,0 +1,25 @@
+#ifndef APPLICATION_HPP
+#define APPLICATION_HPP
+
+#include "widget.hpp"
+#include <vector>
+
+class Application // grafikus alkalmazás
+{
+public:
+ Application(int sx, int sy); // méret alapján program létrehozása
+ ~Application();
+ void AddWidget(Widget *w); // új vezérlõ felvétele
+ void Run(); // futtatás
+ void Shutdown(); // leállítás
+
+ int Width() const { return sizeX; }
+ int Height() const { return sizeY; }
+protected:
+ std::vector<Widget*> widgets; // vezérlõk
+ int focus; // megadja, melyik vezérlõn van a fókusz
+ bool isExiting; // kilépés alatt áll-e a program
+ int sizeX, sizeY; // képernyõ méret
+};
+
+#endif // APPLICATION_HPP
View
@@ -0,0 +1,39 @@
+#include "button.hpp"
+using namespace genv;
+
+Button::Button(int px, int py, int sx, int sy, std::string text, bool focus)
+: Widget(px, py, sx, sy, focus)
+{
+ buttonText = text;
+}
+
+void Button::Show() const
+{
+ gout << move_to(posX, posY) << color(255,255,255) << box(sizeX, sizeY);
+
+ if (isFocused ) gout << color(0,0,100);
+ else if(Mouse) gout << color(255,0,0);
+ else gout << color(0,0,50);
+ gout << move_to(posX + 1, posY + 1) << box(sizeX - 2, sizeY - 2);
+
+ gout << color(255,255,255)
+ << move_to(posX + sizeX / 2 - gout.twidth(buttonText) / 2, posY + sizeY / 2 + 6)
+ << text(buttonText);
+}
+
+void Button::HandleEvent(event ev)
+{
+ // ha a gomb fókuszálva van és ENTER-t ütünk, vagy felette bal egérgombbal kattintunk
+ if ((isFocused && ev.keycode == key_enter) ||
+ (MouseOver(ev.pos_x, ev.pos_y) && ev.button == btn_left))
+ {
+ Action(); // hajtsuk végre az akciót
+ }
+ if(MouseOver(ev.pos_x, ev.pos_y))
+ {
+ Mouse = true;
+ }
+ else if (!MouseOver(ev.pos_x, ev.pos_y) && ev.type == ev_mouse)
+ Mouse = false;
+}
+
View
@@ -0,0 +1,23 @@
+#ifndef BUTTON_HPP
+#define BUTTON_HPP
+
+#include "widget.hpp"
+#include <string>
+
+class Button : public Widget // gomb vezérlõje
+{
+public:
+ Button(int px, int py, int sx, int sy, std::string text, bool focus = false);
+ void Show() const;
+ void HandleEvent(genv::event ev); // eseménykezelés
+ void SetText(std::string text);
+
+ std::string Text() const { return buttonText; }
+protected:
+ virtual void Action() {} // akciókezelés, ez lehet rejtett
+
+ std::string buttonText;
+};
+
+
+#endif // BUTTON_ppH
View
@@ -0,0 +1,237 @@
+/** The core of the calculator, it converts an infix mathematical expression to RPN, than evaulates the result. **/
+
+#include <iostream>
+#include <stack>
+#include <deque>
+#include <string>
+#include <vector>
+#include <cstdlib>
+#include <sstream>
+#include <cmath>
+using namespace std;
+
+bool isoperator(char output)
+{
+ switch(output)
+ {
+ case '+' :
+ case '-' :
+ case '*' :
+ case '/' :
+ case '^' :
+ return true;
+ default:
+ return false;
+ }
+}
+
+
+int preced(char op)
+{
+ switch(op)
+ {
+ case '+' :
+ case '-' :
+ return 2;
+
+ case '*' :
+ case '/' :
+ return 3;
+
+ case '^' :
+ return 4;
+
+ case '(' :
+ case ')' :
+ return 1;
+ }
+ return 0;
+}
+
+bool assoc(char op)
+{
+ switch(op)
+ {
+ case '^' :
+ return true;
+ default:
+ return false;
+ }
+}
+
+deque <string> tokenize(string s)
+{
+ deque <string> d;
+ string temp;
+
+ for(unsigned int i=0; i<s.size(); i++)
+ {
+ if(!isdigit(s[i]) && s[i] != '.')
+ {
+ if(!temp.empty())
+ d.push_back(temp);
+
+ temp=s[i];
+ d.push_back(temp);
+ temp.clear();
+ }
+ else
+ temp+=s[i];
+ }
+ if(isdigit(s[s.size()-1]) && !temp.empty())
+ d.push_back(temp);
+
+ return d;
+}
+
+double evaulate(vector <double> v, string s)
+{
+ switch(s[0])
+ {
+ case '+':
+ return v[0]+v[1];
+ case '-':
+ return v[1]-v[0];
+ case '*':
+ return v[0]*v[1];
+ case '/':
+ return v[1]/v[0];
+ case '^':
+ return pow(v[1],v[0]);
+ }
+
+ return 0;
+}
+
+int main()
+{
+ bool bad = false;
+ bool lpar = false;
+ deque <string> rpn;
+ stack <string> opStack;
+ string input;
+ getline(cin,input);
+ deque <string> d = tokenize(input);
+
+ //converting to RPN
+
+ while(!d.empty())
+ {
+ if(isoperator(d.front()[0]))
+ {
+ while(!opStack.empty())
+ {
+ if(isoperator(opStack.top()[0]) &&
+ ((!assoc(d.front()[0]) && preced(d.front()[0])<=preced(opStack.top()[0])) ||
+ (assoc(d.front()[0]) && preced(d.front()[0])<preced(opStack.top()[0]))))
+ {
+ rpn.push_back(opStack.top());
+ opStack.pop();
+ }
+ else
+ break;
+ }
+
+ opStack.push(d.front());
+ }
+
+ else if(d.front() == "(")
+ opStack.push(d.front());
+
+ else if(d.front() == ")")
+ {
+ lpar = false;
+ while(!opStack.empty())
+ {
+ if(opStack.top() == "(")
+ {
+ lpar = true;
+ break;
+ }
+ rpn.push_back(opStack.top());
+ opStack.pop();
+ }
+
+ if(!lpar)
+ bad = true;
+
+ if(!opStack.empty())
+ opStack.pop();
+ }
+
+ else
+ {
+ rpn.push_back(d.front());
+ }
+
+ if(bad)
+ break;
+
+ d.pop_front();
+ }
+
+ while (!opStack.empty() && !bad)
+ {
+
+ if(opStack.top() == "(" || opStack.top() == ")")
+ {
+ bad=true;
+ break;
+ }
+
+ rpn.push_back(opStack.top());
+ opStack.pop();
+ }
+
+ //evaluating the result
+
+ stack <double> valStack;
+ vector <double> *tempv;
+ stringstream *s;
+ int t;
+ while(!rpn.empty())
+ {
+ if(isoperator(rpn.front()[0]))
+ {
+ if(valStack.size()<2)
+ {
+ bad = true;
+ break;
+ }
+ else
+ {
+ tempv = new vector <double>;
+ for(unsigned int i=0;i<2;i++)
+ {
+ tempv->push_back(valStack.top());
+ valStack.pop();
+ }
+
+ valStack.push(evaulate(*tempv, rpn.front()));
+ delete tempv;
+ }
+
+ }
+ else
+ {
+ s = new stringstream;
+ *s<<rpn.front();
+ *s>>t;
+ delete s;
+ valStack.push(t);
+ }
+
+ rpn.pop_front();
+ }
+
+ if(valStack.size() > 1 || valStack.empty())
+ bad = true;
+
+ if(bad)
+ cout<<"hibas kifejezes";
+ else
+ cout<<"eredmeny: "<<valStack.top();
+
+
+ return 0;
+}
Oops, something went wrong.

0 comments on commit 5f8c2ca

Please sign in to comment.