📄 main.c
字号:
/* Y o u r D e s c r i p t i o n *//* AppBuilder Photon Code Lib *//* Version 1.12E *//* Standard headers */#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>/* Toolkit headers */#include <Ph.h>#include <Pt.h>#include <Ap.h>#include <photon/PxImage.h>/* Local headers */#include "abimport.h"#include "proto.h"//#include "drag.h"typedef struct{ char * name; int l; char * p;} TIPO_LINHA;TIPO_LINHA tipo_linha[] = {// "solid", 0, NULL,// "dotted", 1, "\1", "dashed", 2, "\10\4", };// variaveis globaisPtArg_t args[10];//ELEMENTO * wsinal;PtWidget_t * wsinal;//static int cont = 0;static int pto_ini_x = 0, pto_ini_y = 0, pto_fim_x = 0, pto_fim_y = 0;PtWidget_t * retangulo;PhPoint_t posicao;PhPoint_t origem;PtRawCallback_t bound_callback;int under_widget( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo ){ PhPoint_t * pontos; PtArg_t arg[2]; PhPoint_t points[]= { {164, 129}, {216, 155} }; char n = 0; widget = widget, apinfo = apinfo, cbinfo = cbinfo; if(cbinfo->event->subtype == Ph_EV_PTR_ENTER) { pontos = (PhPoint_t *) malloc (sizeof(PhPoint_t) * 4); (pontos+0)->x = (points+0)->x; (pontos+0)->y = (points+0)->y; (pontos+1)->x = (points+1)->x; (pontos+1)->y = (points+1)->y; PtSetArg(&arg[n++], Pt_ARG_POINTS, pontos, 2); PtSetArg(&arg[n++], Pt_ARG_LINE_WIDTH, 4, 4); PtSetArg(&arg[n++], Pt_ARG_COLOR, Pg_CYAN, 0); wsinal = PtCreateWidget(PtRect, ABW_sa_area, n, arg); PtRealizeWidget(wsinal); } else if(cbinfo->event->subtype == Ph_EV_PTR_LEAVE) { PtDestroyWidget(wsinal); wsinal = NULL; } return( Pt_CONTINUE );}int moving( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo ){ PhRect_t * rect; PhPoint_t pos; char x[5], y[5]; /* eliminate 'unreferenced' warnings */ widget = widget, apinfo = apinfo; rect = PhGetData( cbinfo->event ); PtTranslateRect( rect, &cbinfo->event->translation ); pos.x = rect->ul.x; pos.y = rect->ul.y; sprintf(x, "%d", pos.x); sprintf(y, "%d", pos.y); PtSetArg(&args[0], Pt_ARG_TEXT_STRING, x, 0); PtSetResources( ABW_tx_x, 1, args ); PtSetArg(&args[0], Pt_ARG_TEXT_STRING, y, 0); PtSetResources(ABW_tx_y, 1, args); return( Pt_CONTINUE );}intinicia_selecao( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo ){ PhRect_t * rect; PhPoint_t pos; /* eliminate 'unreferenced' warnings */ widget = widget, apinfo = apinfo; // antes de destruir deve verificar se o clique foi executado sobre o mesmo, por exemplo para move-lo if(retangulo != NULL) { PtDestroyWidget(retangulo); retangulo = NULL; } rect = PhGetData( cbinfo->event ); PtTranslateRect( rect, &cbinfo->event->translation ); pos.x = rect->ul.x; pos.y = rect->ul.y; // recupera as coordenadas do ponto inicial pto_ini_x = pos.x; pto_ini_y = pos.y; posicao.x = pos.x - pos.x; posicao.y = pos.y - pos.y; origem.x = pos.x; origem.y = pos.y; // guarda as coordenadas do ponto final, que sera atualizado enquanto o mouse esta sendo movido para o "redraw" // do retangulo de selecao// pto_fim_x = pos.x;// pto_fim_y = pos.y; return( Pt_CONTINUE );}intfinaliza_selecao( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo ){ PhRect_t * rect; PhPoint_t pos; PtArg_t argl[2]; /* eliminate 'unreferenced' warnings */ widget = widget, apinfo = apinfo; rect = PhGetData( cbinfo->event ); PtTranslateRect( rect, &cbinfo->event->translation ); pos.x = rect->ul.x; pos.y = rect->ul.y; // guarda as coordenadas do ponto final, que sera atualizado enquanto o mouse esta sendo movido para o "redraw" // do retangulo de selecao pto_fim_x = pos.x; pto_fim_y = pos.y; // desenha retangulo da area de selecao// PgSetStrokeColor(Pg_WHITE);// PgSetStrokeDash(DLPtr->p, DLPtr->l, 0x10000);// PgDrawIRect(pto_ini_x, pto_ini_y, pto_fim_x, pto_fim_y, Pg_DRAW_STROKE);// pontos = (PhPoint_t *) malloc (sizeof(PhPoint_t) * 4);// (pontos+0)->x = pto_ini_x;// (pontos+0)->y = pto_ini_y;// (pontos+1)->x = pto_fim_x;// (pontos+1)->y = pto_fim_y;//// PtSetArg(&argl[0], Pt_ARG_POINTS, pontos, 2);// PtSetArg(&argl[1], Pt_ARG_LINE_WIDTH, 2, 2);// PtSetArg(&argl[2], Pt_ARG_COLOR, Pg_BLACK, 0);// if(cont == 0)// {// retangulo = PtCreateWidget(PtRect, ABW_sa_area, 3, argl);// PtRealizeWidget(retangulo); // cont++;// }// else// if(cont == 1)// {// cont--;// } if(retangulo != NULL) { bound_callback.event_f = seta_cursor; bound_callback.event_mask = Ph_EV_BOUNDARY;// bound_callback.data = (void *) PtSetArg(&argl[0], Pt_ARG_RAW_CALLBACKS, &bound_callback, 0); PtSetArg(&argl[1], Pt_ARG_LINE_WIDTH, 4, 2); PtSetResources(retangulo,2, argl); } return( Pt_CONTINUE );}intatualiza_ptos( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo ){ PhRect_t * rect; PhPoint_t pos; char x[5], y[5]; PtArg_t argl[10]; PhPoint_t * pontos=NULL; /* eliminate 'unreferenced' warnings */ widget = widget, apinfo = apinfo; rect = PhGetData( cbinfo->event ); PtTranslateRect( rect, &cbinfo->event->translation ); pos.x = rect->ul.x; pos.y = rect->ul.y; sprintf(x, "%d", pos.x); sprintf(y, "%d", pos.y); PtSetArg(&args[0], Pt_ARG_TEXT_STRING, x, 0); PtSetResources( ABW_tx_x, 1, args ); PtSetArg(&args[0], Pt_ARG_TEXT_STRING, y, 0); PtSetResources(ABW_tx_y, 1, args); // guarda as coordenadas do ponto final, que sera atualizado enquanto o mouse esta sendo movido para o "redraw" // do retangulo de selecao pto_fim_x = pos.x; pto_fim_y = pos.y; // desenha retangulo da area de selecao// PgSetStrokeColor(Pg_WHITE);// PgSetStrokeDash(DLPtr->p, DLPtr->l, 0x10000);// PgDrawIRect(pto_ini_x, pto_ini_y, pto_fim_x, pto_fim_y, Pg_DRAW_STROKE); if(retangulo != NULL) { PtDestroyWidget(retangulo); retangulo = NULL; // libera a memoria alocada anteriormente// free(pontos); } // a cada movimento do mouse destroy o reatangulo anterior e cria um novo pontos = (PhPoint_t *) malloc (sizeof(PhPoint_t) * 4); (pontos+0)->x = pto_ini_x; (pontos+0)->y = pto_ini_y; (pontos+1)->x = pto_fim_x; (pontos+1)->y = pto_fim_y; PtSetArg(&argl[0], Pt_ARG_POINTS, pontos, 2); PtSetArg(&argl[1], Pt_ARG_LINE_WIDTH, 2, 2); PtSetArg(&argl[2], Pt_ARG_COLOR, Pg_GREEN, 0); PtSetArg(&argl[3], Pt_ARG_FLAGS, Pt_TRUE, Pt_SET); PtSetArg(&argl[4], Pt_ARG_FLAGS, Pt_TRUE, Pt_SELECT_NOREDRAW); PtSetArg(&argl[3], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_MOVE, 0);// PtSetArg(&argl[4], Pt_ARG_ORIGIN, &posicao, 0);// PtSetArg(&argl[5], Pt_ARG_POS, &origem, 0); retangulo = PtCreateWidget(PtRect, ABW_sa_area, 4, argl); PtRealizeWidget(retangulo); return( Pt_CONTINUE );}intseta_cursor( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo ){ PtArg_t argu[1]; if(cbinfo->event->subtype == Ph_EV_PTR_ENTER) { PtSetArg(&argu[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_MOVE, 0); PtSetResources(retangulo,1, argu); //PtSetResources(ABW_bt_snap,1, argu); } else { PtSetArg(&argu[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_FINGER, 0); PtSetResources(retangulo,1, argu); } return(Pt_CONTINUE);}int CB_ACT_bt_snap( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo ){ /* eliminate 'unreferenced' warnings */ widget = widget, apinfo = apinfo, cbinfo = cbinfo; system("snapshot"); return( Pt_CONTINUE );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -