00001
00002
00003 char *task_chcolors_cpp = "$Id: sxy_task_chcolors.cpp,v 1.1 2002/11/25 19:52:05 clinio Exp $";
00004
00005
00006
00007 #include <assert.h>
00008 #include <xy.h>
00009
00010 extern "C" {
00011 #include <iup.h>
00012 #include <iupgc.h>
00013 #include <cd.h>
00014 }
00015
00016 #include "sxy_chart.h"
00017 #include "sxy_graph.h"
00018 #include "sxy_task.h"
00019 #include "sxy_task_chcolors.h"
00020
00021 #define HIDDEN_CHART "HIDDEN_CHART_ATTRIBUTE_AT_TASK"
00022
00023
00024
00025 static int cb_main_color( Ihandle* h );
00026 static int cb_grid_color( Ihandle* h );
00027 static int cb_back_color( Ihandle* h );
00028
00029
00030
00031 SXYTaskReturn SXYTaskChangeChartColors::mouseClick(SXYGraph* graph, int b,
00032 int x, int y, int sft, int ctr) {
00033 if (b != 3) return CALLBACK_NOT_TREATED;
00034
00035 int cht = graph->getChartOfEvent(x, y);
00036 if (cht < 0) return CALLBACK_NOT_TREATED;
00037 SXYChart* chart = graph->getChart(cht);
00038 if ( !chart ) return CALLBACK_NOT_TREATED;
00039
00040 popupActions( chart );
00041 return CALLBACK_TREATED;
00042 }
00043
00044
00045
00046 SXYTaskReturn SXYTaskChangeChartColors::mouseUnclick(SXYGraph* graph, int b,
00047 int x, int y, int sft, int ctr) {
00048 return CALLBACK_NOT_TREATED;
00049 }
00050
00051
00052
00053 SXYTaskReturn SXYTaskChangeChartColors::mouseMotion(SXYGraph* graph, int x, int y,
00054 int sft, int ctr) {
00055 return CALLBACK_NOT_TREATED;
00056 }
00057
00058
00059
00060 SXYTaskReturn SXYTaskChangeChartColors::mouseEnter(SXYGraph* graph) {
00061 return CALLBACK_NOT_TREATED;
00062 }
00063
00064
00065
00066 SXYTaskReturn SXYTaskChangeChartColors::mouseLeave(SXYGraph* graph) {
00067 return CALLBACK_NOT_TREATED;
00068 }
00069
00070
00071
00072 Ihandle* SXYTaskChangeChartColors::createMenu(SXYChart* chart) {
00073 char* strings[] = {
00074 "Editar cor de fundo",
00075 "Editar cor principal"
00076
00077 };
00078 char* callbacks[] = {
00079 "cb_back_color",
00080 "cb_main_color"
00081
00082 };
00083
00084 int nitens = sizeof(callbacks) / sizeof(char*);
00085 Ihandle *iup_menu = IupMenu(NULL);
00086 IupSetAttribute(iup_menu, HIDDEN_CHART, (char*)chart);
00087 for (int i = 0; i < nitens; i++) {
00088 Ihandle* iup_item = IupItem( strings[i], callbacks[i]);
00089 IupSetAttribute(iup_item, HIDDEN_CHART, (char*)chart);
00090 IupAppend(iup_menu, iup_item);
00091 }
00092
00093 IupSetFunction("cb_back_color", (Icallback) cb_back_color);
00094 IupSetFunction("cb_main_color", (Icallback) cb_main_color);
00095 IupSetFunction("cb_grid_color", (Icallback) cb_grid_color);
00096
00097 return iup_menu;
00098 }
00099
00100
00101
00102 void SXYTaskChangeChartColors::popupActions(SXYChart* chart) {
00103 Ihandle* iup_menu = createMenu(chart);
00104 IupPopup(iup_menu, IUP_MOUSEPOS, IUP_MOUSEPOS);
00105 IupDestroy(iup_menu);
00106 }
00107
00108
00109
00110 SXYTaskChangeChartColors::SXYTaskChangeChartColors(void) {
00111 }
00112
00113
00114
00115 SXYTaskChangeChartColors::~SXYTaskChangeChartColors() {
00116 };
00117
00118
00119
00120 static int cb_back_color( Ihandle* h ) {
00121 SXYChart* cht = (SXYChart*) IupGetAttribute( h, HIDDEN_CHART );
00122 assert(cht);
00123 long int color = cht->getBackgroundColor();
00124 unsigned char r, g, b;
00125 r = (color & 0xFF0000) >> 16;
00126 g = (color & 0x00FF00) >> 8;
00127 b = (color & 0x0000FF);
00128 int answer = IupGetColor( IUP_CENTER, IUP_CENTER, &r, &g, &b );
00129 if ( answer == 1 ) {
00130 color = r << 16 | g << 8 | b;
00131 cht->setBackgroundColor(color);
00132 }
00133 return IUP_DEFAULT;
00134 }
00135
00136
00137
00138 static int cb_main_color( Ihandle* h ) {
00139 SXYChart* cht = (SXYChart*) IupGetAttribute( h, HIDDEN_CHART );
00140 assert(cht);
00141 long int color = cht->getMainColor();
00142 unsigned char r, g, b;
00143 r = (color & 0xFF0000) >> 16;
00144 g = (color & 0x00FF00) >> 8;
00145 b = (color & 0x0000FF);
00146 int answer = IupGetColor( IUP_CENTER, IUP_CENTER, &r, &g, &b );
00147 if ( answer == 1 ) {
00148 color = r << 16 | g << 8 | b;
00149 cht->setMainColor(color);
00150 }
00151 return IUP_DEFAULT;
00152 }
00153
00154
00155
00156 static int cb_grid_color( Ihandle* h ) {
00157 SXYChart* cht = (SXYChart*) IupGetAttribute( h, HIDDEN_CHART );
00158 assert(cht);
00159 long int color = cht->getGridColor();
00160 unsigned char r, g, b;
00161 r = (color & 0xFF0000) >> 16;
00162 g = (color & 0x00FF00) >> 8;
00163 b = (color & 0x0000FF);
00164 int answer = IupGetColor( IUP_CENTER, IUP_CENTER, &r, &g, &b );
00165 if ( answer == 1 ) {
00166 color = r << 16 | g << 8 | b;
00167 cht->setGridColor(color);
00168 }
00169 return IUP_DEFAULT;
00170 }
00171