Esempio n. 1
0
void TestUtilities::testMyround()
{
	UASSERT(myround(4.6f) == 5);
	UASSERT(myround(1.2f) == 1);
	UASSERT(myround(-3.1f) == -3);
	UASSERT(myround(-6.5f) == -7);
}
Esempio n. 2
0
/** interpolateZero: nearest neighbor interpolation function, see interpolate */
void _FLT(interpolateZero)(unsigned char *rv, float x, float y,
                           unsigned char* img, int width, int height, unsigned char def)
{
    int x_n = myround(x);
    int y_n = myround(y);
    *rv = (unsigned char) PIXEL(img, x_n, y_n, width, height, def);
}
Esempio n. 3
0
void DrawZone::setZoom(double z)
{
	_zoom=z;
	imageRect.setHeight(myround(image.height()*_zoom));
	imageRect.setWidth(myround(image.width()*_zoom));
	zoomedImage=QPixmap(imageRect.width(),imageRect.height());
	QPainter p(&zoomedImage);
	p.scale(z,z);
	QPixmap pix;
	pix.convertFromImage(image);
	// if the picture has transparent areas,
	// fill them with Gimp like background
	if (pix.mask()) {
  	QPixmap backPix(32,32);
  	QPainter p2(&backPix);
  	p2.fillRect(0,0,32,32,QColor(156,149,156));
  	p2.fillRect(0,16,16,16,QColor(98,105,98));
  	p2.fillRect(16,0,16,16,QColor(98,105,98));
  	p2.flush();
  	p.setPen(QPen());
  	p.fillRect(imageRect.left(),imageRect.top(),imageRect.width(),imageRect.height(),QBrush(QColor("black"),backPix));
	}
	p.drawPixmap(imageRect.left(),imageRect.top(),pix);
	p.flush();
	resizeContents(visibleWidth()>imageRect.width() ? visibleWidth() : imageRect.width(),
								 visibleHeight()>imageRect.height() ? visibleHeight() : imageRect.height());
	repaintContents(0,0,contentsWidth(),contentsHeight(),true);
}
Esempio n. 4
0
/**
 * transformRGB: applies current transformation to frame
 * Parameters:
 *         td: private data structure of this filter
 * Return value:
 *         0 for failture, 1 for success
 * Preconditions:
 *  The frame must be in RGB format
 /// TODO Add zoom!
 */
