summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xMakefile3
-rwxr-xr-xcalculator.cpp88
-rwxr-xr-xcalculator.h38
3 files changed, 99 insertions, 30 deletions
diff --git a/Makefile b/Makefile
index 47bd57a..fd4f25d 100755
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,6 @@
CPP=g++
-CFLAGS=-O2
+WARN=-W -Wall
+CFLAGS=-O2 ${WARN}
LDFLAGS=-los
EXE=calculator.app
diff --git a/calculator.cpp b/calculator.cpp
index 7124a06..c17fb50 100755
--- a/calculator.cpp
+++ b/calculator.cpp
@@ -1,59 +1,89 @@
#include <gui/ApplicationWindow.h>
#include <gui/Application.h>
-using namespace SkyGI;
+#include "calculator.h"
-class MyApp : public Application {
- public:
- MyApp(int argc, char *argv[]);
-};
-
-class MyApplicationWindow : public ApplicationWindow {
- public:
- MyApplicationWindow( const Rect &rFrame,
- const String& szTitle,
- unsigned int nWindowLayoutFlags,
- unsigned int uiFlags = 0);
- void OnCommand( const MessageCommand *pMessage);
-
-};
-
-
-MyApplicationWindow::MyApplicationWindow( const Rect &rFrame,
+CalculatorWindow::CalculatorWindow( const Rect &rFrame,
const String& szTitle,
unsigned int nWindowLayoutFlags,
unsigned int uiFlags
): ApplicationWindow(rFrame, szTitle, nWindowLayoutFlags)
{
+ Button * pButton;
+
+ pButton = new Button(this, Rect(Point(15, 60), Point(40, 82)), "7", 0, new MessageCommand(BUTTON_SEVEN));
+ pButton = new Button(this, Rect(Point(45, 60), Point(70, 82)), "8", 0, new MessageCommand(BUTTON_EIGHT));
+ pButton = new Button(this, Rect(Point(75, 60), Point(100, 82)), "9", 0, new MessageCommand(BUTTON_NINE));
+ pButton = new Button(this, Rect(Point(105, 60), Point(160, 82)), "Clear", 0, new MessageCommand(BUTTON_CLEAR));
+
+ pButton = new Button(this, Rect(Point(15, 87), Point(40, 109)), "4", 0, new MessageCommand(BUTTON_FOUR));
+ pButton = new Button(this, Rect(Point(45, 87), Point(70, 109)), "5", 0, new MessageCommand(BUTTON_FIVE));
+ pButton = new Button(this, Rect(Point(75, 87), Point(100, 109)), "6", 0, new MessageCommand(BUTTON_SIX));
+ pButton = new Button(this, Rect(Point(105, 87), Point(130, 109)), "+", 0, new MessageCommand(BUTTON_PLUS));
+ pButton = new Button(this, Rect(Point(135, 87), Point(160, 109)), "-", 0, new MessageCommand(BUTTON_MINUS));
+
+ pButton = new Button(this, Rect(Point(15, 114), Point(40, 136)), "1", 0, new MessageCommand(BUTTON_ONE));
+ pButton = new Button(this, Rect(Point(45, 114), Point(70, 136)), "2", 0, new MessageCommand(BUTTON_TWO));
+ pButton = new Button(this, Rect(Point(75, 114), Point(100, 136)), "3", 0, new MessageCommand(BUTTON_THREE));
+ pButton = new Button(this, Rect(Point(105, 114), Point(130, 136)), "\u00D7", 0, new MessageCommand(BUTTON_TIMES));
+ pButton = new Button(this, Rect(Point(135, 114), Point(160, 136)), "\u00F7", 0, new MessageCommand(BUTTON_DIVIDE));
+
+ pButton = new Button(this, Rect(Point(15, 141), Point(40, 163)), "0", 0, new MessageCommand(BUTTON_ZERO));
+ pButton = new Button(this, Rect(Point(45, 141), Point(70, 163)), ".", 0, new MessageCommand(BUTTON_POINT));
+ pButton = new Button(this, Rect(Point(75, 141), Point(100, 164)), "\u00B1", 0, new MessageCommand(BUTTON_SIGN));
+ pButton = new Button(this, Rect(Point(105, 141), Point(160, 164)), "=", 0, new MessageCommand(BUTTON_EQUALS));
+/*
+ pButton = new Button(this, Point(10,10), "1", 0, new MessageCommand(BUTTON_ONE));
+ pButton = new Button(this, Point(10,10), "1", 0, new MessageCommand(BUTTON_ONE));
+ pButton = new Button(this, Point(10,10), "1", 0, new MessageCommand(BUTTON_ONE));
+ pButton = new Button(this, Point(10,10), "1", 0, new MessageCommand(BUTTON_ONE));*/
}
-void MyApplicationWindow::OnCommand(const MessageCommand *pMessage) {
+void CalculatorWindow::OnCommand(const MessageCommand *pMessage) {
switch (pMessage->GetID()) {
+ case BUTTON_ZERO:
+ case BUTTON_ONE:
+ case BUTTON_TWO:
+ case BUTTON_THREE:
+ case BUTTON_FOUR:
+ case BUTTON_FIVE:
+ case BUTTON_SIX:
+ case BUTTON_SEVEN:
+ case BUTTON_EIGHT:
+ case BUTTON_NINE:
+ case BUTTON_PLUS:
+ case BUTTON_MINUS:
+ case BUTTON_TIMES:
+ case BUTTON_DIVIDE:
+ case BUTTON_EQUALS:
+ case BUTTON_POINT:
+ case BUTTON_SIGN:
+ case BUTTON_CLEAR:
+ printf("Button %d clicked\n", pMessage->GetID());
default:
break;
}
}
-
-MyApp::MyApp(int argc, char* argv[]):
+Calculator::Calculator(int argc, char* argv[]):
Application("application/x-vnd.Calculator", argc, argv) {
- Rect r(Point(100, 100), Point(400, 300));
+ Rect r(Point(100, 100), Point(275, 275));
- MyApplicationWindow* pApplicationWindow =
- new MyApplicationWindow(r, "Calculator", WINDOW_LAYOUT_NOTHING,
+ CalculatorWindow * pCalculatorWindow =
+ new CalculatorWindow(r, "Calculator", WINDOW_LAYOUT_NOTHING,
APPLICATION_WINDOW_NO_VIEW);
- pApplicationWindow->GetTitleWindow()->SetFlags(
- (TitleWindowFlags)(pApplicationWindow->GetTitleWindow()->GetFlags()
+ pCalculatorWindow->GetTitleWindow()->SetFlags(
+ (TitleWindowFlags)(pCalculatorWindow->GetTitleWindow()->GetFlags()
));
- pApplicationWindow->Show();
+ pCalculatorWindow->Show();
}
int main(int argc, char *argv[]) {
- MyApp pApp(argc, argv);
+ Calculator pCalculator(argc, argv);
- return pApp.Run();
+ return pCalculator.Run();
}
diff --git a/calculator.h b/calculator.h
new file mode 100755
index 0000000..f6edfaa
--- /dev/null
+++ b/calculator.h
@@ -0,0 +1,38 @@
+#include <gui/ApplicationWindow.h>
+#include <gui/Application.h>
+
+using namespace SkyGI;
+
+#define BUTTON_ZERO 0
+#define BUTTON_ONE 1
+#define BUTTON_TWO 2
+#define BUTTON_THREE 3
+#define BUTTON_FOUR 4
+#define BUTTON_FIVE 5
+#define BUTTON_SIX 6
+#define BUTTON_SEVEN 7
+#define BUTTON_EIGHT 8
+#define BUTTON_NINE 9
+#define BUTTON_PLUS 10
+#define BUTTON_MINUS 11
+#define BUTTON_TIMES 12
+#define BUTTON_DIVIDE 13
+#define BUTTON_EQUALS 14
+#define BUTTON_POINT 15
+#define BUTTON_SIGN 16
+#define BUTTON_CLEAR 17
+
+class Calculator : public Application {
+ public:
+ Calculator(int argc, char *argv[]);
+};
+
+class CalculatorWindow : public ApplicationWindow {
+ public:
+ CalculatorWindow( const Rect &rFrame,
+ const String& szTitle,
+ unsigned int nWindowLayoutFlags,
+ unsigned int uiFlags = 0);
+ void OnCommand( const MessageCommand *pMessage);
+
+};