PROTO/equate: Cleanup code, and add bracket support.

SVN revision: 63874
devs/captainigloo/elm
Nicolas Aguirre 11 years ago
parent 83ed76b877
commit 7b462f7c57
  1. 8
      data/Makefile.am
  2. 11
      data/equate.desktop
  3. 24
      data/equate.edc
  4. BIN
      data/equate.png
  5. 72
      src/Equate.h
  6. 8
      src/Makefile.am
  7. 1
      src/calc.h
  8. 1
      src/calc_parse.c
  9. 299
      src/edje.c
  10. 43
      src/gui.c
  11. 12
      src/gui.h
  12. 234
      src/main.c

@ -18,7 +18,13 @@ all: $(EDCS)
.edc.edj:
$(EDJE_CC) $(EDJE_FLAGS) $< $@
EXTRA_DIST = $(EDCS)
desktopdir = $(datadir)/applications
desktop_DATA = equate.desktop
icondir = $(datadir)/icons
icon_DATA = equate.png
EXTRA_DIST = $(EDCS) equate.png equate.desktop
clean-local:
rm -f $(EDJS)

@ -0,0 +1,11 @@
[Desktop Entry]
Type=Application
Name=Equate
GenericName=Calculator
Comment=EFL Calculator
Icon=equate
TryExec=equate
Exec=equate
Terminal=false
Categories=X-ENLIGHTENMENT;Utility;
StartupWMClass=equate