int _FLT(transformRGB)(TransformData* td, Transform t)
{
    int x = 0, y = 0, z = 0;
    unsigned char *D_1, *D_2;
    D_1  = td->src;
    D_2  = td->destbuf;
    float c_s_x = td->fiSrc.width/2.0;
    float c_s_y = td->fiSrc.height/2.0;
    float c_d_x = td->fiDest.width/2.0;
    float c_d_y = td->fiDest.height/2.0;

    /* for each pixel in the destination image we calc the source
     * coordinate and make an interpolation:
     *      p_d = c_d + M(p_s - c_s) + t
     * where p are the points, c the center coordinate,
     *  _s source and _d destination,
     *  t the translation, and M the rotation matrix
     *      p_s = M^{-1}(p_d - c_d - t) + c_s
     */
    /* All 3 channels */
    if (fabs(t.alpha) > td->rotationThreshhold) {
        for (x = 0; x < td->fiDest.width; x++) {
            for (y = 0; y < td->fiDest.height; y++) {
                float x_d1 = (x - c_d_x);
                float y_d1 = (y - c_d_y);
                float x_s  =  cos(-t.alpha) * x_d1
                              + sin(-t.alpha) * y_d1 + c_s_x -t.x;
                float y_s  = -sin(-t.alpha) * x_d1
                             + cos(-t.alpha) * y_d1 + c_s_y -t.y;
                for (z = 0; z < 3; z++) { // iterate over colors
                    unsigned char* dest = &D_2[(x + y * td->fiDest.width)*3+z];
                    _FLT(interpolateN)(dest, x_s, y_s, D_1,
                                       td->fiSrc.width, td->fiSrc.height,
                                       3, z, td->crop ? 16 : *dest);
                }
            }
        }
    } else {
        /* no rotation, just translation
         *(also no interpolation, since no size change (so far)
         */
        int round_tx = myround(t.x);
        int round_ty = myround(t.y);
        for (x = 0; x < td->fiDest.width; x++) {
            for (y = 0; y < td->fiDest.height; y++) {
                for (z = 0; z < 3; z++) { // iterate over colors
                    short p = PIXELN(D_1, x - round_tx, y - round_ty,
                                     td->fiSrc.width, td->fiSrc.height, 3, z, -1);
                    if (p == -1) {
                        if (td->crop == 1)
                            D_2[(x + y * td->fiDest.width)*3+z] = 16;
                    } else {
                        D_2[(x + y * td->fiDest.width)*3+z] = (unsigned char)p;
                    }
                }
            }
        }
    }
    return 1;
}
Esempio n. 5
0
void tia_calibration(int via_fpga, int fd, unsigned short addr, unsigned char *pval)
{
	unsigned char reg1DB, reg1DC, reg1DD, reg1DE, reg1DF;
	unsigned int reg1EB, reg1EC, reg1E6, Cbbf, R2346, temp;
	float BBBW_MHz, CTIA_fF;//需确定
	BBBW_MHz = 9;
	reg1EB = Ad9361ReadReg(via_fpga, fd, 0x1eb);
	reg1EC = Ad9361ReadReg(via_fpga, fd, 0x1ec);
	reg1E6 = Ad9361ReadReg(via_fpga, fd, 0x1e6);
	if(BBBW_MHz > 28)
	{
		BBBW_MHz = 28;
	}
	else if(BBBW_MHz < 0.2)
	{
		BBBW_MHz = 0.2;
	}
	Cbbf = (reg1EB * 160) + (reg1EC * 10) + 140;//fF
	R2346 = 18300 * (reg1E6 & 7);
	CTIA_fF = (Cbbf * R2346 * 0.56) / 3500;
	if(myceil(BBBW_MHz) <= 3)
	{
		reg1DB = 0xE0;
	}
	else if(myceil(BBBW_MHz) > 3 && myceil(BBBW_MHz) <= 10)
	{
		reg1DB = 0x60;
	}
	else if(myceil(BBBW_MHz) > 10)
	{
		reg1DB = 0x20;
	}
	if(CTIA_fF > 2920)
	{
		reg1DC = 0x40;
		reg1DE = 0x40;
		temp = min(127, myround((CTIA_fF - 400) / 320));
		reg1DD = temp;
		reg1DF = temp;
	}
	else
	{
		temp = myround((CTIA_fF - 400) / 40) + 0x40;
		reg1DC = temp;
		reg1DE = temp;
		reg1DD = 0;
		reg1DF = 0;
	}
	if(addr == 0x1DB)
		*pval = reg1DB;
	else if(addr == 0x1DC)
		*pval = reg1DC;
	else if(addr == 0x1DD)
		*pval = reg1DD;
	else if(addr == 0x1DE)
		*pval = reg1DE;
	else if(addr == 0x1DF)
		*pval = reg1DF;	
}
Esempio n. 6
0
void tree_node_placement(ManualMapVoxelManipulator &vmanip, v3f p0,
		MapNode node)
{
	v3s16 p1 = v3s16(myround(p0.X),myround(p0.Y),myround(p0.Z));
	if(vmanip.m_area.contains(p1) == false)
		return;
	u32 vi = vmanip.m_area.index(p1);
	if(vmanip.m_data[vi].getContent() != CONTENT_AIR
			&& vmanip.m_data[vi].getContent() != CONTENT_IGNORE)
		return;
	vmanip.m_data[vmanip.m_area.index(p1)] = node;
}
Esempio n. 7
0
void HatchingBrush::iterateVerticalLines(bool forward, int lineindex, bool oneline)
{
    //---Preparations before the loop---
    
    double xdraw = 0;
    double ydraw[2] = {0, height_};
    //points A and B of the segments to trace
    QPointF A, B;
    bool remaininginnerlines = true;
    
    while (remaininginnerlines) { 
        
        //---------START INTERSECTION POINT VERIFICATION--------
        remaininginnerlines = false;     // We assume there's no more lines unless proven contrary
        if (forward)
            verticalScanX = verticalHotX + separation*lineindex;
        else
            verticalScanX = verticalHotX - separation*lineindex;
        
        lineindex++;
        
        /*Read the explanation in HatchingBrush::iterateLines for more information*/
        
        if ((verticalScanX >= 0) && (verticalScanX <= width_)) {
            xdraw = verticalScanX;
            remaininginnerlines = true;
        }
        //--------END INTERSECTION POINT VERIFICATION---------
        
        if (!remaininginnerlines)
            break;
        
        if (!m_settings->subpixelprecision) {
            myround(&xdraw);
            myround(&ydraw[1]);
        }
        
        A.setX(xdraw);
        A.setY(ydraw[0]);
        B.setX(xdraw);
        B.setY(ydraw[1]);
        
        if (m_settings->antialias)
            m_painter.drawThickLine(A, B, thickness, thickness);
        else        
            m_painter.drawDDALine(A, B);    //testing no subpixel;
            
        if (oneline)
            break;
        else
            continue;
    }
}
Esempio n. 8
0
void tree_fruit_placement(ManualMapVoxelManipulator &vmanip, v3f p0,
		TreeDef &tree_definition)
{
	v3s16 p1 = v3s16(myround(p0.X),myround(p0.Y),myround(p0.Z));
	if(vmanip.m_area.contains(p1) == false)
		return;
	u32 vi = vmanip.m_area.index(p1);
	if(vmanip.m_data[vi].getContent() != CONTENT_AIR
		&& vmanip.m_data[vi].getContent() != CONTENT_IGNORE)
		return;
	vmanip.m_data[vmanip.m_area.index(p1)] = tree_definition.fruitnode;
}
Esempio n. 9
0
void TestRandom::testPcgRandomNormalDist()
{
	static const int max = 120;
	static const int min = -120;
	static const int num_trials = 20;
	static const u32 num_samples = 61000;
	s32 bins[max - min + 1];
	memset(bins, 0, sizeof(bins));

	PcgRandom r(486179 + (int)time(NULL));

	for (u32 i = 0; i != num_samples; i++) {
		s32 randval = r.randNormalDist(min, max, num_trials);
		UASSERT(randval <= max);
		UASSERT(randval >= min);
		bins[randval - min]++;
	}

	// Note that here we divide variance by the number of trials;
	// this is because variance is a biased estimator.
	int range      = (max - min + 1);
	float mean     = (max + min) / 2;
	float variance = ((range * range - 1) / 12) / num_trials;
	float stddev   = sqrt(variance);

	static const float prediction_intervals[] = {
		0.68269f, // 1.0
		0.86639f, // 1.5
		0.95450f, // 2.0
		0.98758f, // 2.5
		0.99730f, // 3.0
	};

	//// Simple normality test using the 68-95-99.7% rule
	for (u32 i = 0; i != ARRLEN(prediction_intervals); i++) {
		float deviations = i / 2.f + 1.f;
		int lbound = myround(mean - deviations * stddev);
		int ubound = myround(mean + deviations * stddev);
		UASSERT(lbound >= min);
		UASSERT(ubound <= max);

		int accum = 0;
		for (int j = lbound; j != ubound; j++)
			accum += bins[j - min];

		float actual = (float)accum / num_samples;
		UASSERT(fabs(actual - prediction_intervals[i]) < 0.02);
	}
}
Esempio n. 10
0
void tree_single_leaves_placement(ManualMapVoxelManipulator &vmanip, v3f p0,
		PseudoRandom ps, TreeDef &tree_definition)
{
	MapNode leavesnode=tree_definition.leavesnode;
	if (ps.range(1,100) > 100-tree_definition.leaves2_chance)
		leavesnode=tree_definition.leaves2node;
	v3s16 p1 = v3s16(myround(p0.X),myround(p0.Y),myround(p0.Z));
	if(vmanip.m_area.contains(p1) == false)
		return;
	u32 vi = vmanip.m_area.index(p1);
	if(vmanip.m_data[vi].getContent() != CONTENT_AIR
		&& vmanip.m_data[vi].getContent() != CONTENT_IGNORE)
		return;
	vmanip.m_data[vmanip.m_area.index(p1)] = leavesnode;
}
Esempio n. 11
0
GUIChatConsole::GUIChatConsole(
		gui::IGUIEnvironment* env,
		gui::IGUIElement* parent,
		s32 id,
		ChatBackend* backend,
		Client* client,
		IMenuManager* menumgr
):
	IGUIElement(gui::EGUIET_ELEMENT, env, parent, id,
			core::rect<s32>(0,0,100,100)),
	m_chat_backend(backend),
	m_client(client),
	m_menumgr(menumgr),
	m_animate_time_old(porting::getTimeMs())
{
	// load background settings
	s32 console_alpha = g_settings->getS32("console_alpha");
	m_background_color.setAlpha(clamp_u8(console_alpha));

	// load the background texture depending on settings
	ITextureSource *tsrc = client->getTextureSource();
	if (tsrc->isKnownSourceImage("background_chat.jpg")) {
		m_background = tsrc->getTexture("background_chat.jpg");
		m_background_color.setRed(255);
		m_background_color.setGreen(255);
		m_background_color.setBlue(255);
	} else {
		v3f console_color = g_settings->getV3F("console_color");
		m_background_color.setRed(clamp_u8(myround(console_color.X)));
		m_background_color.setGreen(clamp_u8(myround(console_color.Y)));
		m_background_color.setBlue(clamp_u8(myround(console_color.Z)));
	}

	m_font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED, FM_Mono);

	if (!m_font) {
		errorstream << "GUIChatConsole: Unable to load mono font ";
	} else {
		core::dimension2d<u32> dim = m_font->getDimension(L"M");
		m_fontsize = v2u32(dim.Width, dim.Height);
		m_font->grab();
	}
	m_fontsize.X = MYMAX(m_fontsize.X, 1);
	m_fontsize.Y = MYMAX(m_fontsize.Y, 1);

	// set default cursor options
	setCursor(true, true, 2.0, 0.1);
}
Esempio n. 12
0
void SummaryDrawWidget::mousePressEvent( QMouseEvent *e)
{
  View *view = gdata->view;
  double timeRatio = double(width()) / gdata->totalTime(); // px per second
  double noteRatio = double(height()) / (100.0 / scaler);
  clickMode = 0;
  mouseDown = true;
  mouseX = e->x();
  mouseY = e->y();

  // Work out where the user clicked
  clickTime = e->x()/timeRatio + gdata->leftTime();
  clickNote = (height()-1-e->y())/noteRatio;
  if(clickTime > view->viewLeft() && clickTime < view->viewRight() &&
     clickNote > view->viewBottom() && clickNote < view->viewTop()) {
	  // If they're in the view, they're dragging it.
    clickCurrentTimeDiff = view->currentTime() - clickTime;
    clickViewBottomDiff = view->viewBottom() - clickNote;
    clickMode = 1;
    downScaler = scaler;
  } else {
	  // Otherwise, move the view to where they clicked.
    view->setCurrentTime(clickTime);
    view->setViewBottom(int(myround(clickNote - (view->viewHeight() / 2))));
    clickMode = 1;
  }

}
static void init(void)
{
  FILE *f;
  int s;
  long long tb0; long long us0;
  long long tb1; long long us1;

  f = fopen("/proc/cpuinfo","r");
  if (!f) return 0;

  for (;;) {
    s = fscanf(f," clock : %lf MHz",&cpufrequency);
    if (s > 0) break;
    if (s == 0) s = fscanf(f,"%*[^\n]\n");
    if (s < 0) { cpufrequency = 0; break; }
  }

  fclose(f);
  if (!cpufrequency) return;
  cpufrequency *= 1000000.0;

  tb0 = timebase();
  us0 = microseconds();
  do {
    tb1 = timebase();
    us1 = microseconds();
  } while (us1 - us0 < 10000);
  if (tb1 <= tb0) return;

  tb1 -= tb0;
  us1 -= us0;
  tbcycles = myround((cpufrequency * 0.000001 * (double) us1) / (double) tb1);
}
Esempio n. 14
0
void main()
{
	double x;
	printf("Input a number:");
	scanf("%lf", &x);
	printf("%lf\n", myround(x));
}
Esempio n. 15
0
float myroundclamp( float i )
{
    float j = myround( i );
    if (j < 0)
        j = 0;
    return j;
}
Esempio n. 16
0
int main(void)
{
	double n;
	printf("please input number:\n");
	scanf("%lf",&n);
	printf("the result is %lf.\n", myround(n));
	return 0;
}
Esempio n. 17
0
static void init(void)
{
  unsigned int tbfrequency = 0; size_t tbfrequencylen = sizeof(unsigned int);
  cpufrequency = osfreq();
  sysctl(tbmib,2,&tbfrequency,&tbfrequencylen,0,0);
  if (tbfrequency > 0)
    tbcycles = myround(64 * (double) (unsigned long long) cpufrequency
                          / (double) (unsigned long long) tbfrequency);
}
Esempio n. 18
0
// return: # of samples written
size_t DSD2PCM::writeFinal(std::vector<float> resample_data, size_t odone, uint8_t* out)
{
	uint8_t* op = out;

	switch (wordSize) {
	case 16:
		for (int s = 0; s < odone * channels; ) {
			for (int ch = 0; ch < channels; ++ch) {
				float r = resample_data[s] * 32768.0f + ns[ch].get();
				long smp = clip<long>(-32768, myround(r), 32767);
				ns[ch].update(clip<long>(-1, smp - r, 1));
				write_intel16(op, smp);
				op += 2;
				++s;
			}
		}
		break;
	case 24:
		for (int s = 0; s < odone * channels; ) {
			for (int ch = 0; ch < channels; ++ch) {
				float r = resample_data[s] * 8388608.0f;
				long smp = clip<long>(-8388608, myround(r), 8388607);
				write_intel24(op, smp);
				op += 3;
				++s;
			}
		}
		break;
	case 32:
		for (int s = 0; s < odone * channels; ) {
			for (int ch = 0; ch < channels; ++ch) {
				float r = resample_data[s] * (1 << 31);
				long smp = clip<long>(INT32_MIN, myround(r), INT32_MAX);
				write_intel32(op, smp);
				op += 4;
				++s;
			}
		}
		break;
	}
	return odone;
}
Esempio n. 19
0
/** interpolateLin: linear (only x) interpolation function, see interpolate */
void _FLT(interpolateLin)(unsigned char *rv, float x, float y,
                          unsigned char* img, int width, int height,
                          unsigned char def)
{
    int x_f = myfloor(x);
    int x_c = x_f+1;
    int y_n = myround(y);
    float v1 = PIXEL(img, x_c, y_n, width, height, def);
    float v2 = PIXEL(img, x_f, y_n, width, height, def);
    float s  = v1*(x - x_f) + v2*(x_c - x);
    *rv = (unsigned char)s;
}
Esempio n. 20
0
void regobj::addtobound(boundart& barp, i32 x, i32 y)
{
  if (regmngp->flpasablear[regmngp->mapp(x,y)])
  {
    if (myround(sqr(x-centerp.x)+sqr(y-centerp.y))<=regmngp->regionradius2)
    {
      barp.add(pointt(x,y));

      regmngp->regmapp(x,y)=this;
      square++;
    }
  }
}
Esempio n. 21
0
// This avoids duplicating the code in terrainLevelFromNoise, adding
// only the final step of terrain generation without a noise map.
float MapgenValleys::adjustedTerrainLevelFromNoise(TerrainNoise *tn)
{
	float mount = terrainLevelFromNoise(tn);
	s16 y_start = myround(mount);

	for (s16 y = y_start; y <= y_start + 1000; y++) {
		float fill = NoisePerlin3D(&noise_inter_valley_fill->np, tn->x, y, tn->z, seed);

		if (fill * *tn->slope <= y - mount) {
			mount = MYMAX(y - 1, mount);
			break;
		}
	}

	return mount;
}
Esempio n. 22
0
int main(void)
{
	int i = 1;
	double x;
	double result;

	while (i == 1) {
		printf("\n\nplease input a number:");
		scanf("%lf", &x);
		result = myround(x);
		printf("\nthe result of round is:%lf", result);
		printf("\nwhat do you want to do next?");
		printf("\n1.go on\t2.stop\n");
		scanf("%d", &i);
	}
	return 0;
}
Esempio n. 23
0
Hud::Hud(video::IVideoDriver *driver, scene::ISceneManager* smgr,
		gui::IGUIEnvironment* guienv, gui::IGUIFont *font,
		u32 text_height, IGameDef *gamedef,
		LocalPlayer *player, Inventory *inventory) {
	this->driver      = driver;
	this->smgr        = smgr;
	this->guienv      = guienv;
	this->font        = font;
	this->text_height = text_height;
	this->gamedef     = gamedef;
	this->player      = player;
	this->inventory   = inventory;

	m_screensize       = v2u32(0, 0);
	m_displaycenter    = v2s32(0, 0);
	m_hotbar_imagesize = floor(HOTBAR_IMAGE_SIZE * porting::getDisplayDensity() + 0.5);
	m_padding = m_hotbar_imagesize / 12;

	const video::SColor hbar_color(255, 255, 255, 255);
	for (unsigned int i=0; i < 4; i++ ){
		hbar_colors[i] = hbar_color;
	}
	
	tsrc = gamedef->getTextureSource();
	
	v3f crosshair_color = g_settings->getV3F("crosshair_color");
	u32 cross_r = rangelim(myround(crosshair_color.X), 0, 255);
	u32 cross_g = rangelim(myround(crosshair_color.Y), 0, 255);
	u32 cross_b = rangelim(myround(crosshair_color.Z), 0, 255);
	u32 cross_a = rangelim(g_settings->getS32("crosshair_alpha"), 0, 255);
	crosshair_argb = video::SColor(cross_a, cross_r, cross_g, cross_b);
	
	v3f selectionbox_color = g_settings->getV3F("selectionbox_color");
	u32 sbox_r = rangelim(myround(selectionbox_color.X), 0, 255);
	u32 sbox_g = rangelim(myround(selectionbox_color.Y), 0, 255);
	u32 sbox_b = rangelim(myround(selectionbox_color.Z), 0, 255);
	selectionbox_argb = video::SColor(255, sbox_r, sbox_g, sbox_b);
	
	use_crosshair_image = tsrc->isKnownSourceImage("crosshair.png");

	hotbar_image = "";
	use_hotbar_image = false;
	hotbar_selected_image = "";
	use_hotbar_selected_image = false;
}
Esempio n. 24
0
static void init(void)
{
  int loop;
  double guess1;
  double guess2;

  cpufrequency = osfreq();
  if (!cpufrequency) return;

  for (tbshift = 0;tbshift < 10;++tbshift) {
    for (loop = 0;loop < 100;++loop) {
      guess1 = guesstbcycles();
      guess2 = guesstbcycles();
      tbcycles = myround(guess1);
      if (guess1 - tbcycles > 0.1) continue;
      if (tbcycles - guess1 > 0.1) continue;
      if (guess2 - tbcycles > 0.1) continue;
      if (tbcycles - guess2 > 0.1) continue;
      return;
    }
  }
  tbcycles = 0;
}
Esempio n. 25
0
static void init(void)
{
  FILE *f;
  long long tb0; long long us0;
  long long tb1; long long us1;

  f = popen("/usr/sbin/lsattr -E -l proc0 -a frequency","r");
  if (!f) return;
  if (fscanf(f,"frequency %lf",&cpufrequency) < 1) cpufrequency = 0;
  pclose(f);
  if (!cpufrequency) return;

  tb0 = timebase();
  us0 = microseconds();
  do {
    tb1 = timebase();
    us1 = microseconds();
  } while (us1 - us0 < 10000);
  if (tb1 <= tb0) return;

  tb1 -= tb0;
  us1 -= us0;
  tbcycles = myround((cpufrequency * 0.000001 * (double) us1) / (double) tb1);
}
Esempio n. 26
0
Hud::Hud(video::IVideoDriver *driver, scene::ISceneManager* smgr,
		gui::IGUIEnvironment* guienv, gui::IGUIFont *font,
		u32 text_height, IGameDef *gamedef,
		LocalPlayer *player, Inventory *inventory) {
	this->driver      = driver;
	this->smgr        = smgr;
	this->guienv      = guienv;
	this->font        = font;
	this->text_height = text_height;
	this->gamedef     = gamedef;
	this->player      = player;
	this->inventory   = inventory;
	
	screensize       = v2u32(0, 0);
	displaycenter    = v2s32(0, 0);
	hotbar_imagesize = 48;
	
	tsrc = gamedef->getTextureSource();
	
	v3f crosshair_color = g_settings->getV3F("crosshair_color");
	u32 cross_r = rangelim(myround(crosshair_color.X), 0, 255);
	u32 cross_g = rangelim(myround(crosshair_color.Y), 0, 255);
	u32 cross_b = rangelim(myround(crosshair_color.Z), 0, 255);
	u32 cross_a = rangelim(g_settings->getS32("crosshair_alpha"), 0, 255);
	crosshair_argb = video::SColor(cross_a, cross_r, cross_g, cross_b);
	
	v3f selectionbox_color = g_settings->getV3F("selectionbox_color");
	u32 sbox_r = rangelim(myround(selectionbox_color.X), 0, 255);
	u32 sbox_g = rangelim(myround(selectionbox_color.Y), 0, 255);
	u32 sbox_b = rangelim(myround(selectionbox_color.Z), 0, 255);
	selectionbox_argb = video::SColor(255, sbox_r, sbox_g, sbox_b);
	
	use_crosshair_image = tsrc->isKnownSourceImage("crosshair.png");

	hotbar_image = "";
	use_hotbar_image = false;
	hotbar_selected_image = "";
	use_hotbar_selected_image = false;
}
Esempio n. 27
0
GUIChatConsole::GUIChatConsole(
		gui::IGUIEnvironment* env,
		gui::IGUIElement* parent,
		s32 id,
		ChatBackend* backend,
		Client* client
):
	IGUIElement(gui::EGUIET_ELEMENT, env, parent, id,
			core::rect<s32>(0,0,100,100)),
	m_chat_backend(backend),
	m_client(client),
	m_screensize(v2u32(0,0)),
	m_animate_time_old(0),
	m_open(false),
	m_height(0),
	m_desired_height(0),
	m_desired_height_fraction(0.0),
	m_height_speed(5.0),
	m_open_inhibited(0),
	m_cursor_blink(0.0),
	m_cursor_blink_speed(0.0),
	m_cursor_height(0.0),
	m_background(NULL),
	m_background_color(255, 0, 0, 0),
	m_font(NULL),
	m_fontsize(0, 0)
{
	m_animate_time_old = getTimeMs();

	// load background settings
	bool console_color_set = !g_settings->get("console_color").empty();
	s32 console_alpha = g_settings->getS32("console_alpha");

	// load the background texture depending on settings
	m_background_color.setAlpha(clamp_u8(console_alpha));
	if (console_color_set)
	{
		v3f console_color = g_settings->getV3F("console_color");
		m_background_color.setRed(clamp_u8(myround(console_color.X)));
		m_background_color.setGreen(clamp_u8(myround(console_color.Y)));
		m_background_color.setBlue(clamp_u8(myround(console_color.Z)));
	}
	else
	{
		m_background = env->getVideoDriver()->getTexture(getTexturePath("background_chat.jpg").c_str());
		m_background_color.setRed(255);
		m_background_color.setGreen(255);
		m_background_color.setBlue(255);
	}

	// load the font
	// FIXME should a custom texture_path be searched too?
	#if USE_FREETYPE
	std::string font_name = g_settings->get("mono_font_path");
	u16 font_size = g_settings->getU16("mono_font_size");
	m_font = gui::CGUITTFont::createTTFont(env, font_name.c_str(), font_size);
	#else
	std::string font_name = "fontdejavusansmono.png";
	m_font = env->getFont(getTexturePath(font_name).c_str());
	#endif
	if (m_font == NULL)
	{
		dstream << "Unable to load font: " << font_name << std::endl;
	}
	else
	{
		core::dimension2d<u32> dim = m_font->getDimension(L"M");
		m_fontsize = v2u32(dim.Width, dim.Height);
		dstream << "Font size: " << m_fontsize.X << " " << m_fontsize.Y << std::endl;
	}
	m_fontsize.X = MYMAX(m_fontsize.X, 1);
	m_fontsize.Y = MYMAX(m_fontsize.Y, 1);

	// set default cursor options
	setCursor(true, true, 2.0, 0.1);
}
Esempio n. 28
0
void TimeAxis::paintEvent(QPaintEvent *)
{
  int frameWidth = 2;
  const int	h = height(), w = width() - 2*frameWidth;
  int fontSpace = _fontSize+2;
  
  beginDrawing(false);
  fillBackground(colorGroup().background());

  double timeStep = timeWidth() / double(w) * 150.0; //time per 150 pixels
  double timeScaleBase = pow10(floor(log10(timeStep))); //round down to the nearest power of 10

  //choose a timeScaleStep which is a multiple of 1, 2 or 5 of timeScaleBase
  int largeFreq;
  if(timeScaleBase * 5.0 < timeStep) { largeFreq = 5; }
  else if (timeScaleBase * 2.0 < timeStep) { largeFreq = 2; }
  else { largeFreq = 2; timeScaleBase /= 2; }
    
  // Draw Ruler Numbers
  p.setBrush(Qt::black);
  //p.setFont(QFont("AnyStyle", h / 2 - 7));
  p.setFont(_font);
  double timePos = floor(leftTime() / (timeScaleBase*largeFreq)) * (timeScaleBase*largeFreq); //calc the first one just off the left of the screen
  int x, largeCounter=-1;
  
  //precalculate line sizes (for efficiency)
  int smallLineTop = 0;
  int smallLineBottom = 0;
  if(_numbersOnTop) {
    smallLineTop = h - 1 - (h - 1 - fontSpace)/2;
    smallLineBottom = h - 1;
  } else {
    smallLineTop = 0;
    smallLineBottom = (h - 1 - fontSpace) / 2;
  }
  int bigLineTop = 0;
  int bigLineBottom = 0;
  if(_numbersOnTop) {
    bigLineTop = fontSpace;
    bigLineBottom = h - 1;
  } else {
    bigLineTop = 0;
    bigLineBottom = h - 1 - fontSpace;
  }
  int textBottom = 0;
  if(_numbersOnTop) textBottom = _fontSize;
  else textBottom = h - 1;
    
  for(; timePos <= rightTime(); timePos += timeScaleBase) {
    if(++largeCounter == largeFreq) {
      largeCounter = 0;
      //draw the bigger lines and the numbers
      //QString numString = QString::number(timePos);

      double newTime = myround(timePos / timeScaleBase) * timeScaleBase;
      QString mins;
      double secs = fmod(newTime, 60.0);

      if (timePos < 0) {
        mins = "-" + QString::number(int(ceil(newTime / 60)));
        secs *= -1;
      } else {
        mins = QString::number(int(floor(newTime / 60)));
      }

      QString seconds = QString::number(secs);
      if (secs < 10 && secs > -10) {
        seconds = "0" + seconds;
      }
      
      QString numString = mins + ":" + seconds;
      x = frameWidth + toInt((timePos-leftTime()) / (timeWidth() / double(w)));
      p.drawText(x - (p.fontMetrics().width(numString) / 2), textBottom, numString);
      p.drawLine(x, bigLineTop, x, bigLineBottom);
    } else {
      //draw the smaller lines
      x = frameWidth + toInt((timePos-leftTime()) / (timeWidth() / double(w)));
      p.drawLine(x, smallLineTop, x, smallLineBottom);
    }
  }
  //draw the horizontal line
  if(_numbersOnTop) {
    p.drawLine(0, h-1, width(), h-1);
  } else {
    p.drawLine(0, 0, width(), 0);
  }
  endDrawing();
}
Esempio n. 29
0
bool GUIChatConsole::OnEvent(const SEvent& event)
{
	if(event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown)
	{
		// Key input
		if(KeyPress(event.KeyInput) == getKeySetting("keymap_console"))
		{
			closeConsole();
			Environment->removeFocus(this);

			// inhibit open so the_game doesn't reopen immediately
			m_open_inhibited = 50;
			return true;
		}
		else if(event.KeyInput.Key == KEY_ESCAPE)
		{
			closeConsoleAtOnce();
			Environment->removeFocus(this);
			// the_game will open the pause menu
			return true;
		}
		else if(event.KeyInput.Key == KEY_PRIOR)
		{
			m_chat_backend->scrollPageUp();
			return true;
		}
		else if(event.KeyInput.Key == KEY_NEXT)
		{
			m_chat_backend->scrollPageDown();
			return true;
		}
		else if(event.KeyInput.Key == KEY_RETURN)
		{
			std::wstring text = m_chat_backend->getPrompt().submit();
			m_client->typeChatMessage(text);
			return true;
		}
		else if(event.KeyInput.Key == KEY_UP)
		{
			// Up pressed
			// Move back in history
			m_chat_backend->getPrompt().historyPrev();
			return true;
		}
		else if(event.KeyInput.Key == KEY_DOWN)
		{
			// Down pressed
			// Move forward in history
			m_chat_backend->getPrompt().historyNext();
			return true;
		}
		else if(event.KeyInput.Key == KEY_LEFT)
		{
			// Left or Ctrl-Left pressed
			// move character / word to the left
			ChatPrompt::CursorOpScope scope =
				event.KeyInput.Control ?
				ChatPrompt::CURSOROP_SCOPE_WORD :
				ChatPrompt::CURSOROP_SCOPE_CHARACTER;
			m_chat_backend->getPrompt().cursorOperation(
				ChatPrompt::CURSOROP_MOVE,
				ChatPrompt::CURSOROP_DIR_LEFT,
				scope);
			return true;
		}
		else if(event.KeyInput.Key == KEY_RIGHT)
		{
			// Right or Ctrl-Right pressed
			// move character / word to the right
			ChatPrompt::CursorOpScope scope =
				event.KeyInput.Control ?
				ChatPrompt::CURSOROP_SCOPE_WORD :
				ChatPrompt::CURSOROP_SCOPE_CHARACTER;
			m_chat_backend->getPrompt().cursorOperation(
				ChatPrompt::CURSOROP_MOVE,
				ChatPrompt::CURSOROP_DIR_RIGHT,
				scope);
			return true;
		}
		else if(event.KeyInput.Key == KEY_HOME)
		{
			// Home pressed
			// move to beginning of line
			m_chat_backend->getPrompt().cursorOperation(
				ChatPrompt::CURSOROP_MOVE,
				ChatPrompt::CURSOROP_DIR_LEFT,
				ChatPrompt::CURSOROP_SCOPE_LINE);
			return true;
		}
		else if(event.KeyInput.Key == KEY_END)
		{
			// End pressed
			// move to end of line
			m_chat_backend->getPrompt().cursorOperation(
				ChatPrompt::CURSOROP_MOVE,
				ChatPrompt::CURSOROP_DIR_RIGHT,
				ChatPrompt::CURSOROP_SCOPE_LINE);
			return true;
		}
		else if(event.KeyInput.Key == KEY_BACK)
		{
			// Backspace or Ctrl-Backspace pressed
			// delete character / word to the left
			ChatPrompt::CursorOpScope scope =
				event.KeyInput.Control ?
				ChatPrompt::CURSOROP_SCOPE_WORD :
				ChatPrompt::CURSOROP_SCOPE_CHARACTER;
			m_chat_backend->getPrompt().cursorOperation(
				ChatPrompt::CURSOROP_DELETE,
				ChatPrompt::CURSOROP_DIR_LEFT,
				scope);
			return true;
		}
		else if(event.KeyInput.Key == KEY_DELETE)
		{
			// Delete or Ctrl-Delete pressed
			// delete character / word to the right
			ChatPrompt::CursorOpScope scope =
				event.KeyInput.Control ?
				ChatPrompt::CURSOROP_SCOPE_WORD :
				ChatPrompt::CURSOROP_SCOPE_CHARACTER;
			m_chat_backend->getPrompt().cursorOperation(
				ChatPrompt::CURSOROP_DELETE,
				ChatPrompt::CURSOROP_DIR_RIGHT,
				scope);
			return true;
		}
		else if(event.KeyInput.Key == KEY_KEY_U && event.KeyInput.Control)
		{
			// Ctrl-U pressed
			// kill line to left end
			m_chat_backend->getPrompt().cursorOperation(
				ChatPrompt::CURSOROP_DELETE,
				ChatPrompt::CURSOROP_DIR_LEFT,
				ChatPrompt::CURSOROP_SCOPE_LINE);
			return true;
		}
		else if(event.KeyInput.Key == KEY_KEY_K && event.KeyInput.Control)
		{
			// Ctrl-K pressed
			// kill line to right end
			m_chat_backend->getPrompt().cursorOperation(
				ChatPrompt::CURSOROP_DELETE,
				ChatPrompt::CURSOROP_DIR_RIGHT,
				ChatPrompt::CURSOROP_SCOPE_LINE);
			return true;
		}
		else if(event.KeyInput.Key == KEY_TAB)
		{
			// Tab or Shift-Tab pressed
			// Nick completion
			std::list<std::string> names = m_client->getConnectedPlayerNames();
			bool backwards = event.KeyInput.Shift;
			m_chat_backend->getPrompt().nickCompletion(names, backwards);
			return true;
		}
		else if(event.KeyInput.Char != 0 && !event.KeyInput.Control)
		{
			m_chat_backend->getPrompt().input(event.KeyInput.Char);
			return true;
		}
	}
	else if(event.EventType == EET_MOUSE_INPUT_EVENT)
	{
		if(event.MouseInput.Event == EMIE_MOUSE_WHEEL)
		{
			s32 rows = myround(-3.0 * event.MouseInput.Wheel);
			m_chat_backend->scroll(rows);
		}
	}

	return Parent ? Parent->OnEvent(event) : false;
}
Esempio n. 30
0
bool GUIChatConsole::OnEvent(const SEvent& event)
{

	ChatPrompt &prompt = m_chat_backend->getPrompt();

	if(event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown)
	{
		// Key input
		if(KeyPress(event.KeyInput) == getKeySetting("keymap_console"))
		{
			closeConsole();

			// inhibit open so the_game doesn't reopen immediately
			m_open_inhibited = 50;
			m_close_on_enter = false;
			return true;
		}
		else if(event.KeyInput.Key == KEY_ESCAPE)
		{
			closeConsoleAtOnce();
			m_close_on_enter = false;
			// inhibit open so the_game doesn't reopen immediately
			m_open_inhibited = 1; // so the ESCAPE button doesn't open the "pause menu"
			return true;
		}
		else if(event.KeyInput.Key == KEY_PRIOR)
		{
			m_chat_backend->scrollPageUp();
			return true;
		}
		else if(event.KeyInput.Key == KEY_NEXT)
		{
			m_chat_backend->scrollPageDown();
			return true;
		}
		else if(event.KeyInput.Key == KEY_RETURN)
		{
			prompt.addToHistory(prompt.getLine());
			std::wstring text = prompt.replace(L"");
			m_client->typeChatMessage(text);
			if (m_close_on_enter) {
				closeConsoleAtOnce();
				m_close_on_enter = false;
			}
			return true;
		}
		else if(event.KeyInput.Key == KEY_UP)
		{
			// Up pressed
			// Move back in history
			prompt.historyPrev();
			return true;
		}
		else if(event.KeyInput.Key == KEY_DOWN)
		{
			// Down pressed
			// Move forward in history
			prompt.historyNext();
			return true;
		}
		else if(event.KeyInput.Key == KEY_LEFT || event.KeyInput.Key == KEY_RIGHT)
		{
			// Left/right pressed
			// Move/select character/word to the left depending on control and shift keys
			ChatPrompt::CursorOp op = event.KeyInput.Shift ?
				ChatPrompt::CURSOROP_SELECT :
				ChatPrompt::CURSOROP_MOVE;
			ChatPrompt::CursorOpDir dir = event.KeyInput.Key == KEY_LEFT ?
				ChatPrompt::CURSOROP_DIR_LEFT :
				ChatPrompt::CURSOROP_DIR_RIGHT;
			ChatPrompt::CursorOpScope scope = event.KeyInput.Control ?
				ChatPrompt::CURSOROP_SCOPE_WORD :
				ChatPrompt::CURSOROP_SCOPE_CHARACTER;
			prompt.cursorOperation(op, dir, scope);
			return true;
		}
		else if(event.KeyInput.Key == KEY_HOME)
		{
			// Home pressed
			// move to beginning of line
			prompt.cursorOperation(
				ChatPrompt::CURSOROP_MOVE,
				ChatPrompt::CURSOROP_DIR_LEFT,
				ChatPrompt::CURSOROP_SCOPE_LINE);
			return true;
		}
		else if(event.KeyInput.Key == KEY_END)
		{
			// End pressed
			// move to end of line
			prompt.cursorOperation(
				ChatPrompt::CURSOROP_MOVE,
				ChatPrompt::CURSOROP_DIR_RIGHT,
				ChatPrompt::CURSOROP_SCOPE_LINE);
			return true;
		}
		else if(event.KeyInput.Key == KEY_BACK)
		{
			// Backspace or Ctrl-Backspace pressed
			// delete character / word to the left
			ChatPrompt::CursorOpScope scope =
				event.KeyInput.Control ?
				ChatPrompt::CURSOROP_SCOPE_WORD :
				ChatPrompt::CURSOROP_SCOPE_CHARACTER;
			prompt.cursorOperation(
				ChatPrompt::CURSOROP_DELETE,
				ChatPrompt::CURSOROP_DIR_LEFT,
				scope);
			return true;
		}
		else if(event.KeyInput.Key == KEY_DELETE)
		{
			// Delete or Ctrl-Delete pressed
			// delete character / word to the right
			ChatPrompt::CursorOpScope scope =
				event.KeyInput.Control ?
				ChatPrompt::CURSOROP_SCOPE_WORD :
				ChatPrompt::CURSOROP_SCOPE_CHARACTER;
			prompt.cursorOperation(
				ChatPrompt::CURSOROP_DELETE,
				ChatPrompt::CURSOROP_DIR_RIGHT,
				scope);
			return true;
		}
		else if(event.KeyInput.Key == KEY_KEY_A && event.KeyInput.Control)
		{
			// Ctrl-A pressed
			// Select all text
			prompt.cursorOperation(
				ChatPrompt::CURSOROP_SELECT,
				ChatPrompt::CURSOROP_DIR_LEFT, // Ignored
				ChatPrompt::CURSOROP_SCOPE_LINE);
			return true;
		}
		else if(event.KeyInput.Key == KEY_KEY_C && event.KeyInput.Control)
		{
			// Ctrl-C pressed
			// Copy text to clipboard
			if (prompt.getCursorLength() <= 0)
				return true;
			std::wstring wselected = prompt.getSelection();
			std::string selected(wselected.begin(), wselected.end());
			Environment->getOSOperator()->copyToClipboard(selected.c_str());
			return true;
		}
		else if(event.KeyInput.Key == KEY_KEY_V && event.KeyInput.Control)
		{
			// Ctrl-V pressed
			// paste text from clipboard
			if (prompt.getCursorLength() > 0) {
				// Delete selected section of text
				prompt.cursorOperation(
					ChatPrompt::CURSOROP_DELETE,
					ChatPrompt::CURSOROP_DIR_LEFT, // Ignored
					ChatPrompt::CURSOROP_SCOPE_SELECTION);
			}
			IOSOperator *os_operator = Environment->getOSOperator();
			const c8 *text = os_operator->getTextFromClipboard();
			if (!text)
				return true;
			std::basic_string<unsigned char> str((const unsigned char*)text);
			prompt.input(std::wstring(str.begin(), str.end()));
			return true;
		}
		else if(event.KeyInput.Key == KEY_KEY_X && event.KeyInput.Control)
		{
			// Ctrl-X pressed
			// Cut text to clipboard
			if (prompt.getCursorLength() <= 0)
				return true;
			std::wstring wselected = prompt.getSelection();
			std::string selected(wselected.begin(), wselected.end());
			Environment->getOSOperator()->copyToClipboard(selected.c_str());
			prompt.cursorOperation(
				ChatPrompt::CURSOROP_DELETE,
				ChatPrompt::CURSOROP_DIR_LEFT, // Ignored
				ChatPrompt::CURSOROP_SCOPE_SELECTION);
			return true;
		}
		else if(event.KeyInput.Key == KEY_KEY_U && event.KeyInput.Control)
		{
			// Ctrl-U pressed
			// kill line to left end
			prompt.cursorOperation(
				ChatPrompt::CURSOROP_DELETE,
				ChatPrompt::CURSOROP_DIR_LEFT,
				ChatPrompt::CURSOROP_SCOPE_LINE);
			return true;
		}
		else if(event.KeyInput.Key == KEY_KEY_K && event.KeyInput.Control)
		{
			// Ctrl-K pressed
			// kill line to right end
			prompt.cursorOperation(
				ChatPrompt::CURSOROP_DELETE,
				ChatPrompt::CURSOROP_DIR_RIGHT,
				ChatPrompt::CURSOROP_SCOPE_LINE);
			return true;
		}
		else if(event.KeyInput.Key == KEY_TAB)
		{
			// Tab or Shift-Tab pressed
			// Nick completion
			std::list<std::string> names = m_client->getConnectedPlayerNames();
			bool backwards = event.KeyInput.Shift;
			prompt.nickCompletion(names, backwards);
			return true;
		}
		else if(event.KeyInput.Char != 0 && !event.KeyInput.Control)
		{
			#if (defined(linux) || defined(__linux))
				wchar_t wc = L'_';
				mbtowc( &wc, (char *) &event.KeyInput.Char, sizeof(event.KeyInput.Char) );
				prompt.input(wc);
			#else
				prompt.input(event.KeyInput.Char);
			#endif
			return true;
		}
	}
	else if(event.EventType == EET_MOUSE_INPUT_EVENT)
	{
		if(event.MouseInput.Event == EMIE_MOUSE_WHEEL)
		{
			s32 rows = myround(-3.0 * event.MouseInput.Wheel);
			m_chat_backend->scroll(rows);
		}
	}

	return Parent ? Parent->OnEvent(event) : false;
}