static int liqaccelview_paint(liqcell *self, liqcellpainteventargs *args,liqcell *context) { //liqapp_log("starpaint %4i,%4i :: '%s'::'%s'",args->mx,args->my,self->name,self->classname); //liqapp_log("drawing args==NULL==%i args->graph==NULL==%i",args==NULL, args->graph==NULL); // vgraph *graph; // args->graph; //vgraph_setbackcolor(args->graph, vcolor_YUV( (127+(rand()%128)) , (rand()%255) , (rand()%255) ) ); //vgraph_drawbox(args->graph, 10, 40, 300, 400 ); //vgraph_setpencolor(args->graph, vcolor_YUV(255,128,128) ); if( liqcell_propgeti(self,"dialog_running",0)==1 ) { liqaccelview_runchannel((liqcell*)self); //star_calc(self,(STAR *)self->tag, args->graph, liqcell_getsketch(self), args->mx,args->my ); //liqcell_setdirty(self,1); } else { // nothing for now... should show a picture or something.. } //liqapp_log("drawing done"); return 1; }
/** * dialog_selectcolor_colorcube paint - being rendered. use the vgraph held in args to do custom drawing at scale */ static int dialog_selectcolor_colorcube_paint(liqcell *self, liqcellpainteventargs *args,liqcell *context) { // // big heavy event, use sparingly int cy = liqcell_propgeti(self,"colorcube_brightness",128); vgraph_setpencolor( args->graph,vcolor_YUV(cy,128,128) ); vgraph_drawcolorcube(args->graph,0,0,self->w,self->h); return 0; }
/** * liqcalc_run paint - being rendered. use the vgraph held in args to do custom drawing at scale */ static int liqcalc_run_paint(liqcell *self, liqcellpainteventargs *args,liqcell *liqcalc_run) { // big heavy event, use sparingly liqcell *solarcell = liqcell_child_lookup(liqcalc_run, "solarcell"); liqcell *calclcd = liqcell_child_lookup(liqcalc_run, "calclcd"); if( liqcell_easyrun_getactivecontrol() == solarcell && liqcell_easyrun_fingerpressed) { // fade the text.. int solarbrightness = liqcell_propgeti(calclcd,"solarbrightness",255); liqapp_log("solar -- %d",solarbrightness); if(solarbrightness>0) { solarbrightness-=4; if(solarbrightness<0)solarbrightness=0; if(solarbrightness>255)solarbrightness=255; liqcell_propsets_printf(calclcd,"backcolor","rgb(%d,%d,%d)",solarbrightness,solarbrightness,solarbrightness); liqcell_propseti( calclcd, "solarbrightness", solarbrightness ); liqcell_setdirty(calclcd,1); } } else { int solarbrightness = liqcell_propgeti(calclcd,"solarbrightness",255); liqapp_log("solar ++ %d",solarbrightness); if(solarbrightness<255) { solarbrightness+=16; if(solarbrightness<0)solarbrightness=0; if(solarbrightness>255)solarbrightness=255; liqcell_propsets_printf(calclcd,"backcolor","rgb(%d,%d,%d)",solarbrightness,solarbrightness,solarbrightness); liqcell_propseti( calclcd, "solarbrightness", solarbrightness ); liqcell_setdirty(calclcd,1); } // bring the text back up ;) } return 0; }
static int keyboard_show_button_click(liqcell *self,liqcellclickeventargs *args, liqcell *textbox) { liqcell *vkbd = liqcell_quickcreatevis("vkbd", "liqkeyboard", 0, 0, -1, -1); liqcell *vkbd_textbox = liqcell_child_lookup(vkbd, "liqkeyboard_textbox"); if(vkbd) { // 20090814_203451 lcuk : make sure the * follow into the vkb :) liqcell_propseti(vkbd_textbox,"textispassword", liqcell_propgeti(textbox,"textispassword",0) ); char *caption = liqcell_getcaption(textbox); liqcell_setcaption(vkbd_textbox, caption); liqcell_setdata(vkbd, textbox); liqcell_easyrun(vkbd); liqcell_release(vkbd); } return 1; }
static void *liqtimer_workthread(void* workthread_data) { liqcell *self = (liqcell *)workthread_data; //liqapp_sleep(100 + (rand() % 4000)); //liqapp_sleep(100 + (rand() % 2000)); //liqapp_sleep(10 + (rand() % 100)); //liqcell_setdirty(self); while(1) { liqcell_hold(self); //liqapp_log("looping.."); if(liqcell_getenabled(self)) { int dt = liqcell_propgeti(self,"timerinterval",0); if(dt<=0)dt=1; liqcell_release(self); liqapp_sleep(dt); //liqapp_log("ticking.."); liqcell_hold(self); liqcell_handlerrun(self,"timertick",NULL); liqcell_release(self); } else { liqcell_release(self); liqapp_sleep(50); //liqcell_handlerrun(keyhit,"timertick",NULL); } } return NULL; }
/** * liqpostcard.cmdsend clicked */ static int cmdsend_click(liqcell *self,liqcelleventargs *args, liqcell *liqpostcard) { liqcell *picfront = liqcell_child_lookup(liqpostcard, "picfront"); liqcell *messageback = liqcell_child_lookup(liqpostcard, "messageback"); liqcell *tweetmessage = liqcell_child_lookup(liqpostcard, "tweetmessage"); liqimage *imgfront = liqcell_getimage(picfront); liqimage *imgback = liqcell_getimage(messageback); liqsketch *sketch = liqcell_getsketch(messageback); char *tweet = liqcell_getcaption(tweetmessage); if(!imgfront) { liqapp_log("cmdsend_click need imgfront"); return -1; } if(!imgback) { liqapp_log("cmdsend_click need imgback"); return -1; } if(!sketch) { liqapp_log("cmdsend_click need sketch"); return -1; } if(!tweet || !*tweet) { liqapp_log("cmdsend_click need tweet"); return -1; } //liqpostcard_sendnow(liqpostcard,imgfront,imgback,sketch, tweet); liqpostcard_master = liqpostcard; liqcell * progress = liqcell_quickcreatevis("liqpostcard.liqpostcard_sendprogress","liqpostcard.liqpostcard_sendprogress",0,0,-1,-1); if(progress) { liqcell_easyrun(progress); int sentok = liqcell_propgeti(progress,"sentok",0); liqcell_release(progress); if(!sentok) { //return 0; } if(sentok) { liqcell_setcaption(tweetmessage,""); liqsketch_clear(sketch); } } liqpostcard_master = NULL; return 0; }
static int textbox_keypress(liqcell *self, liqcellkeyeventargs *args,void *context) { //liqcell *base = liqcell_getbasewidget(self); // i can then use my base to access members as defined by the widget itself //liqcell_setcaption(self,args->keystring); int selstart = liqcell_propgeti( self,"selstart",-1); int sellength = liqcell_propgeti( self,"sellength",0); int cursorpos = liqcell_propgeti( self,"cursorpos",-1); char *caption = liqcell_getcaption(self); int captionlen = strlen(caption); char *key = args->keystring; int keylen = strlen(key); if(selstart>captionlen){ selstart=captionlen;sellength=0; } if(selstart+sellength>captionlen) { sellength = captionlen-selstart; } if(selstart>=0 && (keylen>0)) { liqapp_log("keypress: %3i '%c'",(int)(*key),*key,args->keycode); if(*key==8) { // delete ;) key=""; keylen=0; if(selstart>0 && sellength==0) { selstart--; sellength++; } } if(*key==13) { // click event! liqapp_log("keypress return! click event firing!"); key=""; keylen=0; liqcell_handlerrun(self,"click",NULL); return 1; } // //liqcell_setcaption(self,args->keystring); char *aftersel=&caption[selstart+sellength]; int aftersellen = strlen(aftersel); // then the result is start..selstart // newbit // selstart+sellen..end int reqd = selstart + keylen + aftersellen + 1; char *buff=malloc(reqd); char *block=buff; if(buff) { if(selstart>0) { strncpy(block,caption,selstart); block+=selstart; } if(keylen>0) { strncpy(block,key,keylen); block+=keylen; } if(aftersellen>0) { strncpy(block,aftersel,aftersellen); block+=aftersellen; } *block=0; liqcell_setcaption(self,buff); free(buff); } liqcell_propseti( self, "selstart", selstart + keylen); liqcell_propseti( self, "sellength", 0 ); liqcell_propseti( self, "cursorpos", selstart + keylen); liqcell_handlerrun(self,"selchange",NULL); } }
// damn, this should be taken care of by the OS itself // this is because the hitpoint will not always match with where I think it will be // this is bad and good in practice static int textbox_mouse(liqcell *self, liqcellmouseeventargs *args,void *context) { // if i have a font on my cell, surely it will have been rendered correctly first.. // infact, thats right i think //liqcell *base = liqcell_getbasewidget(self); liqcell *body = self; liqfont *font = liqcell_getfont( self); if(!font)return 0; char *cap = liqcell_getcaption(self); if(!cap)return 0; int caplen = strlen(cap); int mx = args->mex - liqcell_getx(self); int chpos = liqfont_textfitinside(font,cap,mx); // neat :) i know where the mouse clicked (left aligned text only...) // todo: handle other alignments if(args->mcnt==1) { // start of selection.. liqcell_propseti( self, "selfirst", chpos ); liqcell_propseti( self, "selstart", chpos ); liqcell_propseti( self, "sellength", 0 ); liqcell_propseti( self, "cursorpos", chpos ); } else { // extending selection int selfirst = liqcell_propgeti( self,"selfirst",chpos); int selstart; int sellength; if(chpos<selfirst) { // got to invert selstart=chpos; sellength=selfirst-chpos; } else { selstart=selfirst; sellength=chpos-selfirst; } liqcell_propseti( self, "selstart", selstart ); liqcell_propseti( self, "sellength", sellength ); liqcell_propseti( self, "cursorpos", chpos ); } liqcell_handlerrun(self,"selchange",NULL); return 1; }
static int textbox_mouse(liqcell *self, liqcellmouseeventargs *args,void *context) { // if i have a font on my cell, surely it will have been rendered correctly first.. // infact, thats right i think //liqcell *base = liqcell_getbasewidget(self); //liqcell *body = self; liqfont *font = liqcell_getfont( self); if(!font)return 0; char *cap = liqcell_getcaption(self); if(!cap)return 0; // 20090814_184437 lcuk : if password, replace cap with string("*",len(cap)) for selection purposes char passbuff[1024]; if(liqcell_propgeti(self,"textispassword",0)) { int clen = strlen(cap); if(clen>=sizeof(passbuff)-1)clen=sizeof(passbuff)-1; int x; for(x=0;x<clen;x++)passbuff[x]='*'; passbuff[x]=0; cap=passbuff; } //int caplen = strlen(cap); //########################## // this tells me where abouts I am on a single line int mx = args->mex - liqcell_getx(self) - 8; // available space per line int my = args->mey - liqcell_gety(self) - 4; int chpos = liqfont_textfitinside(font,cap,mx); // char pos of selection //########################## // count all the lines #define linemax 128 char *linestarts[linemax]; int lineheight = liqfont_textheight(font); int lineoffsets[linemax]; int linelengths[linemax]; int linecount=0; char *c = cap; while(c && *c) { int tl = strlen(c); // total length remaining int lc = liqfont_textfitinside(font, c, liqcell_getw(self)-4 ); if(lc<tl) { int le = lc; while(le>0) { switch(c[le-1]) { case ' ': case ',': case ';': case ':': case '.': le--; break; default: goto fin; } } fin: if(le>0)lc=le; while(c[lc]==' ')lc++; } linestarts[linecount] = c; lineoffsets[linecount] = c-cap; linelengths[linecount] = lc; linecount++; c=&c[lc]; } //########################## // work out which line the mouse has hit int lx=mx; int ly=0; ly = my / lineheight; //liqapp_log("mx=%3i, my=%3i, chpos=%3i lx=%3i, ly=%3i",mx,my,chpos, lx,ly); if(ly>=linecount)ly=linecount-1; if(ly>=0) { // adjust chpos to make sure now we are selecting from the correct line chpos = lineoffsets[ly] + liqfont_textfitinside(font, linestarts[ly] ,mx); } // neat :) i know where the mouse clicked (left aligned text only...) // todo: handle other alignments if(args->mcnt==1) { // start of selection.. liqcell_propseti( self, "selfirst", chpos ); liqcell_propseti( self, "selstart", chpos ); liqcell_propseti( self, "sellength", 0 ); liqcell_propseti( self, "cursorpos", chpos ); } else { // extending selection int selfirst = liqcell_propgeti( self,"selfirst",chpos); int selstart; int sellength; if(chpos<selfirst) { // got to invert selstart=chpos; sellength=selfirst-chpos; } else { selstart=selfirst; sellength=chpos-selfirst; } liqcell_propseti( self, "selstart", selstart ); liqcell_propseti( self, "sellength", sellength ); liqcell_propseti( self, "cursorpos", chpos ); } return 1; }
static int textbox_keypress(liqcell *self, liqcellkeyeventargs *args,void *context) { //liqcell *base = liqcell_getbasewidget(self); // i can then use my base to access members as defined by the widget itself //liqcell_setcaption(self,args->keystring); int selstart = liqcell_propgeti( self,"selstart",-1); int sellength = liqcell_propgeti( self,"sellength",0); int cursorpos = liqcell_propgeti( self,"cursorpos",-1); char *caption = liqcell_getcaption(self); int captionlen = strlen(caption); char *key =strdup( args->keystring ? args->keystring : ""); //if(!key)key=""; if(*key && *key<32) { if(*key==10) { // Wed Aug 19 00:17:53 2009 lcuk : change this now to send a different event :) // Wed Aug 19 00:18:00 2009 lcuk : easier to get a special "keypress_enter" message and know what to do // Wed Aug 19 00:23:07 2009 lcuk : lots of things do stuff when you press enter // Wed Aug 19 00:23:17 2009 lcuk : alternative is a default button as in visual basic // Wed Aug 19 00:23:41 2009 lcuk : how do i find the related default button though within the system liqcell_handlerrun(self,"keypress_enter",NULL); free(key); key=strdup(""); } if(*key==8 || *key==9) { // bs and tab } else { // ack! ignore these in single line textbox! free(key); key=strdup(""); } } int keylen = strlen(key); if(selstart>captionlen){ selstart=captionlen;sellength=0; } if(selstart+sellength>captionlen) { sellength = captionlen-selstart; } if(selstart>=0)// && (keylen>0)) { liqapp_log("keypress: %3i '%c' %i %i",(int)(*key),*key,args->keycode,args->keymodifierstate); if(cursorpos<0)cursorpos=0; if(keylen==0) { // special keys if(args->keycode==XK_Left) { selstart--; if(selstart<0)selstart=0; if(args->keymodifierstate==0) sellength=0; else sellength++; cursorpos=selstart; liqcell_propseti( self, "selstart", selstart); liqcell_propseti( self, "sellength", sellength); liqcell_propseti( self, "cursorpos", cursorpos); } else if(args->keycode==XK_Right) { if(args->keymodifierstate==0) { selstart+=sellength+1; if(selstart>captionlen)selstart=captionlen; sellength=0; //cursorpos=selstart; } else { sellength++; //cursorpos=selstart+sellength; //if(cursorpos>captionlen)cursorpos=captionlen; } if(selstart+sellength>captionlen) { sellength = captionlen-selstart; } cursorpos=selstart+sellength; liqcell_propseti( self, "selstart", selstart); liqcell_propseti( self, "sellength", sellength); liqcell_propseti( self, "cursorpos", cursorpos); } else { if(args->keycode==120 && (args->keymodifierstate&4)) { liqapp_log("key CTRL X :: CUT"); if(liqclip){free(liqclip);liqclip=NULL;} liqclip = strndup(&caption[selstart],sellength); free(key); key=strdup(""); keylen = strlen(key); goto selch; } if(args->keycode==99 && (args->keymodifierstate&4)) { liqapp_log("key CTRL C :: COPY"); if(liqclip){free(liqclip);liqclip=NULL;} liqclip = strndup(&caption[selstart],sellength); free(key); return 0; } if(args->keycode==118 && (args->keymodifierstate&4)) { liqapp_log("key CTRL V :: PASTE"); free(key); key=strdup(liqclip?liqclip:""); keylen = strlen(key); goto selch; } } } else { // regular keypress if(*key==8) { // delete ;) free(key); key=strdup(""); keylen = strlen(key); if(selstart>0 && sellength==0) { selstart--; sellength++; } } selch: { } // //liqcell_setcaption(self,args->keystring); char *aftersel=&caption[selstart+sellength]; int aftersellen = strlen(aftersel); // then the result is start..selstart // newbit // selstart+sellen..end int maxlen = liqcell_propgeti( self,"maxlength",0); if(maxlen>0) { if( (selstart + keylen + aftersellen)>maxlen ) keylen = maxlen-(selstart+aftersellen); if(keylen<0)keylen=0; } // !-- BUG FIX BY ZACH HABERSANG -- ! // ---------------------------------- // Program would segfault when 25 or so characters were entered // Fix: + 1 fix to reqd! :D // note: used gdb with backtrace to find this bug // 20090615_210659 lcuk : and me to explain why it was wrong ;) damn those +1 adjustments.. int reqd = selstart + keylen + aftersellen + 1; char *buff=malloc(reqd); char *block=buff; if(buff) { if(selstart>0) { strncpy(block,caption,selstart); block+=selstart; } if(keylen>0) { strncpy(block,key,keylen); block+=keylen; } if(aftersellen>0) { strncpy(block,aftersel,aftersellen); block+=aftersellen; } *block=0; liqcell_setcaption(self,buff); free(buff); } liqcell_propseti( self, "selstart", selstart + keylen); liqcell_propseti( self, "sellength", 0 ); liqcell_propseti( self, "cursorpos", selstart + keylen); } } if(key)free(key); return 0; }