@ -52,7 +52,7 @@ group { name: "button/"pname; \
/* color3: 0 0 0 30; */ \
text { \
font: "Sans"; \
size: 20; \
size: 25; \
min: 1 1; \
align: 0.5 0.5; \
text_class: "button"; \
@ -166,20 +166,20 @@ collections {
BUTTON("four", "4", "NUM_4");
BUTTON("five", "5", "NUM_5");
BUTTON("six", "6", "NUM_6");
//BUTTON("nine", "9", "OP_DIV");
BUTTON("obrak", "(", "OP_OBRAK");
BUTTON("one", "1", "NUM_1");
BUTTON("two", "2", "NUM_2");
BUTTON("three", "3", "NUM_3");
BUTTON("equal", "=", "OP_EQU");
BUTTON("cbrak", ")", "OP_CBRAK");
BUTTON("zero", "0", "NUM_0");
BUTTON("point", ".", "OP_DEC");
BUTTON("equal", "=", "OP_EQU");
group {
name: "Main";
min: 200 296;
max: 200 296;
parts {
part {
name: "bg";
@ -217,7 +217,7 @@ collections {
{
text: "";
font: "Sans";
size: 25;
size: 30;
//fit: 0 0;
min: 1 1;
align: 1.0 0.5;
@ -230,7 +230,7 @@ collections {
type : TABLE;
description {
state : "default" 0.0;
fixed: 1 1;
fixed: 0 1;
rel1.to: "EquateAnswer";
rel1.relative: 0 1;
table {
@ -253,14 +253,16 @@ collections {
BUTTON_TABLE_ITEM("button/four", 0, 2, 1, 1);
BUTTON_TABLE_ITEM("button/five", 1, 2, 1, 1);
BUTTON_TABLE_ITEM("button/six", 2, 2, 1, 1);
BUTTON_TABLE_ITEM("button/equal", 3, 2, 1, 3);
BUTTON_TABLE_ITEM("button/obrak", 3, 2, 1, 1);
BUTTON_TABLE_ITEM("button/one", 0, 3, 1, 1);
BUTTON_TABLE_ITEM("button/two", 1, 3, 1, 1);
BUTTON_TABLE_ITEM("button/three", 2, 3, 1, 1);
BUTTON_TABLE_ITEM("button/cbrak", 3, 3, 1, 1);
BUTTON_TABLE_ITEM("button/zero", 0, 4, 2, 1);
BUTTON_TABLE_ITEM("button/point", 2, 4, 1, 1);
BUTTON_TABLE_ITEM("button/zero", 0, 4, 1, 1);
BUTTON_TABLE_ITEM("button/point", 1, 4, 1, 1);
BUTTON_TABLE_ITEM("button/equal", 2, 4, 2, 1);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

@ -7,50 +7,42 @@
fprintf(stderr,fmt, args); \
} while(0)
#include "calc.h"
#include <Elementary.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include "config.h"
#include "calc.h"
#define BUFLEN 100
/* structures */
typedef struct
{
Ecore_Evas *ee;
Evas_Object *edje;
} Gui;
typedef enum
{
DEFAULT,
BASIC,
SCI,
EDJE
} Mode;
typedef struct
{
Mode mode;
char *theme;
} Conf;
typedef struct
{
Gui gui;
Conf conf;
} Equate;
void equate_init(Equate * equate);
void equate_quit();
#include "gui.h"
#define EQ_EXIT 1
#define OP_CLR 2
#define OP_DIV 3
#define OP_MUT 4
#define OP_ADD 5
#define OP_SUB 6
#define OP_EQU 7
#define OP_DEC 8
#define OP_SIN 9
#define OP_COS 10
#define OP_TAN 11
#define OP_ROOT 12
#define OP_POW 13
#define OP_LOG 14
#define OP_LN 15
#define OP_EXP 16
#define OP_OBRAK 17
#define OP_CBRAK 18
#define NUM_0 20
#define NUM_1 21
#define NUM_2 22
#define NUM_3 23
#define NUM_4 24
#define NUM_5 25
#define NUM_6 26
#define NUM_7 27
#define NUM_8 28
#define NUM_9 29
#define NUM_PI 30

@ -5,19 +5,17 @@ AM_CPPFLAGS = \
-I. \
-I$(top_srcdir)/lib \
-I$(top_builddir)/lib \
-DPACKAGE_PKGDATA_DIR=\"$(pkgdatadir)\" \
-DPACKAGE_DATA_DIR=\"$(pkgdatadir)\" \
-DPACKAGE_BIN_DIR=\"$(pkgbindir)\" \
@EQUATE_CFLAGS@
bin_PROGRAMS = equate
equate_SOURCES = \
gui.c \
calc_parse.c \
edje.c \
main.c \
Equate.h \
calc.h \
gui.h
calc.h
equate_LDADD = @EQUATE_LIBS@

@ -5,6 +5,7 @@
void equate_clear(void);
int equate_append(char *str);
double equate_eval(void);
const char *equate_string_get(void);
/* Fonctions type. */
typedef double (*func_t) (double);

@ -75,6 +75,7 @@
#line 1 "calc.y"
#include <math.h> /* For math functions, cos(), sin(), etc. */
#include "calc.h"
#include "Equate.h"
#define YYERROR_VERBOSE

@ -1,299 +0,0 @@
#include "Equate.h"
/**
* Edjification by atmos and digitalfallout
* edje_signals.[ch] handle the edje part of equate. Translate signals
* our edje emits into the backend. All the operators, functions, and
* input values must have a #define'd numeric constant so it can be
* evaluated in _equate_interp.
*
* Jan 10 DigitalFallout
* Added theme path detection
*
*/
#define EQ_EXIT 1
#define OP_CLR 2
#define OP_DIV 3
#define OP_MUT 4
#define OP_ADD 5
#define OP_SUB 6
#define OP_EQU 7
#define OP_DEC 8
#define OP_SIN 9
#define OP_COS 10
#define OP_TAN 11
#define OP_ROOT 12
#define OP_POW 13
#define OP_LOG 14
#define OP_LN 15
#define OP_EXP 16
#define NUM_0 20
#define NUM_1 21
#define NUM_2 22
#define NUM_3 23
#define NUM_4 24
#define NUM_5 25
#define NUM_6 26
#define NUM_7 27
#define NUM_8 28
#define NUM_9 29
#define NUM_PI 30
/**
* defined in calc.tab.c
*/
extern void equate_clear(void);
extern double equate_eval(void);
extern int equate_append(char *str);
extern const char *equate_string_get(void);
Evas_Object *equate_edje_root;
Ecore_Evas *equate_edje_window;
int equate_edje_inited;
static void
_no_filter_cb(void *data, Evas_Object * o, const char *emission, const
char *source)
{
//printf("emission: %s\t source: %s\n", emission, source);
}
/**
* Interpret all of our different signals, and do things !
*/
static void
_equate_interp(void *data, Evas_Object * o, const char *emission, const
char *source)
{
int val = 0;
if (data)
{
double result;
char buf[BUFLEN];
val = (int) data;
switch (val)
{
case EQ_EXIT:
ecore_main_loop_quit();
break;
case OP_CLR:
equate_clear();
break;
case OP_DIV:
equate_append("/");
break;
case OP_MUT:
equate_append("*");
break;
case OP_ADD:
equate_append("+");
break;
case OP_SUB:
equate_append("-");
break;
case OP_EQU:
snprintf(buf, BUFLEN, "%.10g", equate_eval());
edje_object_part_text_set(o, "EquateAnswer", buf);
return;
break;
case OP_DEC:
equate_append(".");
break;
case OP_SIN:
equate_append("sin");
break;
case OP_COS:
equate_append("cos");
break;
case OP_TAN:
equate_append("tan");
break;
case OP_ROOT:
equate_append("sqrt");
break;
case OP_POW:
equate_append("^");
break;
case OP_LOG:
equate_append("log");
break;
case OP_LN:
equate_append("ln");
break;
case OP_EXP:
equate_append("exp");
break;
case NUM_0:
equate_append("0");
break;
case NUM_1:
equate_append("1");
break;
case NUM_2:
equate_append("2");
break;
case NUM_3:
equate_append("3");
break;
case NUM_4:
equate_append("4");
break;
case NUM_5:
equate_append("5");
break;
case NUM_6:
equate_append("6");
break;
case NUM_7:
equate_append("7");
break;
case NUM_8:
equate_append("8");
break;
case NUM_9:
equate_append("9");
break;
default:
E(1, "Unknown edje signal operator %d", val);
break;
/* etc */
}
edje_object_part_text_set(o, "EquateAnswer", equate_string_get());
}
}
/* equate_edje_callback_define - setup the edje signal interceptions
* @o - the object we're assigning these callbacks to
*/
void
equate_edje_callback_define(Evas_Object * o)
{
edje_object_signal_callback_add(o,
"*", "*", _no_filter_cb,
NULL);
/** Equate Application Callbacks **/
/* EQ_EXIT - Quit Equate */
edje_object_signal_callback_add(o,
"EQ_EXIT", "*", _equate_interp,
(void *) EQ_EXIT);
/** Equate Operation Callbacks **/
/* OP_CLR - Clear Display */
edje_object_signal_callback_add(o,
"OP_CLR", "*", _equate_interp,
(void *) OP_CLR);
/* OP_DIV - Division Operator */
edje_object_signal_callback_add(o,
"OP_DIV", "*", _equate_interp,
(void *) OP_DIV);
/* OP_MUT - Mutplication Operator */
edje_object_signal_callback_add(o,
"OP_MUT", "*", _equate_interp,
(void *) OP_MUT);
/* OP_ADD - Addition Operator */
edje_object_signal_callback_add(o,
"OP_ADD", "*", _equate_interp,
(void *) OP_ADD);
/* OP_SUB - Subtraction Operator */
edje_object_signal_callback_add(o,
"OP_SUB", "*", _equate_interp,
(void *) OP_SUB);
/* OP_EQU - Equals Operator */
edje_object_signal_callback_add(o,
"OP_EQU", "*", _equate_interp,
(void *) OP_EQU);
/* OP_DEC - Decimal Operator */
edje_object_signal_callback_add(o,
"OP_DEC", "*", _equate_interp,
(void *) OP_DEC);
/* OP_SIN - Sin of x in degrees */
edje_object_signal_callback_add(o,
"OP_SIN", "*", _equate_interp,
(void *) OP_SIN);
/* OP_COS - Cos of x in degree */
edje_object_signal_callback_add(o,
"OP_COS", "*", _equate_interp,
(void *) OP_COS);
/* OP_TAN - Tan of x in degrees */
edje_object_signal_callback_add(o,
"OP_TAN", "*", _equate_interp,
(void *) OP_TAN);
/* OP_ROOT - The square root of x */
edje_object_signal_callback_add(o,
"OP_ROOT", "*", _equate_interp,
(void *) OP_ROOT);
/* OP_POW - Raise x to the y power */
edje_object_signal_callback_add(o,
"OP_POW", "*", _equate_interp,
(void *) OP_POW);
/* OP_LOG - Logarithm */
edje_object_signal_callback_add(o,
"OP_LOG", "*", _equate_interp,
(void *) OP_LOG);
/* OP_LN - the natural logarithm */
edje_object_signal_callback_add(o,
"OP_LN", "*", _equate_interp, (void *) OP_LN);
/* OP_EXP - e to the x */
edje_object_signal_callback_add(o,
"OP_EXP", "*", _equate_interp,
(void *) OP_EXP);
/** Equate Number Callbacks **/
/* NUM_0 - Zero */
edje_object_signal_callback_add(o,
"NUM_0", "*", _equate_interp, (void *) NUM_0);
/* NUM_1 - One */
edje_object_signal_callback_add(o,
"NUM_1", "*", _equate_interp, (void *) NUM_1);
/* NUM_2 - Two */
edje_object_signal_callback_add(o,
"NUM_2", "*", _equate_interp, (void *) NUM_2);
/* NUM_3 - Three */
edje_object_signal_callback_add(o,
"NUM_3", "*", _equate_interp, (void *) NUM_3);
/* NUM_4 - Four */
edje_object_signal_callback_add(o,
"NUM_4", "*", _equate_interp, (void *) NUM_4);
/* NUM_5 - Five */
edje_object_signal_callback_add(o,
"NUM_5", "*", _equate_interp, (void *) NUM_5);
/* NUM_6 - Six */
edje_object_signal_callback_add(o,
"NUM_6", "*", _equate_interp, (void *) NUM_6);
/* NUM_7 - Seven */
edje_object_signal_callback_add(o,
"NUM_7", "*", _equate_interp, (void *) NUM_7);
/* NUM_8 - Eight */
edje_object_signal_callback_add(o,
"NUM_8", "*", _equate_interp, (void *) NUM_8);
/* NUM_9 - Nine */
edje_object_signal_callback_add(o,
"NUM_9", "*", _equate_interp, (void *) NUM_9);
/* NUM_PI - 3.14159 */
edje_object_signal_callback_add(o, "NUM_PI", "*", _equate_interp,
(void *) NUM_PI);
}

@ -1,43 +0,0 @@
#include "Equate.h"
int inited = 0;
Evas_Object *win;
Evas_Object *ly;
void
equate_init_gui(Equate * equate, int argc, char **argv)
{
char buf[1024];
char *pkgdatadir;
if (inited == 1)
return;
if (equate)
{
win = elm_win_add(NULL, "equate", ELM_WIN_BASIC);
elm_win_title_set(win, "Equate");
elm_win_autodel_set(win, EINA_TRUE);
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
ly = elm_layout_add(win);
pkgdatadir = getenv("EQUATE_PKGDATA_DIR");
if (!pkgdatadir)
pkgdatadir = PACKAGE_PKGDATA_DIR;
snprintf(buf, sizeof(buf), "%s/themes/equate.edj", pkgdatadir);
elm_layout_file_set(ly, buf, "Main");
evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(ly, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_win_resize_object_add(win, ly);
evas_object_show(ly);
evas_object_show(win);
evas_object_resize(win, 200, 296);
equate_edje_callback_define(elm_layout_edje_get(ly));
inited = 1;
}
}

@ -1,12 +0,0 @@
#ifndef _EQUATE_GUI_H
#define _EQUATE_GUI_H
/* needed 'cos generated h files suck */
double yyresult(void);
void update_display(char *text);
void equate_gui_init(Equate * equate, int argc, char **arvg);
void equate_gui_quit(void);
void equate_gui_update(Equate * equate);
#endif

@ -1,22 +1,236 @@
#include <Elementary.h>
#ifndef ELM_LIB_QUICKLAUNCH
#include "Equate.h"
#include "calc.h"
Equate equate;
static Evas_Object *win;
static Evas_Object *ly;
int
main(int argc, char *argv[], char *env[])
static void
_signal_cb(void *data, Evas_Object * o, const char *emission, const
char *source)
{
int nextarg = 1, parse_ret, found;
char *arg;
int val = 0;
elm_init(argc, argv);
if (data)
{
double result;
char buf[BUFLEN];
equate.conf.mode = EDJE;
math_init();
equate_init_gui(&equate, argc, argv);
val = (int) data;
switch (val)
{
case EQ_EXIT:
elm_exit();
break;
case OP_CLR:
equate_clear();
break;
case OP_DIV:
equate_append("/");
break;
case OP_MUT:
equate_append("*");
break;
case OP_ADD:
equate_append("+");
break;
case OP_SUB:
equate_append("-");
break;
case OP_EQU:
snprintf(buf, BUFLEN, "%.10g", equate_eval());
edje_object_part_text_set(o, "EquateAnswer", buf);
return;
break;
case OP_DEC:
equate_append(".");
break;
case OP_OBRAK:
equate_append("(");
break;
case OP_CBRAK:
equate_append(")");
break;
case OP_SIN:
equate_append("sin");
break;
case OP_COS:
equate_append("cos");
break;
case OP_TAN:
equate_append("tan");
break;
case OP_ROOT:
equate_append("sqrt");
break;
case OP_POW:
equate_append("^");
break;
case OP_LOG:
equate_append("log");
break;
case OP_LN:
equate_append("ln");
break;
case OP_EXP:
equate_append("exp");
break;
case NUM_0:
equate_append("0");
break;
case NUM_1:
equate_append("1");
break;
case NUM_2:
equate_append("2");
break;
case NUM_3:
equate_append("3");
break;
case NUM_4:
equate_append("4");
break;
case NUM_5:
equate_append("5");
break;
case NUM_6:
equate_append("6");
break;
case NUM_7:
equate_append("7");
break;
case NUM_8:
equate_append("8");
break;
case NUM_9:
equate_append("9");
break;
default:
E(1, "Unknown edje signal operator %d", val);
break;
/* etc */
}
edje_object_part_text_set(o, "EquateAnswer", equate_string_get());
elm_run();
}
}
static void
_edje_callbacks_define(Evas_Object * o)
{
/** Equate Application Callbacks **/
/* EQ_EXIT - Quit Equate */
edje_object_signal_callback_add(o, "EQ_EXIT", "*", _signal_cb,
(void *) EQ_EXIT);
/** Equate Operation Callbacks **/
/* OP_CLR - Clear Display */
edje_object_signal_callback_add(o, "OP_CLR", "*", _signal_cb,
(void *) OP_CLR);
/* OP_DIV - Division Operator */
edje_object_signal_callback_add(o, "OP_DIV", "*", _signal_cb,
(void *) OP_DIV);
/* OP_MUT - Mutplication Operator */
edje_object_signal_callback_add(o, "OP_MUT", "*", _signal_cb,
(void *) OP_MUT);
/* OP_ADD - Addition Operator */
edje_object_signal_callback_add(o, "OP_ADD", "*", _signal_cb,
(void *) OP_ADD);
/* OP_SUB - Subtraction Operator */
edje_object_signal_callback_add(o, "OP_SUB", "*", _signal_cb,
(void *) OP_SUB);
/* OP_EQU - Equals Operator */
edje_object_signal_callback_add(o, "OP_EQU", "*", _signal_cb,
(void *) OP_EQU);
/* OP_DEC - Decimal Operator */
edje_object_signal_callback_add(o, "OP_DEC", "*", _signal_cb,
(void *) OP_DEC);
/* OP_SIN - Sin of x in degrees */
edje_object_signal_callback_add(o, "OP_SIN", "*", _signal_cb,
(void *) OP_SIN);
/* OP_COS - Cos of x in degree */
edje_object_signal_callback_add(o, "OP_COS", "*", _signal_cb,
(void *) OP_COS);
/* OP_TAN - Tan of x in degrees */
edje_object_signal_callback_add(o, "OP_TAN", "*", _signal_cb,
(void *) OP_TAN);
/* OP_ROOT - The square root of x */
edje_object_signal_callback_add(o, "OP_ROOT", "*", _signal_cb,
(void *) OP_ROOT);
/* OP_POW - Raise x to the y power */
edje_object_signal_callback_add(o, "OP_POW", "*", _signal_cb,
(void *) OP_POW);
/* OP_LOG - Logarithm */
edje_object_signal_callback_add(o, "OP_LOG", "*", _signal_cb,
(void *) OP_LOG);
/* OP_LN - the natural logarithm */
edje_object_signal_callback_add(o, "OP_LN", "*", _signal_cb, (void *) OP_LN);
/* OP_EXP - e to the x */
edje_object_signal_callback_add(o, "OP_EXP", "*", _signal_cb,
(void *) OP_EXP);
/* OP_OBRAK - open bracket */
edje_object_signal_callback_add(o, "OP_OBRAK", "*", _signal_cb,
(void *) OP_OBRAK);
/* OP_CBRAK - close bracket */
edje_object_signal_callback_add(o, "OP_CBRAK", "*", _signal_cb,
(void *) OP_CBRAK);
/** Equate Number Callbacks **/
edje_object_signal_callback_add(o, "NUM_0", "*", _signal_cb, (void *) NUM_0);
edje_object_signal_callback_add(o, "NUM_1", "*", _signal_cb, (void *) NUM_1);
edje_object_signal_callback_add(o, "NUM_2", "*", _signal_cb, (void *) NUM_2);
edje_object_signal_callback_add(o, "NUM_3", "*", _signal_cb, (void *) NUM_3);
edje_object_signal_callback_add(o, "NUM_4", "*", _signal_cb, (void *) NUM_4);
edje_object_signal_callback_add(o, "NUM_5", "*", _signal_cb, (void *) NUM_5);
edje_object_signal_callback_add(o, "NUM_6", "*", _signal_cb, (void *) NUM_6);
edje_object_signal_callback_add(o, "NUM_7", "*", _signal_cb, (void *) NUM_7);
edje_object_signal_callback_add(o, "NUM_8", "*", _signal_cb, (void *) NUM_8);
edje_object_signal_callback_add(o, "NUM_9", "*", _signal_cb, (void *) NUM_9);
/* NUM_PI - 3.14159 */
edje_object_signal_callback_add(o, "NUM_PI", "*", _signal_cb, (void *) NUM_PI);
}
static void
_create_gui(void)
{
char buf[1024];
win = elm_win_add(NULL, "equate", ELM_WIN_BASIC);
elm_win_title_set(win, "Equate");
elm_win_autodel_set(win, EINA_TRUE);
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
ly = elm_layout_add(win);
snprintf(buf, sizeof(buf), "%s/themes/equate.edj", elm_app_data_dir_get());
elm_layout_file_set(ly, buf, "Main");
evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(ly, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_win_resize_object_add(win, ly);
evas_object_show(ly);
evas_object_show(win);
evas_object_resize(win, 240, 320);
_edje_callbacks_define(elm_layout_edje_get(ly));
}
EAPI_MAIN int
elm_main(int argc, char **argv)
{
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR);
elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);
elm_app_info_set(elm_main, "equate", "images/equate.png");
math_init();
_create_gui();
elm_run();
elm_shutdown();
return 0;
}
#endif
ELM_MAIN()

Loading…
Cancel
Save