bool BasicEditboxView::mouseDrag(int x, int y) { int textheight = text_height(textfont); if(model->getSelection().isSelecting()) { pair<int, int> oldsel = model->getSelection().getSelection(); CharPos cp = findCharacter(x,y); model->getCursor().updateCursor(cp.totalIndex); model->getSelection().adjustSelection(model->getCursor()); if(y < area_ystart) { view_y = zc_max(0, view_y-1); } if(y > area_ystart+area_height) { int ymost = zc_max(area_height, (int)model->getLines().size()*textheight); view_y = zc_min(ymost-area_height, view_y+1); } if(x < area_xstart) view_x = zc_max(0, view_x-1); if(x > area_xstart+area_width) { int xmost = zc_max(area_width, view_width); view_x = zc_min(xmost-area_width, view_x+1); } if(oldsel != model->getSelection().getSelection()) { return true; } } return false; }
void master_volume(int dv,int mv) { if(dv>=0) digi_volume=zc_max(zc_min(dv,255),0); if(mv>=0) midi_volume=zc_max(zc_min(mv,255),0); int i = zc_min(zc_max(currmidi,0),MAXMIDIS-1); set_volume(digi_volume,mixvol(tunes[i].volume,midi_volume)); }
void BasicEditboxView::enforceHardLimits() { int textheight = text_height(textfont); int ymost = zc_max(area_height, (int)model->getLines().size()*textheight); view_y = zc_max(view_y, 0); view_y = zc_min(view_y, ymost-area_height); int xmost = zc_max(area_width, view_width); view_x = zc_max(view_x, 0); view_x = zc_min(view_x, xmost-area_width); }
void BasicEditboxView::ensureCursorOnScreen() { CursorPos cp = model->findCursor(); int textheight = text_height(textfont); int cystart = cp.lineno*textheight; int cyend = cystart+textheight; view_y = zc_min(view_y, cystart); view_y = zc_max(view_y, cyend-area_height); view_x = zc_min(view_x, cp.x); view_x = zc_max(view_x, cp.x-area_width); //enforce hard limits enforceHardLimits(); }
void EditboxView::invertRectangle(int x1, int y1, int x2, int y2) { //I don't feel like dicking around with colormaps right now //this method is SLOOOW, big efficiency opportunity here static std::map<int, int> invmap; RGB color; //don't wast time drawing in stupid places x1 = zc_max(x1, 0); x1 = zc_min(x1, host->w); x2 = zc_max(x2,0); x2 = zc_min(x2, host->w); y1 = zc_max(y1, 0); y1 = zc_min(y1, host->h); y2 = zc_max(y2, 0); y2 = zc_min(y2, host->h); for(int i=x1; i<x2; i++) { for(int j=y1; j<y2; j++) { int c = getpixel(dbuf, i,j); if(c != -1) { std::map<int, int>::iterator it = invmap.find(c); int invcolor; if(it == invmap.end()) { Backend::palette->getPaletteEntry(c, color); unsigned char r = 4*(((~color.r)&0x3F)+1)-1; unsigned char g = 4*(((~color.g)&0x3F)+1)-1; unsigned char b = 4*(((~color.b)&0x3F)+1)-1; invcolor = makecol(r,g,b); invmap[c] = invcolor; } else invcolor = it->second; putpixel(dbuf, i,j,invcolor); } } } }
void EditboxVScrollView::drawExtraComponents() { int textheight = text_height(textfont); //draw the scrollbar draw_arrow_button(dbuf, toparrow_x-host->x, toparrow_y-host->y, 16, 16, true, toparrow_state*3); draw_arrow_button(dbuf, bottomarrow_x-host->x, bottomarrow_y-host->y, 16, 16, false, bottomarrow_state*3); if(!sbarpattern) { sbarpattern = create_bitmap_ex(bitmap_color_depth(screen),2,2); putpixel(sbarpattern, 0, 1, scheme[jcLIGHT]); putpixel(sbarpattern, 0, 1, scheme[jcLIGHT]); putpixel(sbarpattern, 0, 1, scheme[jcLIGHT]); putpixel(sbarpattern, 0, 1, scheme[jcLIGHT]); } drawing_mode(DRAW_MODE_COPY_PATTERN, sbarpattern, 0, 0); int barstart = toparrow_y + 16 - host->y; int barend = bottomarrow_y - host->y-1; if(barstart < barend) rectfill(dbuf, toparrow_x-host->x, barstart, toparrow_x-host->x+15, barend, 0); solid_mode(); //compute the bar button, based on view_y int totallen = (int)model->getLines().size()*textheight; int available = bottomarrow_y-(toparrow_y+16); if(available < 0) { baroff=barlen=0; } else { //area_height:totallen = barlen:available barlen = (available*area_height)/zc_max(totallen,area_height)+1; //clip to reasonable values barlen = zc_max(barlen, 8); baroff = zc_min(baroff, available-barlen); //view_y:(totallen-area_height) = baroff:(available-barlen) if(totallen <= area_height) baroff=0; else baroff = ((available-barlen)*view_y)/(totallen-area_height); } if(barlen > 0) { jwin_draw_button(dbuf, toparrow_x-host->x, toparrow_y+16-host->y+baroff, 16, barlen, false, 1); } }
void GameOver::activate() { link.setAction(none); Playing=false; if(!debug_enabled) Paused=false; game->set_deaths(zc_min(game->get_deaths()+1,999)); link.dir=down; music_stop(); kill_sfx(); link.cancelAttack(); link.setHitTimer(0); link.setInvincible(false); link.scriptcoldet = 1; for(int i=0; i<16; i++) link.miscellaneous[i] = 0; //get rid off all sprites but Link guys.clear(); items.clear(); Ewpns.clear(); Lwpns.clear(); Sitems.clear(); chainlinks.clear(); decorations.clear(); playing_field_offset=56; // otherwise, red_shift() may go past the bottom of the screen quakeclk=wavy=0; //in original Z1, Link marker vanishes at death. //code in subscr.cpp, put_passive_subscr checks the following value. //color 255 is a GUI color, so quest makers shouldn't be using this value. //Also, subscreen is static after death in Z1. int tmp_link_dot = QMisc.colors.link_dot; QMisc.colors.link_dot = 255; //doesn't work //scrollbuf is tampered with by draw_screen() //put_passive_subscr(scrollbuf, &QMisc, 256, passive_subscreen_offset, false, false);//save this and reuse it. clear_bitmap(subscrbmp); put_passive_subscr(subscrbmp, &QMisc, 0, passive_subscreen_offset, false, sspUP); QMisc.colors.link_dot = tmp_link_dot; }
void EditboxNoWrapView::drawExtraComponents() { EditboxVScrollView::drawExtraComponents(); int textheight; textheight = text_height(textfont); //draw the scrollbar draw_arrow_button_horiz(dbuf, leftarrow_x-host->x, leftarrow_y-host->y, 16, 16, true, leftarrow_state*3); draw_arrow_button_horiz(dbuf, rightarrow_x-host->x, rightarrow_y-host->y, 16, 16, false, rightarrow_state*3); drawing_mode(DRAW_MODE_COPY_PATTERN, sbarpattern, 0, 0); int hbarstart = leftarrow_x + 16 - host->x; int hbarend = rightarrow_x - host->x-1; if(hbarstart < hbarend) rectfill(dbuf, hbarstart, leftarrow_y-host->y, hbarend, leftarrow_y-host->y+15, 0); solid_mode(); //compute the bar button, based on view_y int totallen = view_width; int available = rightarrow_x-(leftarrow_x+16); if(available < 0) { hbaroff=hbarlen=0; } else { //area_width:totallen = barlen:available hbarlen = (available*area_width)/zc_max(totallen,area_width)+1; //clip to reasonable values hbarlen = zc_max(hbarlen, 8); hbaroff = zc_min(hbaroff, available-hbarlen); //view_x:(totallen-area_width) = baroff:(available-hbarlen) if(totallen <= area_width) hbaroff = 0; else hbaroff = ((available-hbarlen)*view_x)/(totallen-area_width); } if(hbarlen > 0) { jwin_draw_button(dbuf, leftarrow_x-host->x+hbaroff+16, leftarrow_y-host->y, hbarlen, 16, false, 1); } }
CharPos BasicEditboxView::findCharacter(int x, int y) { int absolutey = y-area_ystart+view_y; int textheight = text_height(textfont); int lineno = absolutey/textheight; lineno = zc_max(lineno, 0); lineno = zc_min(lineno, (int)(model->getLines().size())-1); int totalindex = 0; //NOTE: future optimization opportunity list<LineData>::iterator it = model->getLines().begin(); for(int i=0; i<lineno; i++) { totalindex += it->numchars; it++; } CharPos rval; rval.it = it; rval.lineIndex = Unicode::getIndexOfWidth(it->line, -area_xstart+x+view_x, textfont); rval.totalIndex = totalindex + rval.lineIndex; return rval; }
void get_midi_text(MIDI *midi, midi_info *mi, char *text) // must have called get_midi_info() first { byte buf[1024]; char *out = text; int length=4096; dword nbytes; text[0] = 0; for(int i=0; midi->track[i].len>0; i++) { byte *data = midi->track[i].data; if(data==NULL) break; mi->event=0; mi->running_status = 0; while(!eot(mi) && data - midi->track[i].data < midi->track[i].len) { parse_mtrk(&data,mi); if(mi->event==0xFF) { nbytes=zc_min(mi->nbytes, 1023); memcpy(buf,mi->buf,nbytes); buf[nbytes]=0; if(decode_text_event(out,length,mi->type,buf)) { length-=strlen(out); out+=strlen(out); } } } } }
static inline int mixvol(int v1,int v2) { return (zc_min(v1,255)*zc_min(v2,255)) >> 8; }